|
- osg::ref_ptr<osg::Geode>geode=new osg::Geode;
- osg::ref_ptr<osg::Geometry>geometry=new osg::Geometry;
- _vertexArr->push_back(osg::Vec3(0.0f,0.0f,.0f));
- _vertexArr->push_back(osg::Vec3(2.0f,0.0f,.0f));
- _vertexArr->push_back(osg::Vec3(2.0f,0.0f,2.0f));
- _vertexArr->push_back(osg::Vec3(0.0f,0.0f,2.0f));
- geometry->setVertexArray(_vertexArr);
- geometry->addPrimitiveSet(new osg::DrawArrays(GL_LINE_LOOP,0,_vertexArr->size()));
- geometry->dirtyBound();
- //geometry->setDataVariance(osg::Object::DYNAMIC);
- geometry->setSupportsDisplayList(false);
- //no use at this moment;
- //geometry->setUpdateCallback(new GeometryUpdate);
- geode->addDrawable(geometry.get());
- geode->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
- //set dispaly mode as line mode
- osg::ref_ptr<osg::PolygonMode> polygonMode = new osg::PolygonMode();
- polygonMode->setMode( osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE);
- geode->getOrCreateStateSet()->setAttribute( polygonMode.get(),
- osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON );
- return geode;
复制代码
添加了EventHandler,在EventHandler执行下面的更新函数update
- if (ea.getEventType()==osgGA::GUIEventAdapter::KEYDOWN)
- {
- switch(ea.getKey())
- {
- case osgGA::GUIEventAdapter::KEY_Left:
- std::cout<<"left key down";
- _vertexArr->at(0)._v[0]-=0.5;
- for(osg::Vec3Array::iterator itr=_vertexArr->begin();itr!=_vertexArr->end();++itr)
- {
- std::cout<<"x:"<<(*itr)._v[0]<<" y:"<<(*itr)._v[1]<<" z:"<<(*itr)._v[2]<<std::endl;
- }
- break;
- case osgGA::GUIEventAdapter::KEY_Right:
- _vertexArr->at(0)._v[0]+=0.5;
- break;
- case osgGA::GUIEventAdapter::KEY_Up:
- _vertexArr->at(0)._v[2]+=0.5;
- break;
- case osgGA::GUIEventAdapter::KEY_Down:
- _vertexArr->at(0)._v[2]-=0.5;
- break;
- default:break;
- }
- }
复制代码
开始显示正常,可是移动一个顶点后然后变换视角,发现图元的一部分被裁剪了。不得其解。目前觉得是包围盒相关的原因。不知道怎么解决
移动顶点前
移动顶点后
移动顶点,转换视角
|
|