Debian Codegraph @

apps/examples/Mentor/CXX/05.4.QuadMesh.c++

raw
1 /*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37 /*--------------------------------------------------------------
38 * This is an example from the Inventor Mentor,
39 * chapter 5, example 4.
40 *
41 * This example creates the St. Louis Arch using a QuadMesh.
42 *------------------------------------------------------------*/
43
44 #include <cstdlib>
45 #include <Inventor/Xt/SoXt.h>
46 #include <Inventor/Xt/viewers/SoXtExaminerViewer.h>
47 #include <Inventor/nodes/SoCoordinate3.h>
48 #include <Inventor/nodes/SoMaterial.h>
49 #include <Inventor/nodes/SoQuadMesh.h>
50 #include <Inventor/nodes/SoSeparator.h>
51
52 //////////////////////////////////////////////////////////////
53 // CODE FOR The Inventor Mentor STARTS HERE
54
55 // Positions of all of the vertices:
56 static float vertexPositions[160][3] =
57 { // 1st row
58 {-13.0, 0.0, 1.5}, {-10.3, 13.7, 1.2}, { -7.6, 21.7, 1.0},
59 { -5.0, 26.1, 0.8}, { -2.3, 28.2, 0.6}, { -0.3, 28.8, 0.5},
60 { 0.3, 28.8, 0.5}, { 2.3, 28.2, 0.6}, { 5.0, 26.1, 0.8},
61 { 7.6, 21.7, 1.0}, { 10.3, 13.7, 1.2}, { 13.0, 0.0, 1.5},
62 // 2nd row
63 {-10.0, 0.0, 1.5}, { -7.9, 13.2, 1.2}, { -5.8, 20.8, 1.0},
64 { -3.8, 25.0, 0.8}, { -1.7, 27.1, 0.6}, { -0.2, 27.6, 0.5},
65 { 0.2, 27.6, 0.5}, { 1.7, 27.1, 0.6}, { 3.8, 25.0, 0.8},
66 { 5.8, 20.8, 1.0}, { 7.9, 13.2, 1.2}, { 10.0, 0.0, 1.5},
67 // 3rd row
68 {-10.0, 0.0,-1.5}, { -7.9, 13.2,-1.2}, { -5.8, 20.8,-1.0},
69 { -3.8, 25.0,-0.8}, { -1.7, 27.1,-0.6}, { -0.2, 27.6,-0.5},
70 { 0.2, 27.6,-0.5}, { 1.7, 27.1,-0.6}, { 3.8, 25.0,-0.8},
71 { 5.8, 20.8,-1.0}, { 7.9, 13.2,-1.2}, { 10.0, 0.0,-1.5},
72 // 4th row
73 {-13.0, 0.0,-1.5}, {-10.3, 13.7,-1.2}, { -7.6, 21.7,-1.0},
74 { -5.0, 26.1,-0.8}, { -2.3, 28.2,-0.6}, { -0.3, 28.8,-0.5},
75 { 0.3, 28.8,-0.5}, { 2.3, 28.2,-0.6}, { 5.0, 26.1,-0.8},
76 { 7.6, 21.7,-1.0}, { 10.3, 13.7,-1.2}, { 13.0, 0.0,-1.5},
77 // 5th row
78 {-13.0, 0.0, 1.5}, {-10.3, 13.7, 1.2}, { -7.6, 21.7, 1.0},
79 { -5.0, 26.1, 0.8}, { -2.3, 28.2, 0.6}, { -0.3, 28.8, 0.5},
80 { 0.3, 28.8, 0.5}, { 2.3, 28.2, 0.6}, { 5.0, 26.1, 0.8},
81 { 7.6, 21.7, 1.0}, { 10.3, 13.7, 1.2}, { 13.0, 0.0, 1.5}
82 };
83
84 // Routine to create a scene graph representing an arch.
85 SoSeparator *
86 makeArch()
87 {
88 SoSeparator *result = new SoSeparator;
89 result->ref();
90
91 #ifdef IV_STRICT
92 // This is the preferred code for Inventor 2.1
93
94 // Using the new SoVertexProperty node is more efficient
95 SoVertexProperty *myVertexProperty = new SoVertexProperty;
96
97 // Define the material
98 myVertexProperty->orderedRGBA.setValue(SbColor(.78, .57, .11).getPackedValue());
99
100 // Define coordinates for vertices
101 myVertexProperty->vertex.setValues(0, 60, vertexPositions);
102
103 // Define the QuadMesh.
104 SoQuadMesh *myQuadMesh = new SoQuadMesh;
105 myQuadMesh->verticesPerRow = 12;
106
107 myQuadMesh->verticesPerColumn = 5;
108
109 myQuadMesh->vertexProperty.setValue(myVertexProperty);
110 result->addChild(myQuadMesh);
111
112 #else
113 // Define the material
114 SoMaterial *myMaterial = new SoMaterial;
115 myMaterial->diffuseColor.setValue(.78, .57, .11);
116 result->addChild(myMaterial);
117
118 // Define coordinates for vertices
119 SoCoordinate3 *myCoords = new SoCoordinate3;
120 myCoords->point.setValues(0, 60, vertexPositions);
121 result->addChild(myCoords);
122
123 // Define the QuadMesh.
124 SoQuadMesh *myQuadMesh = new SoQuadMesh;
125 myQuadMesh->verticesPerRow = 12;
126 #endif
127
128 myQuadMesh->verticesPerColumn = 5;
129 result->addChild(myQuadMesh);
130
131 result->unrefNoDelete();
132 return result;
133 }
134
135 // CODE FOR The Inventor Mentor ENDS HERE
136 //////////////////////////////////////////////////////////////
137
138 int
139 main(int, char **argv)
140 {
141 // Initialize Inventor and Xt
142 Widget myWindow = SoXt::init(argv[0]);
143 if (myWindow == NULL) exit(1);
144
145 SoSeparator *root = makeArch();
146 root->ref();
147
148 SoXtExaminerViewer *myViewer =
149 new SoXtExaminerViewer(myWindow);
150 myViewer->setSceneGraph(root);
151 myViewer->setTitle("Quad Mesh: Arch");
152 myViewer->show();
153 myViewer->viewAll();
154
155 SoXt::show(myWindow);
156 SoXt::mainLoop();
157 }