Search code examples
graphicsopeninventorcoin3d

How can I draw a line in Open Inventor 3D Graphics API?


I'm new to Open Inventor 3D Graphics API and I just want to draw a line between given to 3-D coordinates. Let's say the first point is 0,0,0 and the second is 1,1,1. The documentation and examples of this API are really awful and can't get it out right. I'm using Visual Studio.


Solution

  • Assuming you're just asking about creating the line shape - just store the coordinates in an SoVertexProperty node, set that node in an SoLineSet node, then add the line set to your scene graph. Open Inventor will assume that you want to use all the coordinates given, so that's all you need to do. For just two coordinates it may be easiest to use the set1Value method, but you can also set the coordinates from an array. You didn't say which language you're using, so I'll show the code in C++ (C# and Java would be essentially the same except for language syntax differences):

    SoVertexProperty* vprop = new SoVertexProperty();
      vprop->vertex.set1Value( 0, 0,0,0 );  // Set first vertex to be 0,0,0
      vprop->vertex.set1Value( 1, 1,1,1 );  // Set second vertex to be 1,1,1
    
    SoLineSet* line = new SoLineSet();
      line->vertexProperty = vprop;
    
    sceneGraph->addChild( line );