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/

Reply via email to