Rusty, If your altimeter renders correctly and gives you correct results, then I'd say your implementation is probably fine. There are plenty of OSG examples and tutorials that you can compare with to see if you're on the right track.
On understanding how normals are used, I would suggest that you learn about how OpenGL renders objects in a scene since OSG uses OGL for its rendering. The normals in a primitive are only used when lighting is enabled. There are normals that are used for culling but that's another discussion. If you want your lines to always appear bright red, don't use normals, turn off lighting, and specify the color red before drawing the line. Color can be specified per primitive or per vertex depending on what you want to do. -Shayne -----Original Message----- From: osg-users-boun...@lists.openscenegraph.org [mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Rusty Shackleford Sent: Saturday, April 09, 2011 2:45 PM To: osg-users@lists.openscenegraph.org Subject: [osg-users] Building an Altimeter Hi, I'm working on a tool that visualizes a spacecraft in orbit around a planetary body. As it is set up now, the position of that spacecraft is given relative to the center of the body as an x,y,z coordinate. What I'm trying to do right now is set up a simple altimeter that looks essentially like a ruler reaching from the planetary surface up to a little past the spacecraft. That is, a straight line with perpendicular lines crossing it at regular intervals. The black circle is the spacecraft, the black blob at the bottom is the planetary surface, and I'm trying to draw that "ladder" with regular demarkations. I'm VERY new at OSG (two weeks in) so I could be going about this completely wrong, please let me know if so. What needs to happen is for the altimeter to follow the spacecraft (position given by "end" in the code) such that the central line always intersects it and the origin stays at the center of the planet (given by "start"). I've included the code here for building the altimeter. It outputs a group that is attached to the root node to which the planet is also attached. Code: osg::Group* Visualizer::getAltimeter(osg::Vec3 start, osg::Vec3 end, int interval) { int distance = sqrt(pow(end[0]-start[0],2) + pow(end[1]-start[1],2) + pow(end[2]-start[2],2)); osg::Group* g = new osg::Group(); osg::Geode* geode = new osg::Geode(); //Line running up the middle osg::Geometry* line_x_red = new osg::Geometry(); osg::Vec3Array* verticesx = new osg::Vec3Array(2); (*verticesx)[0]=start; (*verticesx)[1]=end; line_x_red->setVertexArray(verticesx); // set the color osg::Vec4Array* red = new osg::Vec4Array; red->push_back(osg::Vec4(1.0f,0.0f,0.0f,1.0f)); line_x_red->setColorArray(red); line_x_red->setColorBinding(osg::Geometry::BIND_OVERALL); // set the normal in the same way color. osg::Vec3Array* normals = new osg::Vec3Array; normals->push_back(osg::Vec3(0.0f,0.0f,-1.0f)); line_x_red->setNormalArray(normals); line_x_red->setNormalBinding(osg::Geometry::BIND_OVERALL); line_x_red->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,2)); //Surface of planet, no need to mark below this int surfaceE = 100000; int numMarkers = (distance-surfaceE)/interval; osg::Geometry* marker[numMarkers]; //Construct elevation marks for(int i = 0; i<numMarkers;i++) { marker[i] = new osg::Geometry(); osg::Vec3Array* vertices = new osg::Vec3Array(2); (*vertices)[0]=osg::Vec3(-50,i*interval + surfaceE,0); (*vertices)[1]=osg::Vec3(50,i*interval + surfaceE,0); marker[i]->setVertexArray(vertices); marker[i]->setColorArray(red); marker[i]->setColorBinding(osg::Geometry::BIND_OVERALL); marker[i]->setNormalArray(normals); marker[i]->setNormalBinding(osg::Geometry::BIND_OVERALL); marker[i]->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,2)); geode->addDrawable(marker[i]); } geode->addDrawable(line_x_red); altimeterFrame = new osg::PositionAttitudeTransform(); altimeterFrame->addChild(geode); g->addChild(altimeterFrame); return g; } If this is a good way to go about it, my next question is about normals, which I don't fully understand. I'd like the lines to appear bright red, regardless of which angle they're viewed from. An added bonus would be for the markers to rotate around the central line to always face the camera. I imagine this could be done with Billboards, but some initial experimentation showed I have a lot to learn regarding them. This is my first post on this board, so excuse me if I've missed a point of etiquette, I'd be glad to elaborate on anything if need be. All advice is greatly appreciated. Thank you! Cheers, Rusty ------------------ Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=38368#38368 _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or g _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org