QVector<const AObject*> Flower::collideSphere( const AObject * exclude, const float & radius, QVector3D & center, QVector3D * normal ) { QVector<const AObject*> collides = AObject::collideSphere( exclude, radius, center, normal ); float depth; QVector3D tmpNormal; if( !Sphere::intersectSphere( position(), boundingSphereRadius(), center, radius, &tmpNormal, &depth ) ) return collides; // return if we aren't even near the forest for( QVector<QMatrix4x4>::iterator i = mInstances.begin(); i != mInstances.end(); ++i ) { float treeScale = (*i).column(0).length(); QVector3D treeBottom = (*i).column(3).toVector3D() + (*i).mapVector( QVector3D(0,-10,0) ); QVector3D treeTop = (*i).column(3).toVector3D() + (*i).mapVector( QVector3D(0,60,0) ); if( Capsule::intersectSphere( treeBottom, treeTop, treeScale, center, radius/3, &tmpNormal, &depth ) ) { collides.append( this ); center += tmpNormal * depth; if( normal ) *normal += tmpNormal; } } return collides; }
///// zoomFit ///////////////////////////////////////////////////////////////// void GLView::zoomFit(const bool update) /// Calculates zPos so that the scene fits in the current window /// It uses the result of boundingSphereRadius, a pure virtual { ///// determine the radius of the bounding sphere maxRadius = boundingSphereRadius(); ///// calculate the camera position if(baseParameters.perspectiveProjection) { if(width() > height()) zPos = maxRadius/tan(fieldOfView)/1.5f; else zPos = maxRadius/tan(fieldOfView)/1.5f * static_cast<float>(height())/static_cast<float>(width()); if(zPos < 0.1f) zPos = 0.1f; } else { zPos = 1.0f; resizeGL(width(), height()); } ///// update the scene updateFog(maxRadius); if(update) updateGL(); setModified(); }
QVector<const AObject*> Teapot::collideSphere( const AObject * exclude, const float & radius, QVector3D & center, QVector3D * normal ) const { QVector<const AObject*> collides = AObject::collideSphere( exclude, radius, center, normal ); float depth; QVector3D tmpNormal(0,1,0); /* if( Sphere::intersectSphere( position(), boundingSphereRadius(), center, radius, &tmpNormal, &depth ) ) { collides.append( this ); center += tmpNormal * depth; if( normal ) *normal = tmpNormal; } */ if( Capsule::intersectSphere( position(), position()+QVector3D(0,2,0), boundingSphereRadius()/2.0f, center, radius, &tmpNormal, &depth ) ) { collides.append( this ); center += tmpNormal * depth; if( normal ) *normal = tmpNormal; } return collides; }