Your geometry is probably using display lists (on by default).
setVertexArray will dirty and rebuild them. A more efficient solution would
be to disable display lists. If you do that, you should be able to change
individual elements of your array and not have to set the entire array.

Paul Martz
Skew Matrix Software LLC
http://www.skew-matrix.com
+1 303 859 9466

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Allen
Saucier
Sent: Wednesday, April 15, 2009 3:26 PM
To: [email protected]
Subject: Re: [osg-users] Dinamic Line Drawing

boooch (and anyone who might have suggestions...),

I really appreciate the code you posted but I can't get it to work as you
did.  The ONLY way I was able to get the "lines" drawn was to RE-set the
vertexArray  of  my geometry.  Like so:
m_ogeomTrailGeometry->setVertexArray(vad);

However, this is an extremely expensive operation.  Do you have any
suggestions that I might try to lower my re-draw expense?


Here's my code snippet:


class class1
{
public:
    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; 

}

class1::method_1(double xInitial, double yInitial, double zInitial) {
  // initialize previous to current point/position sent in
  m_ov3dPrevPos.set(xInitial, yInitial, zInitial);
  // curr pos
  osg::Vec3d ov3d(xInitial, yInitial, zInitial);

  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 pos
  m_ov3aLineVerticesData->push_back(ov3d);          // curr pos    

  m_podreTrailDrawElements->setFirst(0);
  m_podreTrailDrawElements->setCount(m_ov3aLineVerticesData->size());
  
  
  m_ogeomTrailGeometry->addPrimitiveSet(m_podreTrailDrawElements.get());
  m_ogeomTrailGeometry->setVertexArray(m_ov3aLineVerticesData.get());// add
line segs to geometry
  m_ogeoTrailGeode->addDrawable(m_ogeomTrailGeometry.get());

  
  // ADD ONLY ONCE to the Node Scene
  m_no3vViewer->m_iAddElementToScene(m_ogeoTrailGeode.get());
} // method_1()


class1::method_updateLine(double x, double y, double z) {
  osg::Vec3Array *vad = dynamic_cast<osg::Vec3Array
*>(m_ogeomTrailGeometry->getVertexArray());
  vad->push_back(osg::Vec3(x,y,z));
  
  osg::DrawArrays *drArrys = dynamic_cast<osg::DrawArrays
*>(m_ogeomTrailGeometry->getPrimitiveSet(0));
  drArrys->setFirst(0);
  drArrys->setCount(vad->size());
  //drArrys->dirty();
  //std::cout<<" vad->size()=="<< vad->size() << std::endl;
  m_ogeomTrailGeometry->setVertexArray(vad);
}

------------------------
----
Allen

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=10277#10277





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

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

Reply via email to