OSG 对线或者点组成的模型选取
2017-08-31 17:48
197 查看
#include "PickHandler.h" #include "ModelShape.h" #include "DraggerNodeVisitor.h" #include <osgViewer/view> #include <osgUtil/PolytopeIntersector> #include <osgFX/Scribe> #include <QDebug> PickHandler::PickHandler(osg::Node* ptrSceneNode) : m_X(0.0f) , m_Y(0.0f) , m_enableDragger(true) , m_ptrSceneNode(ptrSceneNode) { } PickHandler::~PickHandler() { } bool PickHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) { osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa); if (NULL == view) { return false; } switch (ea.getEventType()) { case osgGA::GUIEventAdapter::PUSH: { m_X = ea.getX(); m_Y = ea.getY(); } break; case osgGA::GUIEventAdapter::RELEASE: { if (ea.getX() == m_X && ea.getY() == m_Y) { pick(ea, aa); } } break; case osgGA::GUIEventAdapter::KEYDOWN: { if (ea.getKey() == 'd') { m_enableDragger = !m_enableDragger; } } break; default: break; } return false; } void PickHandler::pick(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) { osgViewer::View* view = dynamic_cast<osgViewer::View*> (&aa); // 创建求交圆柱体与切片节点相交判断 double mx = ea.getXnormalized(); double my = ea.getYnormalized(); osg::ref_ptr<osgUtil::PolytopeIntersector> picker = new osgUtil::PolytopeIntersector(osgUtil::Intersector::PROJECTION, mx - 0.01, my - 0.01, mx + 0.01, my + 0.01); picker->setDimensionMask(osgUtil::PolytopeIntersector::DimZero | osgUtil::PolytopeIntersector::DimOne); osgUtil::IntersectionVisitor iv(picker); aa.asView()->getCamera()->accept(iv); BoundingBoxDisableNodeVisitor boundingBoxDisableVisitor = BoundingBoxDisableNodeVisitor(); m_ptrSceneNode->accept(boundingBoxDisableVisitor); if (picker->containsIntersections()) { osgUtil::PolytopeIntersector::Intersections setIntersections = picker->getIntersections(); osgUtil::PolytopeIntersector::Intersection intersection = *setIntersections.begin(); osg::NodePath& nodePath = intersection.nodePath; int nNodeSize = static_cast<int> (nodePath.size()); if (nNodeSize > 0) { osg::Node* node = nodePath[nNodeSize - 1]; osg::Node* grandParent = node->getParent(0); while (grandParent->getName() != "ModelShape") { grandParent = grandParent->getParent(0); } ModelShape* ptrShape = dynamic_cast<ModelShape*>(grandParent); ptrShape->setBoundingBoxShow(true); if (ptrShape != NULL) { m_enableDragger ? ptrShape->enableDragger() : ptrShape->disableDragger(); } } } }
对于点或者线生成的模型,由于没有三角面的存在,所以无法使用LineSegmentIntersector来判断相交。所以使用PolytopeIntersector生成一个细长的小圆柱体来判断是否与点线模型相交
相关文章推荐
- 38 WebGL针对单独的顶点坐标绘制组成模型
- 3ds max文件导出osg或者ive格式
- PCL在VS2013下快速安装或者cmake详细安装(可以运行kinectFusion使用kinect1拍摄深度图彩色图三维模型)两种安装方式
- JavaScript的组成--BOM浏览器对象模型
- android 调用系统相册选取照片或者打开相机拍照获取图片,返回时回到手机桌面,然后才会跳转到当前activity
- unity--鼠标或者手指点击模型播放动画
- 机器学习中的数据不平衡问题----通过随机采样比例大的类别使得训练集中大类的个数与小类相当,或者模型中加入惩罚项
- Mask裁切UI粒子特效或者3D模型
- osg加载模型后使模型居中且以最佳大小显示
- 1、在一个由自然数1-1000中某些数字所组成的数组中,每个数字可能出现零次或者多次。设计一个算法,找出出现次数最多的数字。
- XML:XPath路径定义选取节点 XPath 使用路径表达式在 XML 文档中选取节点。节点是通过沿着路径或者 step 来选取的。 下面列出了最有用的路径表达式: 表达式 描述 nodename
- R语言︱LDA主题模型——最优主题数选取(topicmodels)+LDAvis可视化(lda+LDAvis)
- iOS实现头像选取(照相或者图片库)、大小等比缩放、生成圆形头像
- Json中相同或者重复记录的值相加组成新的Json
- osg模型发黑
- OSG模型简单控制
- 设计一个算法,要求在20个数字中(0到19)随机选取十个数字,但是这十个数字不能重复(用C语言或者OC实现)
- DirectX-3d中.x模型转换成three.js可用的obj文件或者js文件
- osg选取
- 37 WebGL多个模型组成一个复杂的模型