Hi, David

try to replace
osg::ref_ptr<osg::DrawArrays> da = new osg::DrawArrays( 
osg::PrimitiveSet::LINES, 1, 2 ) ;
with
osg::ref_ptr<osg::DrawArrays> da = new osg::DrawArrays( 
osg::PrimitiveSet::LINES, 0, 2 ) ;

Cheers

21.10.2011, 04:29, "David Smith" <[email protected]>:
> Hello,
>
> I'm having trouble with drawing a line.
>
> A little background. I have a graph with vertices and edges represented in 
> the boost graph library. I am using boost to find some coordinates for me to 
> layout the graph graphically. For each vertex I then draw a model at its 
> location. For each edge I then attempt to draw a line between the locations 
> of the models. Problem is that doesn't work. The lines go from the origin to 
> the vertices. It does not go from vertex to vertex. Now some code:
>
> Code:
>
> for ( ; it != end ; ++it ) {
>  VertexID id = *it ;
>  Vertex* vertex = &(*ng)[id] ;
>  osg::ref_ptr<osg::Node> cModel =
>     (osg::Node*)model->clone(osg::CopyOp::DEEP_COPY_NODES ) ;
>
>  printf( "%d, x=%f, y=%f, z=%f\n", id, vertex->point[0], 0.0f, 
> vertex->point[1] ) ;
>  osg::ref_ptr<osg::PositionAttitudeTransform> transform = new 
> osg::PositionAttitudeTransform( )  ;
>  transform->setPosition( osg::Vec3f( vertex->point[0], 0.0f, vertex->point[1] 
> ) ) ;
>  transform->addChild( cModel ) ;
>
>  root->addChild( transform ) ;
> }
>
> boost::tie( eit, eend ) = edges(*ng) ;
> for( ; eit != eend ; ++eit ) {
>  EdgeID ide = *eit ;
>  Edge& edge = (*ng)[ide] ;
>  VertexID srcId = source( ide, *ng ) ;
>  VertexID dstId = target( ide, *ng ) ;
>  Vertex* src = &(*ng)[srcId] ;
>  Vertex* dst = &(*ng)[dstId] ;
>
>  printf( "%d, x=%f, y=%f, z=%f\n", dstId, dst->point[0], 0.0f, dst->point[1] 
> ) ;
>  printf( "%d, x=%f, y=%f, z=%f\n", srcId, src->point[0], 0.0f, src->point[1] 
> ) ;
>
>  osg::Geometry* lg = new osg::Geometry( ) ;
>
>  osg::Vec3Array* vs = new osg::Vec3Array( )  ;
>  vs->push_back( osg::Vec3f( src->point[0], 0.0f, src->point[1] ) ) ;
>  vs->push_back( osg::Vec3f( dst->point[0], 0.0f, dst->point[1] ) ) ;
>
>  lg->setVertexArray( vs );
>
>  osg::ref_ptr<osg::DrawArrays> da = new osg::DrawArrays( 
> osg::PrimitiveSet::LINES, 1, 2 ) ;
>  lg->addPrimitiveSet( da ) ;
>  osg::ref_ptr<osg::Geode> lgeode = new osg::Geode( ) ;
>
>  lgeode->addDrawable( lg ) ;
>  root->addChild( lgeode ) ;
> }
>
> Now consider these two vertices:
> 0, x=10.000000, y=0.000000, z=0.000000
> 1, x=9.510565, y=0.000000, z=3.090170
>
> I add the model at each of them with a transform and then I draw a line from 
> one point to another. No translations are done as seen in the code above.
>
> So, what am I doing wrong? Do I need to draw a line and then translate it?
>
> Thanks!
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=43477#43477
>
> _______________________________________________
> 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