24 #include <Inventor/nodes/SoPerspectiveCamera.h>
25 #include <Inventor/nodes/SoPickStyle.h>
26 #include <Inventor/nodes/SoCone.h>
27 #include <Inventor/nodes/SoLineSet.h>
28 #include <Inventor/nodes/SoVertexProperty.h>
29 #include <Inventor/nodes/SoDrawStyle.h>
30 #include <Inventor/nodes/SoMaterial.h>
49 selectionRootNode =
new SoSelection;
50 selectionRootNode->setName(
"selectionRootNode");
51 selectionRootNode->ref();
54 SoPickStyle* unpickable =
new SoPickStyle();
55 unpickable->style = SoPickStyle::UNPICKABLE;
56 SoSeparator* gridFloorRoot =
new SoSeparator;
57 SoPickStyle* pickable =
new SoPickStyle();
58 pickable->style = SoPickStyle::SHAPE;
60 selectionRootNode->addChild(unpickable);
61 selectionRootNode->addChild(gridFloorRoot);
62 selectionRootNode->addChild(pickable);
74 const int GRIDSIZE = 5;
75 const int GRIDUNIT = 5;
76 const int GRIDSUBSIZE = 5;
77 const unsigned short GRIDPATTERN = 0xCCCC;
79 //Red material for X axis
80 SoMaterial* red = new SoMaterial;
81 red->diffuseColor = SbColor(1, 0, 0);
82 //Green material for Y axis
83 SoMaterial* green = new SoMaterial;
84 green->diffuseColor = SbColor(0, 1, 0);
85 //Blue material for Z axis
86 SoMaterial* blue = new SoMaterial;
87 blue->diffuseColor = SbColor(0, 0, 1);
90 SoDrawStyle* thinStyle = new SoDrawStyle;
91 thinStyle->lineWidth = 1;
92 thinStyle->linePattern = GRIDPATTERN;
94 SoDrawStyle* largeStyle = new SoDrawStyle;
95 largeStyle->lineWidth = 2;
97 //Our set of vertices for the grid lines
98 SoVertexProperty* vertices = new SoVertexProperty;
99 SoVertexProperty* subVertices = new SoVertexProperty;
100 SoVertexProperty* xVertices = new SoVertexProperty;
101 SoVertexProperty* yVertices = new SoVertexProperty;
102 SoVertexProperty* zVertices = new SoVertexProperty;
104 //Definition of which vertex belongs to which line and should be connected
105 SoLineSet* lines = new SoLineSet;
106 SoLineSet* subLines = new SoLineSet;
107 SoLineSet* xLines = new SoLineSet;
108 SoLineSet* yLines = new SoLineSet;
109 SoLineSet* zLines = new SoLineSet;
111 //Add 2 vertices for X axis
112 xVertices->vertex.set1Value(0, GRIDSIZE * GRIDUNIT, 0, 0);
113 xVertices->vertex.set1Value(1, -(GRIDSIZE * GRIDUNIT), 0, 0);
114 //Connect them to a line by adding '2' to numVertices at the correct position
115 xLines->numVertices.set1Value(0, 2);
118 yVertices->vertex.set1Value(0, 0, GRIDSIZE * GRIDUNIT, 0);
119 yVertices->vertex.set1Value(1, 0, -(GRIDSIZE * GRIDUNIT), 0);
120 yLines->numVertices.set1Value(0, 2);
123 zVertices->vertex.set1Value(0, 0, 0, GRIDSIZE * GRIDUNIT);
124 zVertices->vertex.set1Value(1, 0, 0, -(GRIDSIZE * GRIDUNIT));
125 zLines->numVertices.set1Value(0, 2);
127 //Counters to keep track of vertex index
128 int verticescounter = 0;
129 int subverticescounter = 0;
131 //Draw all lines parallel to the X and Y axis and all sublines, excepted axis itself
132 for (int i = -(GRIDSIZE * GRIDUNIT); i < GRIDUNIT * (GRIDSIZE + 1); i += GRIDUNIT)
136 vertices->vertex.set1Value(verticescounter++, GRIDSIZE * GRIDUNIT, i, 0);
137 vertices->vertex.set1Value(verticescounter++, -(GRIDSIZE * GRIDUNIT), i, 0);
138 lines->numVertices.set1Value((verticescounter - 1) / 2, 2);
140 vertices->vertex.set1Value(verticescounter++, i, GRIDSIZE * GRIDUNIT, 0);
141 vertices->vertex.set1Value(verticescounter++, i, -(GRIDSIZE * GRIDUNIT), 0);
142 lines->numVertices.set1Value((verticescounter - 1) / 2, 2);
145 //If this is not the last line to draw, draw sublines
146 if (i < GRIDUNIT * GRIDSIZE)
148 float delta = (float)GRIDUNIT / (float)GRIDSUBSIZE;
150 for (int n = 1; n < GRIDSUBSIZE; n++)
152 subVertices->vertex.set1Value(subverticescounter++, GRIDSIZE * GRIDUNIT, (float)i + (float)n * delta, 0);
153 subVertices->vertex.set1Value(subverticescounter++, -(GRIDSIZE * GRIDUNIT), (float)i + (float)n * delta, 0);
154 subLines->numVertices.set1Value((subverticescounter - 1) / 2, 2);
156 subVertices->vertex.set1Value(subverticescounter++, (float)i + (float)n * delta, GRIDSIZE * GRIDUNIT, 0);
157 subVertices->vertex.set1Value(subverticescounter++, (float)i + (float)n * delta, -(GRIDSIZE * GRIDUNIT), 0);
158 subLines->numVertices.set1Value((subverticescounter - 1) / 2, 2);
164 lines->vertexProperty.setValue(vertices);
165 subLines->vertexProperty.setValue(subVertices);
166 xLines->vertexProperty.setValue(xVertices);
167 yLines->vertexProperty.setValue(yVertices);
168 zLines->vertexProperty.setValue(zVertices);
170 gridFloorRoot->addChild(thinStyle);
171 gridFloorRoot->addChild(subLines);
172 gridFloorRoot->addChild(largeStyle);
173 gridFloorRoot->addChild(lines);
174 gridFloorRoot->addChild(red);
175 gridFloorRoot->addChild(xLines);
176 gridFloorRoot->addChild(green);
177 gridFloorRoot->addChild(yLines);
178 gridFloorRoot->addChild(blue);
179 gridFloorRoot->addChild(zLines);
184 objectRootNode = new SoSeparator;
185 objectRootNode->setName("objectRootNode");
186 selectionRootNode->addChild(objectRootNode);
189 scene3D::Scene::~Scene()
191 selectionRootNode->unref();
195 void scene3D::Scene::makeCameraViewAll(SoCamera* camera, const SbViewportRegion& region)
197 camera->viewAll(this->objectRootNode, region);
200 SoSeparator* scene3D::Scene::registerCamera(SoCamera* camera)
202 SoSeparator* cameraRoot = new SoSeparator;
203 cameraRoot->addChild(camera);
204 cameraRoot->addChild(selectionRootNode);
209 scene3D::SceneObjectManagerPtr scene3D::Scene::getObjectManager()
211 return sceneObjectManager;
214 scene3D::SceneGroupManagerPtr scene3D::Scene::getGroupManager()
216 return sceneGroupManager;
219 scene3D::SceneSelectionManagerPtr scene3D::Scene::getSelectionManager()
221 return sceneSelectionManager;
224 scene3D::SceneManipulatorManagerPtr scene3D::Scene::getManipulatorManager()
226 return sceneManipulatorManager;
229 scene3D::PreviewGeneratorPtr scene3D::Scene::getPreviewGenerator()
231 return scenePreviewGenerator;
234 controller::ControllerWeakPtr scene3D::Scene::getController()
239 void scene3D::Scene::enterEditorMode()
241 if (this->viewerMode)
243 this->selectionRootNode->policy = SoSelection::SHIFT;
244 this->sceneSelectionManager->deselectAll();
245 this->sceneSelectionManager->restoreHistory();
246 this->sceneSelectionManager->setCreateOperations(true);
247 this->viewerMode = false;
251 void scene3D::Scene::enterViewerMode()
253 if (!this->viewerMode)
255 this->sceneSelectionManager->setCreateOperations(false);
256 this->selectionRootNode->policy = SoSelection::SINGLE;
257 scene3D::SceneObjectPtr activeObject = this->sceneSelectionManager->getLastSelected();
258 this->sceneSelectionManager->storeHistory();
259 this->sceneSelectionManager->deselectAll();
263 this->sceneSelectionManager->addToSelection(activeObject);
266 this->viewerMode = true;