|
用鼠标获得场景中的节点 节点类型本身是PositionAttitudeTransform的
获得的时候 想从node类型转成PositionAttitudeTransform 的 代码如下
- osgUtil::LineSegmentIntersector::Intersections intersections;
- if (viewer->computeIntersections(x, y, intersections)){
- if(flag == 1){
- parentPick->replaceChild(scribe.get(), nodePick.get());
- scribe->removeChildren(0, scribe->getNumChildren());
- }
- osgUtil::LineSegmentIntersector::Intersection intersection = *intersections.begin();
- osg::NodePath& nodePath = intersection.nodePath;
- nodePick = (nodePath.size()>=1)?nodePath[nodePath.size()-1]:0;
- parentPick = (nodePath.size()>=2)?dynamic_cast<osg::Group*>(nodePath[nodePath.size()-2]):0;
- if (parentPick.get() && nodePick.get()){
- //thisNode= parentPick->getParent(0);
- thisNode = dynamic_cast<osg::PositionAttitudeTransform*>(parentPick->getParent(0)); //获得当前选择的节点
-
- //用高亮显示来显示物体已经被选中
- osg::ref_ptr<osgFX::Scribe> parentAsScribe = dynamic_cast<osgFX::Scribe*>(parentPick.get());
- if(!parentAsScribe){ //如果对象选择到 高亮显示
- scribe->addChild(nodePick.get());
- parentPick->replaceChild(nodePick.get(), scribe.get());
- if(flag == 0){ //第一次拾取
- isSelect = true; //表示已经选择到节点
- flag = 1;
- }
- }else{ //如果没选择到 移除高亮显示的对象
- osg::Node::ParentList parentList = parentAsScribe->getParents();
- for(osg::Node::ParentList::iterator itr = parentList.begin(); itr != parentList.end(); ++itr){
- (*itr)->replaceChild(parentAsScribe.get(), nodePick.get());
- }
- }
- }
- }
复制代码 为什么运行后获得的thisNode不正确 调试过 在thisNode = dynamic_cast<osg:ositionAttitudeTransform*>(parentPick->getParent(0));这句运行后 thisNode里的各种信息说是 错误: 无法计算表达式的值
求指导 谢谢 |
|