Martin Großer wrote:
Hello all,

maybe the subject isn't very significant, but I would like explane my idea. I would like visualize a vector field. I have a gird and every grid cell have a velocity value in x and in y. Also I have the array _x and _y. Now I create a geometry and a vertex array:

osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;

[...]

vertices->push_back( osg::Vec3(0,0,0.0) );
vertices->push_back( osg::Vec3(_x[i], _y[j], 0.0) );

Now I change the values of _x and _y during the runtime, but the geometry isn't changing. I would like pass a pointer to the osg::Vec3 and use the function "dirtyDisplayList".

vertices->push_back( osg::Vec3(&_x[i], &_y[j], 0.0) );
[...]
geom->dirtyDisplayList();

Hi, Martin,


If I understand you correctly, you've got a couple of issues.

First, make sure you tell OSG that the geometry's data will be changing:

geom->setDataVariance(osg::Object::DYNAMIC);


Second, you can avoid having to call dirtyDisplayList() every frame by simply disabling display lists:

geom->setUseDisplayList(false);


Finally, do you call clear() on the vertex array before adding the new vertex values? If not, you're just adding values to the end of the array which will never be drawn. Try this instead:


osg::Vec3Array::iterator itr;
itr = vertices.begin();
int i = 0;
while (itr != vertices.end())
{
  itr->set(&_x[i], &_y[i], 0.0);
  itr++;
  i++;
}


I'm assuming the number of vectors is fixed, of course. If that can change, you'll have to alter the code a bit.

Hope this helps...

--"J"
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to