Skip to content

Commit 36ee7fb

Browse files
translation for objects
1 parent 59fdf6a commit 36ee7fb

File tree

6 files changed

+51
-12
lines changed

6 files changed

+51
-12
lines changed

SimpleSceneGraph.exe

1.11 KB
Binary file not shown.

main.cpp

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ NodeModel *M5 = new NodeModel(Cylinder);
4747
NodeModel *M6 = new NodeModel(Torus);
4848
NodeModel *M7 = new NodeModel(Tetrahedron);
4949

50+
Vector3D tempVec3;
51+
5052
//function which will populate a sample graph
5153
void initGraph(){
5254
//temporary place which holds out values
53-
Vector3D tempVec3;
55+
//Vector3D tempVec3;
5456

5557

5658
//TRANSFORMATION
@@ -93,23 +95,13 @@ void initGraph(){
9395

9496
void runGraph(){
9597
//temporary place which holds out values
96-
Vector3D tempVec3;
98+
// Vector3D tempVec3;
9799

98100

99101
//TRANSFORMATION
100102
//a tranlation transformation node
101103
//how much translation
102-
tempVec3.x = 1000;
103-
tempVec3.y = 10;
104-
tempVec3.z = 10;
105-
T1 = new NodeTransform(Translate, tempVec3);
106-
107104

108-
//add the node as a child of root node
109-
// T1 = new NodeTransform(Translate, tempVec3);
110-
// //insert the node into the graph
111-
// SG->insertChildNodeHere(T1);
112-
// //go to the child node
113105
// SG->goToChild(0);
114106

115107

@@ -125,6 +117,10 @@ void runGraph(){
125117
// NodeModel *M7 = new NodeModel(Tetrahedron);
126118

127119

120+
// tempVec3.x = 2;
121+
// tempVec3.y = 1;
122+
// tempVec3.z = 1;
123+
128124

129125
// SG->insertChildNodeHere(M2);
130126
//
@@ -136,30 +132,52 @@ void runGraph(){
136132
//THE SAME FLOW CAN BE USED TO DYNAMICALLY ADD NODES
137133
//DURING RUNTIME */
138134
if (teapot){
135+
T1 = new NodeTransform(Translate, tempVec3);
136+
SG->insertChildNodeHere(T1);
137+
SG->goToChild(SG -> returnChildNode());
138+
139139
teapot = false;
140140
SG->insertChildNodeHere(M1);
141141
}
142142
else if (sphere){
143+
T1 = new NodeTransform(Translate, tempVec3);
144+
SG->insertChildNodeHere(T1);
145+
SG->goToChild(SG -> returnChildNode());
143146
sphere = false;
144147
SG->insertChildNodeHere(M2);
145148
}
146149
else if (cube){
150+
T1 = new NodeTransform(Translate, tempVec3);
151+
SG->insertChildNodeHere(T1);
152+
SG->goToChild(SG -> returnChildNode());
147153
cube = false;
148154
SG->insertChildNodeHere(M3);
149155
}
150156
else if (cone){
157+
T1 = new NodeTransform(Translate, tempVec3);
158+
SG->insertChildNodeHere(T1);
159+
SG->goToChild(SG -> returnChildNode());
151160
cone = false;
152161
SG->insertChildNodeHere(M4);
153162
}
154163
else if (cylinder){
164+
T1 = new NodeTransform(Translate, tempVec3);
165+
SG->insertChildNodeHere(T1);
166+
SG->goToChild(SG -> returnChildNode());
155167
cylinder = false;
156168
SG->insertChildNodeHere(M5);
157169
}
158170
else if (torus){
171+
T1 = new NodeTransform(Translate, tempVec3);
172+
SG->insertChildNodeHere(T1);
173+
SG->goToChild(SG -> returnChildNode());
159174
torus = false;
160175
SG->insertChildNodeHere(M6);
161176
}
162177
else if (thedron){
178+
T1 = new NodeTransform(Translate, tempVec3);
179+
SG->insertChildNodeHere(T1);
180+
SG->goToChild(SG -> returnChildNode());
163181
thedron = false;
164182
SG->insertChildNodeHere(M7);
165183
}
@@ -204,6 +222,19 @@ void keyboard(unsigned char key, int x, int y)
204222
case 'J':
205223
thedron = true;
206224
break;
225+
case 'm':
226+
//TRANSFORMATION
227+
//a tranlation transformation node
228+
//how much translation
229+
tempVec3.x = 5;
230+
tempVec3.y = 5;
231+
tempVec3.z = 5;
232+
//add the node as a child of root node
233+
T1 = new NodeTransform(Translate, tempVec3);
234+
// //insert the node into the graph
235+
SG->insertChildNodeHere(T1);
236+
//go to the child node
237+
SG->goToChild(SG -> returnChildNode());
207238
}
208239
glutPostRedisplay();
209240
}

main.o

2.59 KB
Binary file not shown.

sceneGraph.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <stdio.h>
44
#include "structs.h"
55

6+
int location = 0;
7+
68
SceneGraph::SceneGraph(){
79
rootNode = new Node();
810
currentNode = rootNode;
@@ -27,6 +29,7 @@ void SceneGraph::goToChild(int i){
2729
currentNode = currentNode->children->at(i);
2830
else
2931
printf("child out of range");
32+
location = i;
3033
}
3134

3235
void SceneGraph::goToParent(){
@@ -44,6 +47,10 @@ void SceneGraph::deleteThisNode(){
4447
//TODO
4548
}
4649

50+
int SceneGraph::returnChildNode(){
51+
return location;
52+
}
53+
4754
//draw the scenegraph
4855
void SceneGraph::draw(){
4956
rootNode->draw();

sceneGraph.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class SceneGraph{
1616

1717
//Scene Graph Draw
1818
void draw();
19+
int returnChildNode();
1920

2021
private:
2122
Node *currentNode;

sceneGraph.o

168 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)