|
现在为实现线框的编辑,使用PolytopeIntersector找出鼠标点击射线与线框的交点,再用矩阵变换变为本地坐标,但是点添加上去明显有误差。本人新手,求高人指点!- osg::ref_ptr<osgUtil::PolytopeIntersector> OsgIntersectorEventHandler::getPolytopeIntersector(
- const osgGA::GUIEventAdapter& aEventAdapter,
- const double& aWidth,
- const double& aHeight)
- {
- double centerX = aEventAdapter.getXnormalized();
- double centerY = aEventAdapter.getYnormalized();
- osg::ref_ptr<osgUtil::PolytopeIntersector> picker(
- new osgUtil::PolytopeIntersector(
- osgUtil::Intersector::PROJECTION,
- centerX - aWidth,
- centerY - aHeight,
- centerX + aWidth,
- centerY + aHeight)
- );
- return picker;
- }
- void IntersectionEditEventHandler::handleIntersector(
- const osgGA::GUIEventAdapter& aEventAdapter,
- const bool& aMouseDown)
- {
- osg::ref_ptr<osgUtil::PolytopeIntersector> picker = getPolytopeIntersector(aEventAdapter, 0.001, 0.001);
- osgUtil::IntersectionVisitor intersectionVisitor(picker);
- _viewer->getCamera()->accept(intersectionVisitor);
- bool isNearFrame = false;
- if (picker->containsIntersections())
- {
- BOOST_FOREACH(const osgUtil::PolytopeIntersector::Intersection & intersection, picker->getIntersections())
- {
- osg::NodePath nodes = intersection.nodePath;
- BOOST_FOREACH(osg::Node * node, nodes)
- {
- if (node->getName() == "IntersectionFrame")
- {
- isNearFrame = true;
- if (aMouseDown)
- {
- osg::Vec3 intersectionPoint =
- intersection.matrix->preMult(intersection.localIntersectionPoint);
- AddVertexToIntersection(intersectionPoint);
- break;
- }
- }
- }
- }
- }
- IsNearFrame(isNearFrame);
- }
复制代码 原线框:
加点后:
|
-
|