Changeset 13041 for OpenSceneGraph/trunk/src/osgManipulator/Projector.cpp
 Timestamp:
 03/21/12 18:36:20 (3 years ago)
 Files:

 1 modified
Legend:
 Unmodified
 Added
 Removed

OpenSceneGraph/trunk/src/osgManipulator/Projector.cpp
r13027 r13041 31 31 // An explanation of the algorithm can be found at 32 32 // http://www.geometryalgorithms.com/Archive/algorithm_0106/algorithm_0106.htm 33 33 34 34 osg::LineSegment::vec_type u = l1.end()  l1.start(); u.normalize(); 35 35 osg::LineSegment::vec_type v = l2.end()  l2.start(); v.normalize(); … … 75 75 } 76 76 77 bool getPlaneLineIntersection(const osg::Vec4d& plane, 78 const osg::Vec3d& lineStart, const osg::Vec3d& lineEnd, 77 bool getPlaneLineIntersection(const osg::Vec4d& plane, 78 const osg::Vec3d& lineStart, const osg::Vec3d& lineEnd, 79 79 osg::Vec3d& isect) 80 80 { … … 95 95 } 96 96 97 bool getSphereLineIntersection(const osg::Sphere& sphere, 98 const osg::Vec3d& lineStart, const osg::Vec3d& lineEnd, 97 bool getSphereLineIntersection(const osg::Sphere& sphere, 98 const osg::Vec3d& lineStart, const osg::Vec3d& lineEnd, 99 99 osg::Vec3d& frontISect, osg::Vec3d& backISect) 100 100 { … … 105 105 double B = 2.0f * (lineDirection * v); 106 106 double C = v * v  sphere.getRadius() * sphere.getRadius(); 107 107 108 108 double discriminant = B * B  4.0f * C; 109 109 … … 121 121 } 122 122 123 bool getUnitCylinderLineIntersection(const osg::Vec3d& lineStart, const osg::Vec3d& lineEnd, 123 bool getUnitCylinderLineIntersection(const osg::Vec3d& lineStart, const osg::Vec3d& lineEnd, 124 124 osg::Vec3d& isectFront, osg::Vec3d& isectBack) 125 125 { … … 153 153 154 154 bool getCylinderLineIntersection(const osg::Cylinder& cylinder, 155 const osg::Vec3d& lineStart, const osg::Vec3d& lineEnd, 155 const osg::Vec3d& lineStart, const osg::Vec3d& lineEnd, 156 156 osg::Vec3d& isectFront, osg::Vec3d& isectBack) 157 157 { … … 162 162 * osg::Matrix::scale(oneOverRadius, oneOverRadius, oneOverRadius) 163 163 * osg::Matrix(cylinder.getRotation().inverse()); 164 164 165 165 // Transform the lineStart and lineEnd into the unit cylinder space. 166 166 osg::Vec3d unitCylLineStart = lineStart * toUnitCylInZ; … … 170 170 osg::Vec3d unitCylIsectFront, unitCylIsectBack; 171 171 if (! getUnitCylinderLineIntersection(unitCylLineStart, unitCylLineEnd, unitCylIsectFront, unitCylIsectBack)) 172 return false; 172 return false; 173 173 174 174 // Transform back from unit cylinder space. 175 175 osg::Matrix invToUnitCylInZ(osg::Matrix::inverse(toUnitCylInZ)); 176 176 isectFront = unitCylIsectFront * invToUnitCylInZ; 177 isectBack = unitCylIsectBack * invToUnitCylInZ; 177 isectBack = unitCylIsectBack * invToUnitCylInZ; 178 178 179 179 return true; … … 182 182 osg::Vec3d getLocalEyeDirection(const osg::Vec3d& eyeDir, const osg::Matrix& localToWorld) 183 183 { 184 // To take a normal from world to local you need to transform it by the transpose of the inverse of the 184 // To take a normal from world to local you need to transform it by the transpose of the inverse of the 185 185 // world to local matrix. Premultiplying is equivalent to doing a postmultiplication of the transpose. 186 186 osg::Vec3d localEyeDir = localToWorld * eyeDir;