26 #include <Inventor/nodes/SoCone.h>
27 #include <Inventor/nodes/SoDrawStyle.h>
28 #include <Inventor/nodes/SoLineSet.h>
29 #include <Inventor/nodes/SoMaterial.h>
30 #include <Inventor/nodes/SoPerspectiveCamera.h>
31 #include <Inventor/nodes/SoPickStyle.h>
32 #include <Inventor/nodes/SoVertexProperty.h>
51 selectionRootNode =
new SoSelection;
52 selectionRootNode->setName(
"selectionRootNode");
53 selectionRootNode->ref();
56 SoPickStyle* unpickable =
new SoPickStyle();
57 unpickable->style = SoPickStyle::UNPICKABLE;
58 SoSeparator* gridFloorRoot =
new SoSeparator;
59 SoPickStyle* pickable =
new SoPickStyle();
60 pickable->style = SoPickStyle::SHAPE;
62 selectionRootNode->addChild(unpickable);
63 selectionRootNode->addChild(gridFloorRoot);
64 selectionRootNode->addChild(pickable);
76 const int GRIDSIZE = 5;
77 const int GRIDUNIT = 5;
78 const int GRIDSUBSIZE = 5;
79 const unsigned short GRIDPATTERN = 0xCCCC;
81 //Red material for X axis
82 SoMaterial* red = new SoMaterial;
83 red->diffuseColor = SbColor(1, 0, 0);
84 //Green material for Y axis
85 SoMaterial* green = new SoMaterial;
86 green->diffuseColor = SbColor(0, 1, 0);
87 //Blue material for Z axis
88 SoMaterial* blue = new SoMaterial;
89 blue->diffuseColor = SbColor(0, 0, 1);
92 SoDrawStyle* thinStyle = new SoDrawStyle;
93 thinStyle->lineWidth = 1;
94 thinStyle->linePattern = GRIDPATTERN;
96 SoDrawStyle* largeStyle = new SoDrawStyle;
97 largeStyle->lineWidth = 2;
99 //Our set of vertices for the grid lines
100 SoVertexProperty* vertices = new SoVertexProperty;
101 SoVertexProperty* subVertices = new SoVertexProperty;
102 SoVertexProperty* xVertices = new SoVertexProperty;
103 SoVertexProperty* yVertices = new SoVertexProperty;
104 SoVertexProperty* zVertices = new SoVertexProperty;
106 //Definition of which vertex belongs to which line and should be connected
107 SoLineSet* lines = new SoLineSet;
108 SoLineSet* subLines = new SoLineSet;
109 SoLineSet* xLines = new SoLineSet;
110 SoLineSet* yLines = new SoLineSet;
111 SoLineSet* zLines = new SoLineSet;
113 //Add 2 vertices for X axis
114 xVertices->vertex.set1Value(0, GRIDSIZE * GRIDUNIT, 0, 0);
115 xVertices->vertex.set1Value(1, -(GRIDSIZE * GRIDUNIT), 0, 0);
116 //Connect them to a line by adding '2' to numVertices at the correct position
117 xLines->numVertices.set1Value(0, 2);
120 yVertices->vertex.set1Value(0, 0, GRIDSIZE * GRIDUNIT, 0);
121 yVertices->vertex.set1Value(1, 0, -(GRIDSIZE * GRIDUNIT), 0);
122 yLines->numVertices.set1Value(0, 2);
125 zVertices->vertex.set1Value(0, 0, 0, GRIDSIZE * GRIDUNIT);
126 zVertices->vertex.set1Value(1, 0, 0, -(GRIDSIZE * GRIDUNIT));
127 zLines->numVertices.set1Value(0, 2);
129 //Counters to keep track of vertex index
130 int verticescounter = 0;
131 int subverticescounter = 0;
133 //Draw all lines parallel to the X and Y axis and all sublines, excepted axis itself
134 for (int i = -(GRIDSIZE * GRIDUNIT); i < GRIDUNIT * (GRIDSIZE + 1); i += GRIDUNIT)
138 vertices->vertex.set1Value(verticescounter++, GRIDSIZE * GRIDUNIT, i, 0);
139 vertices->vertex.set1Value(verticescounter++, -(GRIDSIZE * GRIDUNIT), i, 0);
140 lines->numVertices.set1Value((verticescounter - 1) / 2, 2);
142 vertices->vertex.set1Value(verticescounter++, i, GRIDSIZE * GRIDUNIT, 0);
143 vertices->vertex.set1Value(verticescounter++, i, -(GRIDSIZE * GRIDUNIT), 0);
144 lines->numVertices.set1Value((verticescounter - 1) / 2, 2);
147 //If this is not the last line to draw, draw sublines
148 if (i < GRIDUNIT * GRIDSIZE)
150 float delta = (float)GRIDUNIT / (float)GRIDSUBSIZE;
152 for (int n = 1; n < GRIDSUBSIZE; n++)
154 subVertices->vertex.set1Value(
155 subverticescounter++, GRIDSIZE * GRIDUNIT, (float)i + (float)n * delta, 0);
156 subVertices->vertex.set1Value(
157 subverticescounter++, -(GRIDSIZE * GRIDUNIT), (float)i + (float)n * delta, 0);
158 subLines->numVertices.set1Value((subverticescounter - 1) / 2, 2);
160 subVertices->vertex.set1Value(
161 subverticescounter++, (float)i + (float)n * delta, GRIDSIZE * GRIDUNIT, 0);
162 subVertices->vertex.set1Value(
163 subverticescounter++, (float)i + (float)n * delta, -(GRIDSIZE * GRIDUNIT), 0);
164 subLines->numVertices.set1Value((subverticescounter - 1) / 2, 2);
170 lines->vertexProperty.setValue(vertices);
171 subLines->vertexProperty.setValue(subVertices);
172 xLines->vertexProperty.setValue(xVertices);
173 yLines->vertexProperty.setValue(yVertices);
174 zLines->vertexProperty.setValue(zVertices);
176 gridFloorRoot->addChild(thinStyle);
177 gridFloorRoot->addChild(subLines);
178 gridFloorRoot->addChild(largeStyle);
179 gridFloorRoot->addChild(lines);
180 gridFloorRoot->addChild(red);
181 gridFloorRoot->addChild(xLines);
182 gridFloorRoot->addChild(green);
183 gridFloorRoot->addChild(yLines);
184 gridFloorRoot->addChild(blue);
185 gridFloorRoot->addChild(zLines);
190 objectRootNode = new SoSeparator;
191 objectRootNode->setName("objectRootNode");
192 selectionRootNode->addChild(objectRootNode);
195 scene3D::Scene::~Scene()
197 selectionRootNode->unref();
201 scene3D::Scene::makeCameraViewAll(SoCamera* camera, const SbViewportRegion& region)
203 camera->viewAll(this->objectRootNode, region);
207 scene3D::Scene::registerCamera(SoCamera* camera)
209 SoSeparator* cameraRoot = new SoSeparator;
210 cameraRoot->addChild(camera);
211 cameraRoot->addChild(selectionRootNode);
216 scene3D::SceneObjectManagerPtr
217 scene3D::Scene::getObjectManager()
219 return sceneObjectManager;
222 scene3D::SceneGroupManagerPtr
223 scene3D::Scene::getGroupManager()
225 return sceneGroupManager;
228 scene3D::SceneSelectionManagerPtr
229 scene3D::Scene::getSelectionManager()
231 return sceneSelectionManager;
234 scene3D::SceneManipulatorManagerPtr
235 scene3D::Scene::getManipulatorManager()
237 return sceneManipulatorManager;
240 scene3D::PreviewGeneratorPtr
241 scene3D::Scene::getPreviewGenerator()
243 return scenePreviewGenerator;
246 controller::ControllerWeakPtr
247 scene3D::Scene::getController()
253 scene3D::Scene::enterEditorMode()
255 if (this->viewerMode)
257 this->selectionRootNode->policy = SoSelection::SHIFT;
258 this->sceneSelectionManager->deselectAll();
259 this->sceneSelectionManager->restoreHistory();
260 this->sceneSelectionManager->setCreateOperations(true);
261 this->viewerMode = false;
266 scene3D::Scene::enterViewerMode()
268 if (!this->viewerMode)
270 this->sceneSelectionManager->setCreateOperations(false);
271 this->selectionRootNode->policy = SoSelection::SINGLE;
272 scene3D::SceneObjectPtr activeObject = this->sceneSelectionManager->getLastSelected();
273 this->sceneSelectionManager->storeHistory();
274 this->sceneSelectionManager->deselectAll();
278 this->sceneSelectionManager->addToSelection(activeObject);
281 this->viewerMode = true;