Hi all,

I was wanting to use an AutoTransform as a label for 3D elements in my scene. 

I have been able to create the Autotransform and add text, etc.

However when I try to draw a line between the position of the autotransform and 
the bound of the object, I don't see any line drawn.

I found this puzzling and couldn't figure out why. 

Any help on this issue would be much appreciated. 

Just to double check: For the purpose of creating labels, is a Billboard more 
suitable or an auto transform?

(code realted to autotransform is pasted at the end of my post)

Thanks.

Sincerely,
Sanat


Code:

  //create Auto transform to use as a label
  osg::ref_ptr<osg::AutoTransform> at1 = new osg::AutoTransform();
  osg::Geode* at1Geode = new osg::Geode();
  
  //create txt node
  osgText::Text* text1 = new osgText::Text();
  text1->setFont("timesFont");
  text1->setCharacterSize(30.0);
  text1->setText("Pipe1 Owner= DTE");
  text1->setAlignment(osgText::Text::CENTER_CENTER);
  //add text to geode
  at1Geode->addDrawable(text1);
  at1->addChild(at1Geode);
 
  //setup auto transform's properties:
  at1->setPosition(osg::Vec3d(276377.22, 4685748.0, 1000.0));
  at1->setAutoScaleToScreen(true);
  at1->setAutoRotateMode(osg::AutoTransform::ROTATE_TO_SCREEN);
  
  //draw line from autotransform to geometry object
  //create geode and geometry:
  osg::ref_ptr<osg::Geode> lineGeode = new osg::Geode();
  osg::Geometry* lineGeometry = new osg::Geometry();

  //vertex array
  osg::Vec3Array* vertexArray = new osg::Vec3Array(2);
  vertexArray->push_back(at1->getPosition());
  osg::Vec3 vertex2 = osg::Vec3 (276377.22, 4685748.0, 800.0);

  //color array
  osg::Vec4Array* colorArray = new osg::Vec4Array(2);
  osg::Vec4 yellowColor = osg::Vec4(1.0, 0.0, 0.0, 1.0);
  colorArray->push_back(yellowColor);
 
  //add arrays to geometry
  lineGeometry->setVertexArray(vertexArray);
  lineGeometry->setColorArray(colorArray);
  lineGeometry->setColorBinding(osg::Geometry::BIND_OVERALL);
  lineGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 
0, vertexArray->size()));
  
  //attach geometry to geode
  lineGeode->addDrawable(lineGeometry);
  lineGeode->getOrCreateStateSet()->setMode(GL_LIGHTING, 
osg::StateAttribute::OFF);
  
  //add the geode to the at1
  at1->addChild(lineGeode);
  
  //add pipe1 node to group
  group1->addChild(pipe1.get());
  group1->addChild(at1.get());



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





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

Reply via email to