I want to draw  a line, and to update this line with more points.

Now i render the line, but as soon I do a update which changes the vertices 
size the line dissapears.

please submit an example / suggestions if anyone have, before im going totally 
nuts! :)

PS.

1. Im doing the update via a callback ( in the frame() traversal)
2. Also all osg objects are set to DYNAMIC
3. and the positions are correct
4. i use osg 2.4.0 on vista
5. i use SceneViewer in an Embedded window to render

My code is something like this:

MyClass : public Group
{
      osg::ref_ptr<osg::Geode>           _lineGeode;
      osg::ref_ptr<osg::Geometry>        _line;
      osg::ref_ptr<osg::DrawArrays>      _drawArrays;
      osg::ref_ptr<osg::Vec3Array>       _vertices;
      osg::ref_ptr<osg::StateSet>        _lineStateSet;

MyClass()           // INIT My Osg variables
{
      // stateset attributes
      _lineStateSet = new osg::StateSet;
      _lineStateSet->setDataVariance(osg::Object::DYNAMIC);

      // create line primitive
      _vertices = new osg::Vec3Array;
      _vertices->setDataVariance(osg::Object::DYNAMIC);

      _line = new osg::Geometry;
      _line->setDataVariance(osg::Object::DYNAMIC);
      _line->setVertexArray(_vertices.get());
      _line->setStateSet(_lineStateSet.get());

      //_line->setUseDisplayList(false);
      //_line->setUseVertexBufferObjects(false);

      _drawArrays = new osg::DrawArrays;
      _drawArrays->setDataVariance(osg::Object::DYNAMIC);

      _line->addPrimitiveSet(_drawArrays.get());

      _lineGeode = new osg::Geode;
      _lineGeode->setDataVariance(osg::Object::DYNAMIC);
      _lineGeode->addDrawable(_line.get());

      addChild(_lineGeode.get());
}

Update()
{
      //_vertices->clear();   // TRIED THIS FIRST

      _vertices = new osg::Vec3Array(_size);
      _vertices->setDataVariance(osg::Object::DYNAMIC);

      double x,y,z;

      for(int i=0; i<_size; i++)
      {

            MyGet(x,y,z);

            //_vertices->push_back(osg::Vec3((float)x,(float)y,(float)z);

            (*_vertices)[i].set((float)x,(float)y,(float)z);
      }
      _drawArrays->set(osg::PrimitiveSet::LINE_STRIP, 0, _size);



                               // PS HAVE TRIED LOT OF DIFFERENT VARIATIONS OF 
THESE
      _drawArrays->dirty();

      _line->setVertexArray(_vertices.get());
      _line->setPrimitiveSet(0,_drawArrays.get());

      _lineGeode->setDrawable(0, _line.get());
      _lineGeode->dirtyBound();

      dirtyBound();
}

Thank you very much!

Erlend

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to