Here's my working code, Sergey:
// CLASS
//
class COsgPaxNodeSceneElementInfo
{
public:
// TRAIL components
//
osg::ref_ptr<osg::DrawArrays> m_podreTrailDrawElements;
osg::ref_ptr<osg::Vec3Array> m_ov3aLineVerticesData;
osg::ref_ptr<osg::Geometry > m_ogeomTrailGeometry;
osg::ref_ptr<osg::Geode> m_ogeoTrailGeode;
osg::Vec3d m_ov3dPrevPos;
void COsgPaxNodeSceneElementInfo::m_vConstructATrail(double x, double y, double
z);
void COsgPaxNodeSceneElementInfo::m_vUpdateTrail( double x2, double y2, double
z2);
}; // class
// CALLED BEFORE I ATTEMPT TO UPDATE A TRAIL
//
void COsgPaxNodeSceneElementInfo::m_vConstructATrail(double x, double y, double
z)
{
// initialize previous to current point/position sent in
m_ov3dPrevPos.set(x,y,z);
// curr pos
osg::Vec3d ov3d(x,y,z);
// ALLOCATE ONCE AND ONLY ONCE
m_podreTrailDrawElements= new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP);
m_ov3aLineVerticesData = new osg::Vec3Array();
m_ogeomTrailGeometry = new osg::Geometry();
m_ogeoTrailGeode = new osg::Geode;
m_ov3aLineVerticesData->push_back(m_ov3dPrevPos); // prev position
m_ov3aLineVerticesData->push_back(ov3d); // curr position
m_podreTrailDrawElements->setFirst(0);
m_podreTrailDrawElements->setCount(m_ov3aLineVerticesData->size());
m_ogeomTrailGeometry->addPrimitiveSet(m_podreTrailDrawElements.get());
m_ogeomTrailGeometry->setVertexArray(m_ov3aLineVerticesData.get());
// attempt to draw lines faster by disabling display lists &
// then with each new vertex added, call dirtyBound() on the geometry.
m_ogeomTrailGeometry->setUseDisplayList(false);
m_ogeoTrailGeode->addDrawable(m_ogeomTrailGeometry.get());
// ADD ONLY ONCE to the Node Scene
root->addChild(m_ogeoTrailGeode.get());
} // m_vConstructATrail
// CALLED PERIODICALLY
//
void COsgPaxNodeSceneElementInfo::m_vUpdateTrail(
double x2, double y2, double z2)
{
m_ov3aLineVerticesData->push_back(osg::Vec3(x2,y2,z2)); // curr position
m_podreTrailDrawElements->setFirst(0);
m_podreTrailDrawElements->setCount(m_ov3aLineVerticesData->size());
m_ogeomTrailGeometry->dirtyBound();// forces needed boundary recalc
} // m_vUpdateTrail
After much experimentation, I got this to work, though, it is still not quite
right. I have no color and did not know how to set that up. But from your
code, I now know how to do that. :)
Still, osg, redraws ALL of the line segments instead of the very last one
added. I would prefer it to only draw the last one added. That would be 1000
times faster. 8)
I found that I had to have m_ogeomTrailGeometry->setUseDisplayList(false); set
to false and I had to call m_ogeomTrailGeometry->dirtyBound(); in order to get
my code to work at all.
Hope this helps :?
------------------------
Allen
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=10527#10527
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org