|
在一个选取程序中,想通过模型设置的节点来选取模型, 下面的程序在读取cow.osg总是不能读取在程序中通过setname(targetB),而对于robot.osg则能正确读取,后来发现cow.osg有2个并列的父节点,而总是读取另一个父节点或根节点,不能读取targetB这个节点,当一个节点有多个上级父节点时,该如何处理才能将每个父节点的名字读出来?新手,不知道该如何处理才能读到targetB?请各位大佬帮忙看看,谢谢!
void pick(osg::ref_ptr<osgViewer::View> view, float x, float y)
{
osg::ref_ptr<osg::Node> node = new osg::Node();
osg::ref_ptr<osg::Group> parent = new osg::Group();
//创建一个线段交集检测函数
osgUtil:ineSegmentIntersector::Intersections intersections;
if (view->computeIntersections(x, y, intersections))
{
for (osgUtil::LineSegmentIntersector::Intersections::iterator iter = intersections.begin(); iter != intersections.end(); iter++)
{
osg::NodePath &np =iter->nodePath;
std::cout<<"size:"<<np.size()<<iter->nodePath.back()->getName()<<std::endl;
for(int i=np.size()-1;i>=0;i--)
{
osg::Node *nd=dynamic_cast<osg::Node *>(np[i]);
{
if (nd->getName () == "targetA")
{
std::cout << "HIT A!" << std::endl;
std::cout <<"node name:"<<nd->getName()<<std::endl ;
}
else if (nd->getName() == "targetB")
{
std::cout <<"node name:"<<nd->getName()<<std::endl ;
std::cout << "HIT B!" << std::endl;
}
}
}
} |
|