when I use osgUtil::LineSegmentIntersector in my project based on osgOcean ,I 
find a very strange problem.‍    I want to detect the intersection point by 
push the mouse.It means when I push the mouse middle button,I need to get the 
intersetction of the scene.but when the manipulator is near to the scene,I 
sometimes could get the intersection,but when the manipulaor is far to the 
scene,I could not get the intersection.It is radom.
    Line SegmentIntersector is a simple function and the code is also simple 
.but I do not konw why I occur such problem,my poroject is base on 
osgOcean,whether this is the reason?but I only test the scene that the 
intersection is on the model,I have not test when the intersction is on the 
ocean surface. I also consider the node mask in the comment part.here is my 
code:‍
    I debug the code and find" picker->containsIntersections() "return false.‍
        if (!view)
        {
                AfxMessageBox(L"view failed");
                return false;
        }


        osg::Camera * camera=view->getCamera();
        if (!camera)
        {
                AfxMessageBox(L"camera failed");
                return false;
        }


        float x = ( ea.getX() - ea.getXmin() ) / ( ea.getXmax() - ea.getXmin() 
);
        float y = ( ea.getY() - ea.getYmin() ) / ( ea.getYmax() - ea.getYmin() 
);


        osgUtil::LineSegmentIntersector::CoordinateFrame cf;
        osg::Viewport  *vp = camera->getViewport();
        if( vp ) {
                cf = osgUtil::Intersector::WINDOW;
                x *= vp->width();
                y *= vp->height();
        }else{
                AfxMessageBox(L"view failed");
        }


        //int childNum=_scene->getOceanScene()->getNumChildren();
        //for (int i=0;i<childNum;i++)
        //{
        //      osg::ref_ptr<osg::Node> 
node=_scene->getOceanScene()->getChild(i);
        //      node->setNodeMask(0xffff);
        //}


        osg::Vec3d center;
        osgUtil::LineSegmentIntersector::Intersections inters;


        osg::ref_ptr<osgUtil::LineSegmentIntersector> picker=new 
osgUtil::LineSegmentIntersector( cf,x,y);
        osgUtil::IntersectionVisitor iv(picker);
        camera->accept(iv);


        if (!picker->containsIntersections())
        {
                AfxMessageBox(L"inter failed");
                return false;
        }


        osgUtil::LineSegmentIntersector::Intersections& 
intersections=picker->getIntersections();


        osg::Vec3d center=(*intersections.begin()).getWorldIntersectPoint();




        //for (int i=0;i<childNum;i++)
        //{
        //      osg::ref_ptr<osg::Node> 
node=_scene->getOceanScene()->getChild(i);
        //      node->setNodeMask( 
_scene->getOceanScene()->getNormalSceneMask() | 
        //              _scene->getOceanScene()->getReflectedSceneMask() |
        //              _scene->getOceanScene()->getRefractedSceneMask() );
        //}‍
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to