Sorry, I can't resist making some improvements ;)
www.hesicong.net wrote on Tuesday, March 06, 2007 9:10 AM:
> class findGeoNamedNode:
> public osg::NodeVisitor
> {
> public:
> findGeoNamedNode();
> findGeoNamedNode(const std::string name):
> osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
> {
>
> resultNode=NULL;
> this->name=name;
> }
>
> virtual void apply(osg::Node &searchNode)
You could do this:
virtual void apply(osg::Geode& searchNode)
and it would work without needing the dynamic_cast below, and would be
faster!
> {
> if(searchNode.getName()==name)
> {
> osg::Geode* dynamicTry=dynamic_cast<osg::Geode*>(&searchNode);
>
> if(dynamicTry)
> {
> resultNode=dynamicTry;
> }
> }
> traverse(searchNode);
> }
>
> osg::Geode* getNode()
> {
> return resultNode;
> }
> private:
> osg::Geode* resultNode;
It's a little bit dangerous to just store a pointer, since OSG Nodes are
reference counted; the Geode could be deleted out from under you. It
would be better to use osg::ref_ptr<> or osg::observer_ptr<>.
> std::string name;
> };
> Thanks!
Glad we could help!
--
Bryan Thrall
FlightSafety International
[EMAIL PROTECTED]
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/