/*---------------------------------------------------------------------------------------------------------- FUNCTION: SoSeparator *makeProfileLineSet();定义剖面的场景示意图 Main(int, char **argv);主函数按照场景示意图绘制场景 PURPOSE: 利用面集节点(SoLineSet)绘制两个四边形的剖面。 HISTORY: Date:26/11/2007 Author:Shao Yanhong Comment: ---------------------------------------------------------------------------------------------------------*/ #include "assert.h" #include <Inventor\Win\SoWin.h> #include <Inventor\Win\viewers\SoWinExaminerViewer.h> #include <Inventor\nodes\SoCoordinate3.h> #include <Inventor\nodes\SoLineSet.h> #include <Inventor\nodes\SoMaterial.h> #include <Inventor\nodes\SoSeparator.h> #include <Inventor\nodes\SoVertexProperty.h> static const float lineVertices[16][3] = { // 定义两个剖面 { 1.0f, 2.0f, 1.0f}, { 2.0f, 2.0f, 1.0f}, //顶面四条边 { 2.0f, 2.0f, 1.0f}, { 2.0f, 2.0f, 2.0f}, { 2.0f, 2.0f, 2.0f}, { 1.0f, 2.0f, 2.0f}, { 1.0f, 2.0f, 2.0f}, { 1.0f, 2.0f, 1.0f}, { 1.0f, 1.0f, 1.0f}, { 2.0f, 1.0f, 1.0f}, //底面四条边 { 2.0f, 1.0f, 1.0f}, { 2.0f, 1.0f, 2.0f}, { 2.0f, 1.0f, 2.0f}, { 1.0f, 1.0f, 2.0f}, { 1.0f, 1.0f, 2.0f}, { 1.0f, 1.0f, 1.0f}, }; // 每个边中顶点的个数 static int numvertices[8] = {2, 2, 2, 2, 2, 2, 2, 2}; SoSeparator *makeProfileLineSet() { SoSeparator *profile = new SoSeparator(); profile->ref(); // 定义剖面线框的材质 SoMaterial *myMaterial = new SoMaterial; myMaterial->diffuseColor.setValue(1.0f, 0.0f, 0.0f); myMaterial->ambientColor.setValue(1.0f, 0.8f, 0.8f); profile->addChild(myMaterial); // 定义定点的坐标 SoCoordinate3 *myCoords = new SoCoordinate3; myCoords->point.setValues(0, 16, lineVertices); profile->addChild(myCoords); // 定义SoLineSet线集 SoLineSet *myLineSet = new SoLineSet; myLineSet->numVertices.setValues(0, 8, numvertices); profile->addChild(myLineSet); profile->unrefNoDelete(); return profile; } int main(int, char **argv) { HWND myWindow = SoWin::init(argv[0]); if (myWindow == NULL) exit(1); SoSeparator *root = new SoSeparator; root->ref(); root->addChild(makeProfileLineSet()); SoWinExaminerViewer *myViewer = new SoWinExaminerViewer(myWindow); myViewer->setSceneGraph(root); myViewer->setBackgroundColor(SbColor(0.9f, 0.9f, 0.95f)); myViewer->setTitle("Two Profiles"); myViewer->show(); myViewer->viewAll(); SoWin::show(myWindow); SoWin::mainLoop(); return 0; }