Hi,

this is the new code:
Firstly, I used LineSegmentIntersector to find out the 3-D co-ordinates of 
point data. This is working with solid bodies (sphere, pyramid etc) but it 
doesn't intersect with point data.
Then i moved to PolytopeIntersector, it's working with the point data and 
giving that how many objects are intersected and classname of objects but till 
now i m unable to find out the method by which i can retrieve the 3-D 
co-ordinates of the points.
The lines in red color giving the 3-D co-ordinates when I use 
LineSegmentIntersector, but these method are not working with 
PolyTopeIntersector. 

class PickHandler : public osgGA::GUIEventHandler
{
        protected:
                float _mX, _mY;
                void pick( const osgGA::GUIEventAdapter& ea, osgViewer::Viewer* 
viewer);
                

        public:
        PickHandler() : _mX( 0. ),_mY( 0. ) {}
        bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& 
aa );
        
};

void PickHandler :: pick( const osgGA::GUIEventAdapter& ea, osgViewer::Viewer* 
viewer )
{
        float x, y, w, h;
        x = ea.getX();
        y = ea.getY();
                                
        if (!viewer->getSceneData())
        // Nothing to pick.
        osg::notify(osg::NOTICE)<<std::endl;
                        
        w = h = 0.5;
        osgUtil::PolytopeIntersector::Intersections intersections; 
        osg::ref_ptr<osgUtil::PolytopeIntersector> picker = new 
osgUtil::PolytopeIntersector(osgUtil::Intersector::WINDOW, x-w, y-h, x+w, y+h );
                                
        osgUtil::IntersectionVisitor iv( picker );
        viewer->getCamera() -> accept( iv );
        if (picker->containsIntersections())
        {
        
                intersections = picker->getIntersections();

                for(osgUtil::PolytopeIntersector::Intersections::iterator hitr 
= intersections.begin(); hitr != intersections.end(); ++hitr)
                {
                        
                        if (!hitr->nodePath.empty() && 
!(hitr->nodePath.back()->getName().empty()))
                        {
                // the geodes are identified by name.
                        cout<<"Object 
\""<<hitr->nodePath.back()->getName()<<"\""<<std::endl;
                        }
                        else if (hitr->drawable.valid())
                        {
                        cout<<"Object 
\""<<hitr->drawable->className()<<"\""<<std::endl;
                        }

                        //std::cout<<" local coords vertex("<< 
hitr->getLocalIntersectPoint()    <<")"<<std::endl;
                        //std::cout<<" world coords vertex("<< 
hitr->getWorldIntersectPoint()<<")"<<std::endl;
//
                
        }
        }
        else
        cout<<"doesn't contain intersection ";

        }


bool PickHandler :: 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:
        {
                // Record mouse location for the button press
                // and move events.
                _mX = ea.getX();
                _mY = ea.getY();
                cout<<"position of mouse :"<<_mX<<","<<_mY<<endl;
                
                if (viewer) 
                        pick(ea, viewer);

                return false;
        }
        case(osgGA::GUIEventAdapter::KEYDOWN):
                {
                    if (ea.getKey()=='a')
                    {
                                cout<<"a pressed"<<endl;
                                return false;
                        }
        default:
                return false;
        }
        }
}

Thank you!

Cheers,
Vipin

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=30615#30615





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to