Hi Peter, Julien-Charles Levesque schrieb: > >> Hi, >> >> I'm trying to use a PolytopeIntersector in my scene and so far I have >> succeeded but only by using the camera (i.e. mCamera->accept(PolyVisitor)) >> with a PolytopeIntersector built from x and y coordinates in window frame. >> However I would rather pass the visitor the root of my scene. I am doing >> this in a virtual reality project, and using the camera seems to complicate >> things a fair bit because we modify projection matrices and viewports a >> whole lot. >> For my LineSegmentIntersector I have used 3D points in model space, which >> worked fine when visiting the root of the scene. For the PolytopeIntersector >> I am unsure how to do this... Only examples I have found so far used either >> coordinates in projection space or coordinates in window space. >> > > Yes, the examples do not use all available constructors of > PolytopeIntersector. > That is something that has been sitting on my to-do-list for a long time... >
Here is my code... stripped down to a minimum. I assume that you have a 4x4 matrix containing orientation of your selector (lOrientation) and a vec3 containing it's position (lPosition). I built the polytope to point in the direction of positive y-axis. Sorry for the french variable names and comments here and there... I don't think they hurt readability much at this level :P However, I wasn't able to extract a reliable 3x3 rotation matrix from mouse coordinates. I can only say that this code works well with the raw 3x3 orientation and position provided by my tracker. Do you have any idea for a desktop variation ? I can implement it. I could also integrate all this in the examplekeyboardmouse, once I've figured out how to do it with a mouse :P osg::Vec3 lPosition; osg::Matrixd lOrientation; osg::Vec3d lEnd = lPosition + lOrientation * osg::Vec3d(0,LENGTH, 0); //pointe vers Y à l'origine //construction d'un polytope dans le repere monde. osg::Polytope lPolytope; osg::Plane lPlane; osg::Vec3d lNorm; //This is the angle by which your planes are rotated. Wider angle = larger selection. double lTheta = 0.5 * PI / 180.; //Left X Plane lNorm.set(cos(lTheta),sin(lTheta),0); lNorm = lOrientation*lNorm; lPlane.set(lNorm, lPosition); lPolytope.add(lPlane); //Right X Plane lNorm.set(-cos(lTheta),sin(lTheta),0); //car cos(theta) = cos(-theta) et sin(theta)=-sin(-theta) lNorm = lOrientation*lNorm; lPlane.set(lNorm, lPosition); lPolytope.add(lPlane); //Top Z Plane lNorm.set(0,sin(lTheta),-cos(lTheta)); lNorm = lOrientation*lNorm; lPlane.set(lNorm, lPosition); lPolytope.add(lPlane); //Bottom Z Plane lNorm.set(0,sin(lTheta),cos(lTheta)); lNorm = lOrientation*lNorm; lPlane.set(lNorm, lPosition); lPolytope.add(lPlane); //Far Y Plane. lNorm.set(0,-1,0); lNorm = lOrientation*lNorm; lPlane.set(lNorm, lEnd); lPolytope.add(lPlane); osg::ref_ptr<osgUtil::PolytopeIntersector> lIntersecteur = new osgUtil::PolytopeIntersector(lPolytope); // Création d'un visiteur. osg::ref_ptr<osgUtil::IntersectionVisitor> lVisiteur = new osgUtil::IntersectionVisitor; lVisiteur->setIntersector(lIntersecteur); //Set mask only if you must... in our //application it was for focusable objects. //lVisiteur->setTraversalMask(OBJET_DESIGNABLE); //Accept node at root of scene. mRootNode->accept(lVisiteur); if(lIntersecteur->containsIntersections()) { // Récupère les objets en intersection avec la droite. osgUtil::PolytopeIntersector::Intersections lIntersections = lIntersecteur->getIntersections(); //Parcours la liste des intersections, en commençant par les objets les plus près for (osgUtil::PolytopeIntersector::Intersections::iterator lII = lIntersections.begin(); lII != lIntersections.end(); lII++) { const osg::NodePath& lNodePath = lII->nodePath; //Do whatever you have to here! } } Cheers, Julien-Charles
_______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org