36 SoQtExaminerViewer(widget),
37 sceneRootNode(new SoSeparator),
38 contentRootNode(new SoSeparator),
39 camera(new SoPerspectiveCamera)
41 this->setBackgroundColor(SbColor(150 / 255.0f, 150 / 255.0f, 150 / 255.0f));
42 this->setAccumulationBuffer(this->getAccumulationBuffer());
43 this->setHeadlight(
true);
44 this->setViewing(
false);
45 this->setDecoration(
false);
48 this->setAntialiasing(
true, 4);
51 this->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_BLEND);
52 this->setFeedbackVisibility(
true);
56 this->setSceneGraph(sceneRootNode);
59 sceneRootNode->addChild(camera);
60 this->setCamera(camera);
63 camera->position.setValue(SbVec3f(10, -10, 5));
64 camera->pointAt(SbVec3f(0, 0, 0), SbVec3f(0, 0, 1));
67 SoSeparator* gridFloorRoot =
new SoSeparator();
68 SoPickStyle* unpickable =
new SoPickStyle();
69 unpickable->style = SoPickStyle::UNPICKABLE;
70 SoPickStyle* pickable =
new SoPickStyle();
71 pickable->style = SoPickStyle::SHAPE;
73 sceneRootNode->addChild(unpickable);
74 sceneRootNode->addChild(gridFloorRoot);
75 sceneRootNode->addChild(pickable);
87 const int GRIDSIZE = 3;
88 const int GRIDUNIT = 15;
89 const int GRIDSUBSIZE = 10;
90 const unsigned short GRIDPATTERN = 0xCCCC;
92 //Red material for X axis
93 SoMaterial* red = new SoMaterial;
94 red->diffuseColor = SbColor(1, 0, 0);
95 //Green material for Y axis
96 SoMaterial* green = new SoMaterial;
97 green->diffuseColor = SbColor(0, 1, 0);
98 //Blue material for Z axis
99 SoMaterial* blue = new SoMaterial;
100 blue->diffuseColor = SbColor(0, 0, 1);
103 SoDrawStyle* thinStyle = new SoDrawStyle;
104 thinStyle->lineWidth = 1;
105 thinStyle->linePattern = GRIDPATTERN;
107 SoDrawStyle* largeStyle = new SoDrawStyle;
108 largeStyle->lineWidth = 2;
110 //Our set of vertices for the grid lines
111 SoVertexProperty* vertices = new SoVertexProperty;
112 SoVertexProperty* subVertices = new SoVertexProperty;
113 SoVertexProperty* xVertices = new SoVertexProperty;
114 SoVertexProperty* yVertices = new SoVertexProperty;
115 SoVertexProperty* zVertices = new SoVertexProperty;
117 //Definition of which vertex belongs to which line and should be connected
118 SoLineSet* lines = new SoLineSet;
119 SoLineSet* subLines = new SoLineSet;
120 SoLineSet* xLines = new SoLineSet;
121 SoLineSet* yLines = new SoLineSet;
122 SoLineSet* zLines = new SoLineSet;
124 //Add 2 vertices for X axis
125 xVertices->vertex.set1Value(0, GRIDSIZE * GRIDUNIT, 0, 0);
126 xVertices->vertex.set1Value(1, -(GRIDSIZE * GRIDUNIT), 0, 0);
127 //Connect them to a line by adding '2' to numVertices at the correct position
128 xLines->numVertices.set1Value(0, 2);
131 yVertices->vertex.set1Value(0, 0, GRIDSIZE * GRIDUNIT, 0);
132 yVertices->vertex.set1Value(1, 0, -(GRIDSIZE * GRIDUNIT), 0);
133 yLines->numVertices.set1Value(0, 2);
136 zVertices->vertex.set1Value(0, 0, 0, GRIDSIZE * GRIDUNIT);
137 zVertices->vertex.set1Value(1, 0, 0, -(GRIDSIZE * GRIDUNIT));
138 zLines->numVertices.set1Value(0, 2);
140 //Counters to keep track of vertex index
141 int verticescounter = 0;
142 int subverticescounter = 0;
144 //Draw all lines parallel to the X and Y axis and all sublines, excepted axis itself
145 for (int i = -(GRIDSIZE * GRIDUNIT); i < GRIDUNIT * (GRIDSIZE + 1); i += GRIDUNIT)
149 vertices->vertex.set1Value(verticescounter++, GRIDSIZE * GRIDUNIT, i, 0);
150 vertices->vertex.set1Value(verticescounter++, -(GRIDSIZE * GRIDUNIT), i, 0);
151 lines->numVertices.set1Value((verticescounter - 1) / 2, 2);
153 vertices->vertex.set1Value(verticescounter++, i, GRIDSIZE * GRIDUNIT, 0);
154 vertices->vertex.set1Value(verticescounter++, i, -(GRIDSIZE * GRIDUNIT), 0);
155 lines->numVertices.set1Value((verticescounter - 1) / 2, 2);
158 //If this is not the last line to draw, draw sublines
159 if (i < GRIDUNIT * GRIDSIZE)
161 float delta = (float)GRIDUNIT / (float)GRIDSUBSIZE;
163 for (int n = 1; n < GRIDSUBSIZE; n++)
165 subVertices->vertex.set1Value(
166 subverticescounter++, GRIDSIZE * GRIDUNIT, (float)i + (float)n * delta, 0);
167 subVertices->vertex.set1Value(
168 subverticescounter++, -(GRIDSIZE * GRIDUNIT), (float)i + (float)n * delta, 0);
169 subLines->numVertices.set1Value((subverticescounter - 1) / 2, 2);
171 subVertices->vertex.set1Value(
172 subverticescounter++, (float)i + (float)n * delta, GRIDSIZE * GRIDUNIT, 0);
173 subVertices->vertex.set1Value(
174 subverticescounter++, (float)i + (float)n * delta, -(GRIDSIZE * GRIDUNIT), 0);
175 subLines->numVertices.set1Value((subverticescounter - 1) / 2, 2);
181 lines->vertexProperty.setValue(vertices);
182 subLines->vertexProperty.setValue(subVertices);
183 xLines->vertexProperty.setValue(xVertices);
184 yLines->vertexProperty.setValue(yVertices);
185 zLines->vertexProperty.setValue(zVertices);
187 gridFloorRoot->addChild(thinStyle);
188 gridFloorRoot->addChild(subLines);
189 gridFloorRoot->addChild(largeStyle);
190 gridFloorRoot->addChild(lines);
191 gridFloorRoot->addChild(red);
192 gridFloorRoot->addChild(xLines);
193 gridFloorRoot->addChild(green);
194 gridFloorRoot->addChild(yLines);
195 gridFloorRoot->addChild(blue);
196 gridFloorRoot->addChild(zLines);
201 //Create content root node
202 sceneRootNode->addChild(contentRootNode);