Hi,
i have got the problem with position line - Intersector, more informations in 
part of the code: 

(the scene is only rectangle face, it's  z=0.0f)

1) creating x,y,z position line: 
osg::Vec3f v3f_start(33.0f, -23.0f, 10.0f); //init position ( start )
osg::Vec3d v3f_end(33.0f, -23.0f, -5.0f); //init position ( end )

2) Intersector group:
osg::ref_ptr<osgUtil::IntersectorGroup> intersectorGroup = new 
osgUtil::IntersectorGroup();
        osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector = new 
osgUtil::LineSegmentIntersector(v3f_start, v3f_end);
        intersectorGroup->addIntersector( intersector.get() );
        osgUtil::IntersectionVisitor intersectVisitor( intersectorGroup.get(), 
new MyReadCallback );
        model->accept(intersectVisitor);

3) Check intersect 
if ( intersectorGroup->containsIntersections() )
{
 ...
intersection.getWorldIntersectPoint();  //interscetion point is in 33.0f, - 
23.0f, 0.0f
...
}

4) Update position line
osgUtil::IntersectorGroup::Intersectors& ints = 
intersectorGroup->getIntersectors();
        for(osgUtil::IntersectorGroup::Intersectors::iterator intersector_itr2 
= ints.begin();
                                        intersector_itr2 != ints.end();
                                        ++intersector_itr2)
        {
                osgUtil::LineSegmentIntersector* lsi = 
dynamic_cast<osgUtil::LineSegmentIntersector*>(intersector_itr2->get());
                if (lsi)
                {
                        v3f_start.set(33.0f, 23.0f, 10.0f);     //new position 
( start )
                        v3f_end.set(33.0f, 23.0f, -5.0f);       //new position 
( end )
                        lsi->setStart( v3f_start );  
                        lsi->setEnd( v3f_end );
                }
        }


5) Check intersect 
if ( intersectorGroup->containsIntersections() )
{
 ...
intersection.getWorldIntersectPoint(); 
//interscetion point is still the same(!) 33.0f, - 23.0f, 0.0f
//i thought that correct point must be 33.0f, 23.0f, 0.0f because 
LineSegmentIntersector contains correct new (start - end) position 
...
}

Where is the problem?

full code here:

Code:
void check_face(osgUtil::IntersectorGroup *intersectorGroup)
{
        if ( intersectorGroup->containsIntersections() )
        {
                osgUtil::IntersectorGroup::Intersectors& intersectors = 
intersectorGroup->getIntersectors();
                for(osgUtil::IntersectorGroup::Intersectors::iterator 
intersector_itr = intersectors.begin();
                                        intersector_itr != intersectors.end();
                                        ++intersector_itr)
                {
                        osgUtil::LineSegmentIntersector* lsi = 
dynamic_cast<osgUtil::LineSegmentIntersector*>(intersector_itr->get());
                        if (lsi)
                        {
                                osgUtil::LineSegmentIntersector::Intersections& 
intersections = lsi->getIntersections();
                                
for(osgUtil::LineSegmentIntersector::Intersections::iterator itr = 
intersections.begin();
                                        itr != intersections.end();
                                        ++itr)
                                {
                                        const 
osgUtil::LineSegmentIntersector::Intersection& intersection = *itr;
                                        osg::Vec3f lv_pos;
                                        lv_pos = 
intersection.getWorldIntersectPoint(); 
                                        const osg::NodePath my_nodePath = 
intersection.nodePath;
                                        unsigned int lun_nsize = 
my_nodePath.size(); 
                                        osg::Node * ln_node = 0;
                                        osg::Group * ln_parent = 0; 
                                        
                                        ln_node = 
(lun_nsize>=1)?my_nodePath[my_nodePath.size()-1]:0; 
                                        std::string name = ln_node->getName();  
                //name 
                                        unsigned int mask = 
ln_node->getNodeMask();             //
                                        //2nd group
                                        ln_parent = 
(lun_nsize>=2)?dynamic_cast<osg::Group*>(my_nodePath[1]):0;
                                        if (ln_parent)
                                        {
                                                std::string name2 = 
ln_parent->getName();               //name parent 
                                                unsigned int mask2 = 
ln_parent->getNodeMask();  //mask parent
                                        } 
                                }
                        }
                }
        }
}

//intersection
        osg::Vec3f v3f_start(33.0f, -23.0f, 10.0f);     //init position ( start 
)
        osg::Vec3d v3f_end(33.0f, -23.0f, -5.0f);       //init position ( end )

        osg::ref_ptr<osgUtil::IntersectorGroup> intersectorGroup = new 
osgUtil::IntersectorGroup();
        osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector = new 
osgUtil::LineSegmentIntersector(v3f_start, v3f_end);
        intersectorGroup->addIntersector( intersector.get() );
        osgUtil::IntersectionVisitor intersectVisitor( intersectorGroup.get(), 
new MyReadCallback );
        model->accept(intersectVisitor);        
        
        check_face(intersectorGroup);

        osgUtil::IntersectorGroup::Intersectors& ints = 
intersectorGroup->getIntersectors();
        for(osgUtil::IntersectorGroup::Intersectors::iterator intersector_itr2 
= ints.begin();
                                        intersector_itr2 != ints.end();
                                        ++intersector_itr2)
        {
                osgUtil::LineSegmentIntersector* lsi = 
dynamic_cast<osgUtil::LineSegmentIntersector*>(intersector_itr2->get());
                if (lsi)
                {
                        v3f_start.set(33.0f, 23.0f, 10.0f);     //new position 
( start )
                        v3f_end.set(33.0f, 23.0f, -5.0f);       //new position 
( end )
                        lsi->setStart( v3f_start );  
                        lsi->setEnd( v3f_end );
                }
        }
        check_face(intersectorGroup);



Thank you!

Cheers,
petr[/code]

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





_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to