None of the below information applies to you, because Paul already identified the issue, but I thought an explanation for bounding box stuff might be useful. It's caused some bizarre behavior for us due to special cases imposed by specific node types.
So, here goes... Nodes keep track of their bounding boxes so that the information can be reused on each cull phase. So, each node has a Boolean flag for tracking it, and a BoundingBox member. Whenever a request to getBound is made, the node will return the value of it's BoundingBox if dirty is false, otherwise it recomputes it. You can force dirty to be set by calling dirtyBound(). The computation method is virtual, so each node type does it differently. In the case of groups, dirtyBound is called whenever a new child is added, and during the compute process, the internal bounding box is the bounding box for all children. Transforms also apply their transformation to the BB. AutoTransforms always return the internal BB regardless of the dirty state, since their bound can't be computed until Cull Traversal; that's to take advantage of eye position. PagedLODs work like normal groups, but if you call getBound() before any children are loaded, the computed BB will be invalid. AutoTransforms and PagedLODs have both caused trouble for me :) Geodes traverse all their drawables and use the vertex information for visible vertices to set its extents. So, if you add or remove vertices after the bounds have been computed, you'll need to call setBound. Billboards probably do something similar to AutoTransforms, but I'm not exactly sure. I've never had to dig into their internals. If you are ever worried about not getting a valid bounding box due to problems raised by AutoTransforms and PagedLODs, you can use the setInitialBound() method to explicitly set a bounding box, rather than relying on the first call to computeBound to be successful. Hope that clears stuff up. Chase ________________________________ From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of alessandro terenzi Sent: Wednesday, April 18, 2007 7:03 AM To: osg users Subject: Re: [osg-users] mouse picking problem Actually I don't call dirtyBound() at all...I do not modify my geometry, so I guess I don't need that call, am I wrong? Anyway, since I'm new to osg, I also tried to call that function just after I assign the pyramid to the node representing the scene object, like this: (in the main...) ... osg::ref_ptr<osg::Node> scene = createPyramid(50.0f, 50.0f); scene->dirtyBound(); ... but I still have the same problem. Maybe it is a stupid question, anyway I ask: am I supposed to init/create in some way the bounding box of any geometry I create? I mean, my createPyramid() function just creates some vertices and the polygons that represent the pyramid faces, then it sets vertices colors and texture cooridnates but it does nothing more than that...do I have to compute the bounding box using some Node/Geode's method? Thanks. Alessandro On 4/18/07, Andreas Goebel <[EMAIL PROTECTED]> wrote: alessandro terenzi schrieb: > I cleaned up my code and here a simple example showing my problem: > ...here's the handle method: > > bool myEventHandler::handle( const osgGA::GUIEventAdapter& ea, > osgGA::GUIActionAdapter& aa ) > { > osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>( &aa ); > if (!viewer) > return false; > > switch( ea.getEventType() ) > { > case osgGA::GUIEventAdapter::PUSH: > case osgGA::GUIEventAdapter::MOVE: > { > _mX = ea.getX(); > _mY = ea.getY(); > return false; > } > case osgGA::GUIEventAdapter::RELEASE: > { > if (_mX == ea.getX() && _mY == ea.getY ()) > { > if (pick( ea.getXnormalized(),ea.getYnormalized(), viewer )) > return true; > } > return false; > } > default: > return false; > } > } > > ...and here's the pick method: > > bool myEventHandler::pick( const double x, const double y, > osgViewer::Viewer* viewer ) > { > if (!viewer->getSceneData()) > // Nothing to pick. > return false; > > double w( .05 ), h( .05 ); > osgUtil::PolytopeIntersector* picker = new > osgUtil::PolytopeIntersector(osgUtil::Intersector::PROJECTION, x-w, > y-h, x+w, y+h ); > osgUtil::IntersectionVisitor iv(picker); > > viewer->getCamera()->accept(iv); > if (picker->containsIntersections()) > { > std::cout<< "Found intersections..."<<std::endl; > osg::NodePath& nodePath = picker->getFirstIntersection().nodePath; > unsigned int idx = nodePath.size(); > while (idx--) > { > // look for osg::Geode object > osg::Geode* my_geode = dynamic_cast<osg::Geode*>(nodePath[idx]); > if(my_geode == NULL) > continue; > > std::cout<< "Picking successful..."<<std::endl; > break; > } > } > else > { > std::cout<<"Picking failed [no intersections]... "<<std::endl; > return false; > } > > return true; > } > > ...and finally the main: > > int main(int argc, char* argv[]) > > { > osgViewer::Viewer viewer; > > osg::ref_ptr<osg::Node> scene = createPyramid( 50.0f, 50.0f); > > viewer.addEventHandler(new myEventHandler); > > viewer.setSceneData(scene.get()); > > return viewer.run(); > } > > The behaviour I'm experiencing is as follow: after clicking far away > from the pyramid I got this output on the console: > > *Picking failed [no intersections]...* > > after clicking inside one of the pyramid's faces, I got: > > *Picking failed [no intersections]...* > > finally when I clicked on the apex, I got: > > *Found intersections... > Picking successful...* > > Any Idea about what is wrong? > > Thanks. > > Alessandro > > > > O > You do not show where you create your geometry. Did you call dirtyBound() ? Regards, Andreas _______________________________________________ osg-users mailing list [email protected] http://openscenegraph.net/mailman/listinfo/osg-users http://www.openscenegraph.org/
_______________________________________________ osg-users mailing list [email protected] http://openscenegraph.net/mailman/listinfo/osg-users http://www.openscenegraph.org/
