|
本帖最后由 chenwei2007gs 于 2011-5-15 10:05 编辑
我按下面的方法画轨迹,怎么画不出来,其中_body为一个运动的节点,继承自osg::MatrixTransform
-
- osg::ref_ptr<osg::Node> Parent::setdot()
- {
- osg::ref_ptr<osg::Geometry> geom= new osg::Geometry;
- osg::ref_ptr<osg::Vec3Array> track= new osg::Vec3Array;
- osg::ref_ptr<osg::Geode> geode=new osg::Geode;
- geom->setVertexArray(track.get());
- bb=_body->getBound();
- track->push_back(bb.center());
- if(track->getNumElements()>1) {
- geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP,0,track->getNumElements()));
- osg::ref_ptr<osg::Vec4Array> c = new osg::Vec4Array();
- geom->setColorArray(c.get());
- geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
- c->push_back(osg::Vec4(1,0,0,1)); // 标记红色
- }
- geode->addDrawable(geom.get());
- track->dirty();
- return geode.get();
- }
- void Parent::update(void)
- {
- _body->addChild(setdot());
- }
复制代码 |
|