Re: [osg-users] Building an Altimeter
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 = 10; int numMarkers = (distance-surfaceE)/interval; osg::Geometry* marker[numMarkers]; //Construct elevation marks for(int i = 0; inumMarkers;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
Re: [osg-users] Building an Altimeter
Thanks all, I tried setting the lighting mode to off and it worked fine, but extremely slowly. I managed to fix that by placing all the vertexes in a single Geometry object and using LINES to draw them in pairs, with the central line occupying [0] and [1], needing to only set the lighting mode once for the entire altimeter :) Cheers, Rusty -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=38408#38408 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[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 = 10; int numMarkers = (distance-surfaceE)/interval; osg::Geometry* marker[numMarkers]; //Construct elevation marks for(int i = 0; inumMarkers;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.org
Re: [osg-users] Building an Altimeter
I should add that the reason the marker dimension is being hardcoded into the x axis because at this point I'm positioning the spacecraft along the Y axis. I was considering creating in a way similar to this every time, then rotating it to match the lander, but would be open to a more dynamic solution that find the perpendicular vectors and orients the markers accordingly. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=38373#38373 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Building an Altimeter
On 4/9/2011 2:44 PM, Rusty Shackleford wrote: 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. Is this a 3D thing that lives in the world with the spacecraft, or a 2D thing on screen? If it's 2D, there's an example called osgScalarBar that might be a starting point to gain inspiration from. 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). You can turn off lighting as a stateset to make it always remain fully lit. Osg Text has Autotransform capabilities built in to keep it always facing the camera. -- Chris 'Xenon' Hanson, omo sanza lettere. xe...@alphapixel.com http://www.alphapixel.com/ Digital Imaging. OpenGL. Scene Graphs. GIS. GPS. Training. Consulting. Contracting. There is no Truth. There is only Perception. To Perceive is to Exist. - Xen ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org