|
现在我已经能在地面上点击一个点,垂直拖拽,松开键位后形成一条直线~可是问题来了,效果确实实时画这条线的时候,线不跟鼠标拖动走(鼠标到哪里,线就垂直拉到一个高度)。。。。而且鼠标刚一Drag。。线就窜得老高!!
handle中有关此部分的代码和问题截图已贴出,求高手们详细指点和纠正~调了好几天了,不知道怎么改了
- case osgGA::GUIEventAdapter::PUSH:
- {
- if(ea.getButton() == 1)
- {
- osgUtil::LineSegmentIntersector::Intersections intersections;
- float x=ea.getX();
- float y=ea.getY();
-
- if (viewer->computeIntersections(x,y,intersections))
- {
- for (osgUtil::LineSegmentIntersector::Intersections::iterator hitr=intersections.begin();hitr!=intersections.end();++hitr)
- {
- m_point=osg::Vec3( hitr->getWorldIntersectPoint());
- pointList->push_back(m_point);
- vertices->push_back(pointList->at(0));
- _current_geometry->setVertexArray(vertices);
- osg::ref_ptr <osg::Vec4Array> colors = new osg::Vec4Array;
- colors->push_back( osg::Vec4( 1.0f, 0.0f, 0.0f, 1.0f) );//红色
- _current_geometry->setColorArray(colors);
- _current_geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
- _current_geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP,0,1));
- return true;
- }
- }
- else
- {
- std::cout<<"必须在地面上选择一个点!";
- return false;
- }
- }
- }
- case osgGA::GUIEventAdapter::DRAG:
- {
- vertices = dynamic_cast<osg::Vec3Array*>(_current_geometry->getVertexArray());
- osg::Matrix mtxModelView= viewer->getCamera()->getViewMatrix();
- osg::Matrix mtxProject = viewer->getCamera()->getProjectionMatrix();
- osg::Matrix mtxWindow = viewer->getCamera()->getViewport()->computeWindowMatrix();
- osg::Vec3 vecWindowPt(ea.getX(), ea.getY(), 0.0f);
- osg::Matrix mtxMVPW = mtxModelView * mtxProject * mtxWindow;
- osg::Matrix mtxInverseMVPW = osg::Matrix::inverse(mtxMVPW);
- osg::Vec3 vecWorldPt = vecWindowPt * mtxInverseMVPW;
- osg::Vec3 WorldPt(vertices->at(0).x(),vertices->at(0).y(),vecWorldPt.z());
- vertices->push_back(WorldPt);
- dynamic_cast<osg::DrawArrays*>(_current_geometry->getPrimitiveSet(0))->setCount(vertices->size());
- _current_geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP,0,2));
- _current_geometry->getPrimitiveSet(0)->dirty();
- _current_geometry->dirtyDisplayList();
- return true;
- }
- case osgGA::GUIEventAdapter::RELEASE:
- {
- _current_geometry = NULL;
- return true;
- }
复制代码 问题效果:
|
|