Allen,

Your code has the following line:

 m_ogeomTrailGeometry->dirtyBound();  // forces redraw

dirtyBound does not force a redraw. It simply recalculates the bounding
volume for the geometry. The problem you were having before was that the
geometry was being clipped because the bounding volume was incorrect.

Your performance issues can be due to a number of things.

How many verts do you have?

Brian


This is a PRIVATE message. If you are not the intended recipient, please
delete without copying and kindly advise us by e-mail of the mistake in
delivery.
NOTE: Regardless of content, this e-mail shall not operate to bind CSC to
any order or other contract unless pursuant to explicit written agreement
or government initiative expressly permitting the use of e-mail for such
purpose. •


-----osg-users-boun...@lists.openscenegraph.org wrote: -----


To: osg-users@lists.openscenegraph.org
From: "Allen Saucier" <allen.sauc...@itt.com>
Sent by: osg-users-boun...@lists.openscenegraph.org
Date: 04/16/2009 05:05PM
Subject: Re: [osg-users] Dinamic Line Drawing

Thx everyone!! for the help. :D :D  You've given me a lot to think about.
I really appreciate your time.

J-S, here's my code that now works but still "drags" a little after a few
thousand iterations.  I found that setVertexArray is (I believe, but could
be totally wrong) actually "copying" the array I send it.  After a few
thousand times of being called, it really slows down my entire interface.
In fact, my interface Almost crawls to a halt calling setVertexArray() each
time through the frame loop after about 4000 calls to it.

And I'm drawing a LOT of small line segments each millisecond to make up
the long "looking" line.

I'm not using vertex buffer objects... yet.  if I need to switch to them, I
will.  Though that will be in the land of experimentation for me too. ha,
ha,... :-)

I found that dirtyDisplayList() w.o dirtyBound() did nothing.  I found that
dirtyBound() worked all by itself to get the line to draw during each
iteration of my osg::viewer::frame loop.

I'm using osg::PrimitiveSet::LINE_STRIP as my primitive type and I do not
need to push_back 2 vertices per line segment - I think. [Embarassed] At
least, my line is being drawn... :)

Honestly, I think it's the way I'm drawing the line.  I don't believe there
is a bug in OSG. I'm just to new @ this stuff.. ha, ha...

here's my code: snippets of it: the 2 main methods w/in my class are 1)
setup my line and 2) then to add to that line one new vertex at a time.
This code actually works but it does 'slow' down after a few thousand
iterations and then speeds up.. and slows down and speeds up...

class COsgPaxNodeSceneElementInfo
{
   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;                  ///<
   previous trail head
   bool m_bHasTrail;

void m_vConstructATrail(math::Vector3D &p_v3dVec);
void m_vUpdateTrail(model::PlatformStateVector &p_psvState);
};

void COsgPaxNodeSceneElementInfo::m_vConstructATrail(math::Vector3D
&p_v3dVec)
{
 // initialize previous to current point/position sent in
 m_ov3dPrevPos.set(p_v3dVec.getX(), p_v3dVec.getY(), p_v3dVec.getZ());
 // curr pos
 osg::Vec3d ov3d(p_v3dVec.getX(), p_v3dVec.getY(), p_v3dVec.getZ()););

 // 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 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());
 // 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
 m_no3vViewer->m_iAddElementToScene(m_ogeoTrailGeode.get()); // equivalent
 to root->addChild(m_ogeoTrailGeode.get());  but "root" of the osg node
 scene is actually located w/in another class object, not this one.

 // keep track of fact that this node scene elem has a trail
 m_bHasTrail = true;
} // m_vConstructATrail



void COsgPaxNodeSceneElementInfo::m_vUpdateTrail(
 model::PlatformStateVector &p_psvState)
{
 if (!m_bHasTrail)
   return;

 static bool b_trailIsShowing=true; // trails on be default
 static double x,y,z;
 x=p_psvState.getPosition().getX();
 y=p_psvState.getPosition().getY();
 z=p_psvState.getPosition().getZ();

 // for now, just keep current PTL around;
 //  unused @ moment, however
 m_dPtl=p_psvState.getOrientation().getW();

 m_ov3aLineVerticesData->push_back(osg::Vec3(x,y,z)); // prev pos
 m_podreTrailDrawElements->setFirst(0);
 m_podreTrailDrawElements->setCount(m_ov3aLineVerticesData->size());

 m_ogeomTrailGeometry->dirtyBound();  // forces redraw

} // m_vUpdateTrail

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

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





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

Reply via email to