Hi Basil,
I was expecting this to create a new "trajectory" each time and insert each one
into geode but it looks like it is just appending points into geom and extending the
trajectory instead of putting a new one in. I know the memory situation is a little bit
different with OSG vs. ANSI C++, am I botching it there or how would I approach this?
You are the one who is appending points, not OSG:
geom->setVertexArray(vertexData);
//line width, color, etc set here
for each point in T{
vertexData->push_back(osg::Vec3d(point.X,point.Y,point.Z));
}
drawArrayLines->setFirst(0);
drawArrayLines->setCount(vertexData->size());
If you are reusing the same "vertexData" variable and the same primitive
set, that means all your Geometry objects will be using the same vertex
array, and you're just extending it at each pass through the top-level loop.
Instead try:
for each T in trajectoryList{
osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;
//---- new ----
osg::ref_ptr<osg::DrawArrays> drawArrayLines =
new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP);
osg::ref_ptr<osg::Vec3Array> vertexData = new osg::Vec3Array;
//---- end new ----
geom->addPrimitiveSet(drawArrayLines);
geom->setVertexArray(vertexData);
//line width, color, etc set here
for each point in T{
vertexData->push_back(osg::Vec3d(point.X,point.Y,point.Z));
}
drawArrayLines->setFirst(0);
drawArrayLines->setCount(vertexData->size());
geode->addDrawable( geom.get() );
}
The only thing I added was to create a new vertex array and a new
primitive set at each pass through the top-level loop. That way, each
Geometry object is using a unique vertex array and a unique primitive
set, and you should get what you expected.
Or another way would be to share the same vertex array and append points
to it as you were doing, but use a different primitive set for each
Geometry, with its first element starting at the first vertex you
inserted in this pass through the loop. This will work if your primitive
set uses LINES, but not LINE_STRIP, unless you use a primitive restart
(which I've never used myself so I'm not sure how that works). The
advantage is sharing vertex arrays, so in theory OSG can sort on this
and only set it once and draw many primitive sets, but I'm not even sure
OSG does this, so it may be moot.
Hope this helps,
J-S
--
______________________________________________________
Jean-Sebastien Guay [email protected]
http://www.cm-labs.com/
http://whitestar02.dyndns-web.com/
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org