如何在 Open Inventor 3D Graphics API 中画一条线?
How can I draw a line in Open Inventor 3D Graphics API?
我是 Open Inventor 3D Graphics 的新手 API,我只想在给定的 3-D 坐标之间画一条线。假设第一个点是 0,0,0,第二个点是 1,1,1。这个 API 的文档和示例真的很糟糕,无法正确表达。我正在使用 Visual Studio.
假设您只是询问有关创建线形的问题 - 只需将坐标存储在 SoVertexProperty 节点中,将该节点设置在 SoLineSet 节点中,然后将线集添加到您的场景图中。 Open Inventor 将假设您想要使用所有给定的坐标,所以这就是您需要做的全部。
对于只有两个坐标,使用 set1Value 方法可能是最简单的,但您也可以从数组中设置坐标。你没有说你使用的是哪种语言,所以我将用 C++ 显示代码(C# 和 Java 除了语言语法差异外基本相同):
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 );
如果您只需要设置基色(Open Inventor 和 OpenGL 称之为漫反射颜色),对于线几何体通常就是这种情况,那么您可以直接在 SoVertexProperty 节点中进行设置。
例如,要使前面示例中的行 'red',添加此行:
vprop->orderedRGBA = 0xff0000ff; // By default applies to all vertices
或者,更方便:
vprop->orderedRGBA = SbColor(1,0,0).getPackedValue();
如果您需要更多地控制几何体的外观,请在几何体节点之前将 SoMaterial 节点添加到场景图中。
通过创建 SoDrawStyle 属性 节点并将其添加到场景图 before/above 几何节点来指定线宽。像这样:
SoDrawStyle* style = new SoDrawStyle();
style->lineWidth = 3; // "pixels" but see OpenGL docs
parent->addChild( style );
我是 Open Inventor 3D Graphics 的新手 API,我只想在给定的 3-D 坐标之间画一条线。假设第一个点是 0,0,0,第二个点是 1,1,1。这个 API 的文档和示例真的很糟糕,无法正确表达。我正在使用 Visual Studio.
假设您只是询问有关创建线形的问题 - 只需将坐标存储在 SoVertexProperty 节点中,将该节点设置在 SoLineSet 节点中,然后将线集添加到您的场景图中。 Open Inventor 将假设您想要使用所有给定的坐标,所以这就是您需要做的全部。 对于只有两个坐标,使用 set1Value 方法可能是最简单的,但您也可以从数组中设置坐标。你没有说你使用的是哪种语言,所以我将用 C++ 显示代码(C# 和 Java 除了语言语法差异外基本相同):
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 );
如果您只需要设置基色(Open Inventor 和 OpenGL 称之为漫反射颜色),对于线几何体通常就是这种情况,那么您可以直接在 SoVertexProperty 节点中进行设置。
例如,要使前面示例中的行 'red',添加此行:
vprop->orderedRGBA = 0xff0000ff; // By default applies to all vertices
或者,更方便:
vprop->orderedRGBA = SbColor(1,0,0).getPackedValue();
如果您需要更多地控制几何体的外观,请在几何体节点之前将 SoMaterial 节点添加到场景图中。
通过创建 SoDrawStyle 属性 节点并将其添加到场景图 before/above 几何节点来指定线宽。像这样:
SoDrawStyle* style = new SoDrawStyle();
style->lineWidth = 3; // "pixels" but see OpenGL docs
parent->addChild( style );