Hi,

how can I get my PickHandler edited from the osgpick (see attachment) example 
working inside the osgoculusviewer?

Cheers,
Michael

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



// class to handle events with a pick
class PickHandler : public osgGA::GUIEventHandler {
public:

    PickHandler() {}

    ~PickHandler() {}

    bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa) {
        switch(ea.getEventType())
        {
            case(osgGA::GUIEventAdapter::PUSH):
            {
                osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
                if (view) pick(view,ea);
                return false;
            }
            case(osgGA::GUIEventAdapter::KEYDOWN):
            {
                if (ea.getKey()=='c')
                {
                    osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
                    osg::ref_ptr<osgGA::GUIEventAdapter> event = new 
osgGA::GUIEventAdapter(ea);
                    event->setX((ea.getXmin()+ea.getXmax())*0.5);
                    event->setY((ea.getYmin()+ea.getYmax())*0.5);
                    if (view) pick(view,*event);
                }
                return false;
            }
            default:
                return false;
        }
    }

    virtual void pick(osgViewer::View* view, const osgGA::GUIEventAdapter& ea) {
        osgUtil::LineSegmentIntersector::Intersections intersections;

        std::string gdlist="";

        osg::ref_ptr<osg::Camera> cam = view->getCamera();
        std::cout << "mouse coordinates: " << ea.getX() << ", " << ea.getY() << 
", camera = " << cam->getName() << std::endl;

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

                os<<"        local coords vertex("<< 
hitr->getLocalIntersectPoint()<<")"<<"  
normal("<<hitr->getLocalIntersectNormal()<<")"<<std::endl;
                os<<"        world coords vertex("<< 
hitr->getWorldIntersectPoint()<<")"<<"  
normal("<<hitr->getWorldIntersectNormal()<<")"<<std::endl;
                const osgUtil::LineSegmentIntersector::Intersection::IndexList& 
vil = hitr->indexList;
                for(unsigned int i=0;i<vil.size();++i)
                {
                    os<<"        vertex indices ["<<i<<"] = 
"<<vil[i]<<std::endl;
                }

                gdlist += os.str();
            }
            std:: cout << gdlist << std::endl;
        }       
    }
};
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to