Skip to content

Commit 596aca8

Browse files
delete almost working?
1 parent e6a358d commit 596aca8

File tree

8 files changed

+163
-80
lines changed

8 files changed

+163
-80
lines changed

SimpleSceneGraph.exe

-115 KB
Binary file not shown.

main.cpp

Lines changed: 89 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,6 @@ Vector4D vec4R;
106106

107107
//function which will populate a sample graph
108108
void initGraph(){
109-
//TRANSFORMATION
110-
//a tranlation transformation node
111-
//how much translation
112-
// tempVec3.x = 1;
113-
// tempVec3.y = 0;
114-
// tempVec3.z = 1;
115-
//add the node as a child of root node
116-
// T1 = new NodeTransform(Translate, tempVec3);
117-
//insert the node into the graph
118-
// SG->insertChildNodeHere(T1);
119-
//go to the child node
120-
121109
NodeGroup *G1 = new NodeGroup();
122110
//insert the node into the graph
123111
SG->insertChildNodeHere(G1);
@@ -275,6 +263,7 @@ void runGraph(){
275263

276264

277265
bool Intersect(int x, int y){
266+
printf("%i, %i\n", x, y);
278267

279268
//allocate matricies memory
280269
double matModelView[16], matProjection[16];
@@ -301,8 +290,8 @@ bool Intersect(int x, int y){
301290
viewport, &endArray[0], &endArray[1], &endArray[2]);
302291

303292

304-
//printf("near point: %f,%f,%f\n", start[0], start[1], start[2]);
305-
//printf("far point: %f,%f,%f\n", endArray[0], endArray[1], endArray[2]);
293+
printf("near point: %f,%f,%f\n", start[0], start[1], start[2]);
294+
printf("far point: %f,%f,%f\n", endArray[0], endArray[1], endArray[2]);
306295

307296

308297
px = start[0];
@@ -460,78 +449,116 @@ void keyboard(unsigned char key, int x, int y)
460449
switch (key)
461450
{
462451
case '1':
463-
m_amb[0] = 0.25f;m_amb[1] = 0.25f;m_amb[2] = 0.25f;m_amb[3] = 1.0f;
464-
m_dif[0] = 0.4f;m_dif[1] = 0.4f;m_dif[2] = 0.4f;m_dif[3] = 1.0f;
465-
m_spec[0] = 0.774597f;m_spec[1] = 0.774597f;m_spec[2] = 0.774597f;m_spec[3] = 1.0f;
452+
m_amb[0] = 0.25f;
453+
m_amb[1] = 0.25f;
454+
m_amb[2] = 0.25f;
455+
m_amb[3] = 1.0f;
456+
m_dif[0] = 0.4f;
457+
m_dif[1] = 0.4f;
458+
m_dif[2] = 0.4f;
459+
m_dif[3] = 1.0f;
460+
m_spec[0] = 0.774597f;
461+
m_spec[1] = 0.774597f;
462+
m_spec[2] = 0.774597f;
463+
m_spec[3] = 1.0f;
466464
shiny = 76.8;
467465
break;
468466
case '2':
469-
m_amb[0] = 0.329412f;m_amb[1] = 0.223529f;m_amb[2] = 0.027451f;m_amb[3] = 1.0f;
470-
m_dif[0] = 0.780392f;m_dif[1] = 0.568627f;m_dif[2] = 0.113725f;m_dif[3] = 1.0f;
471-
m_spec[0] = 0.992157f;m_spec[1] = 0.941176f;m_spec[2] = 0.807843f;m_spec[3] = 1.0f;
467+
m_amb[0] = 0.329412f;
468+
m_amb[1] = 0.223529f;
469+
m_amb[2] = 0.027451f;
470+
m_amb[3] = 1.0f;
471+
m_dif[0] = 0.780392f;
472+
m_dif[1] = 0.568627f;
473+
m_dif[2] = 0.113725f;
474+
m_dif[3] = 1.0f;
475+
m_spec[0] = 0.992157f;
476+
m_spec[1] = 0.941176f;
477+
m_spec[2] = 0.807843f;
478+
m_spec[3] = 1.0f;
472479
shiny = 27.8974f;
473480
break;
474481
case '3':
475-
m_amb[0] = 0.1745f;m_amb[1] = 0.01175f;m_amb[2] = 0.01175f;m_amb[3] = 0.55f;
476-
m_dif[0] = 0.61424f;m_dif[1] = 0.04136f;m_dif[2] = 0.04136f;m_dif[3] = 0.55f;
477-
m_spec[0] = 0.727811f;m_spec[1] = 0.626959f;m_spec[2] = 0.626959f;m_spec[3] = 0.55f;
482+
m_amb[0] = 0.1745f;
483+
m_amb[1] = 0.01175f;
484+
m_amb[2] = 0.01175f;
485+
m_amb[3] = 0.55f;
486+
m_dif[0] = 0.61424f;
487+
m_dif[1] = 0.04136f;
488+
m_dif[2] = 0.04136f;
489+
m_dif[3] = 0.55f;
490+
m_spec[0] = 0.727811f;
491+
m_spec[1] = 0.626959f;
492+
m_spec[2] = 0.626959f;
493+
m_spec[3] = 0.55f;
478494
shiny = 76.8f;
479495
break;
480496
case '4':
481-
m_amb[0] = 0.0215f;m_amb[1] = 0.1745f;m_amb[2] = 0.0215f;m_amb[3] = 0.55f;
482-
m_dif[0] = 0.07568f;m_dif[1] = 0.61424f;m_dif[2] = 0.07568f;m_dif[3] = 0.55f;
483-
m_spec[0] = 0.633f;m_spec[1] = 0.727811f;m_spec[2] = 0.626959f;m_spec[3] = 0.55f;
497+
m_amb[0] = 0.0215f;
498+
m_amb[1] = 0.1745f;
499+
m_amb[2] = 0.0215f;
500+
m_amb[3] = 0.55f;
501+
m_dif[0] = 0.07568f;
502+
m_dif[1] = 0.61424f;
503+
m_dif[2] = 0.07568f;
504+
m_dif[3] = 0.55f;
505+
m_spec[0] = 0.633f;
506+
m_spec[1] = 0.727811f;
507+
m_spec[2] = 0.626959f;
508+
m_spec[3] = 0.55f;
484509
shiny = 76.8f;
485510
break;
486511
case '5':
487-
m_amb[0] = 0.24725f;m_amb[1] = 0.1995f;m_amb[2] = 0.0745f;m_amb[3] = 0.55f;
488-
m_dif[0] = 0.75164f;m_dif[1] = 0.60648f;m_dif[2] = 0.22648f;m_dif[3] = 0.55f;
489-
m_spec[0] = 0.628281f;m_spec[1] = 0.555802f;m_spec[2] = 0.366065f;m_spec[3] = 0.55f;
512+
m_amb[0] = 0.24725f;
513+
m_amb[1] = 0.1995f;
514+
m_amb[2] = 0.0745f;
515+
m_amb[3] = 0.55f;
516+
m_dif[0] = 0.75164f;
517+
m_dif[1] = 0.60648f;
518+
m_dif[2] = 0.22648f;
519+
m_dif[3] = 0.55f;
520+
m_spec[0] = 0.628281f;
521+
m_spec[1] = 0.555802f;
522+
m_spec[2] = 0.366065f;
523+
m_spec[3] = 0.55f;
490524
shiny = 51.2f;
491525
break;
492526
case 'q':
493527
case 27:
494528
exit (0);
495529
break;
496-
case 'a':
497-
case 'A': // for teapot
530+
case '6':// for teapot
498531
objectType = 1;
499532
teapot = true;
500533
runGraph();
501534
glutPostRedisplay();
502535
break;
503-
case 's': // for sphere
504-
case 'S':
536+
case '7': // for sphere
505537
objectType = 2;
506538
runGraph();
507539
glutPostRedisplay();
508540
break;
509-
case 'd': // for cube
510-
case 'D':
541+
case '8': // for cube
511542
objectType = 3;
512543
runGraph();
513544
glutPostRedisplay();
514545
break;
515-
case 'f': // for cone
516-
case 'F':
546+
case '9': // for cone
517547
objectType = 4;
518548
runGraph();
519549
glutPostRedisplay();
520550
break;
521-
case 'g':
522-
case 'G': // for cylinder
551+
case '0': // for cylinder
523552
objectType = 5;
524553
runGraph();
525554
glutPostRedisplay();
526555
break;
527-
case 'h':
528-
case 'H': // for torus
556+
case '-': // for torus
529557
objectType = 6;
530558
runGraph();
531559
glutPostRedisplay();
532560
break;
533-
case 'j':
534-
case 'J': // for tetrehedron
561+
case '=': // for tetrehedron
535562
objectType = 7;
536563
runGraph();
537564
glutPostRedisplay();
@@ -556,7 +583,7 @@ void keyboard(unsigned char key, int x, int y)
556583
tempVec3.z = 0;
557584
transformObject();
558585
break;
559-
case 'r': // translate on -y
586+
case 'a': // translate on -y
560587
// Vector3D transform;
561588
tempVec3.x = 0;
562589
tempVec3.y = -1;
@@ -647,6 +674,10 @@ void keyboard(unsigned char key, int x, int y)
647674
light_pos0[2] -= 3;
648675
light_pos1[2] -= 3;
649676
glutPostRedisplay();
677+
break;
678+
case 'r':
679+
SG -> deleteAllNodes();
680+
glutPostRedisplay();
650681
break;
651682
default:
652683
break;
@@ -703,16 +734,25 @@ void drawAxis()
703734
glEnd();
704735
}
705736

737+
706738
void mouse(int button, int state, int x, int y){
739+
bool hit = Intersect(x,y);
707740
if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){
708-
bool hit = Intersect(x,y);
709-
//hit = true;
741+
hit = true;
710742
intX = 1; intY = 1; intZ = 1;
711743
if (hit==true){
712-
// printf("px: %f, pz: %f\n",px, pz);
713-
// drawWireFrame(intX, intY, intZ);
744+
SG -> wireOn();
745+
glutPostRedisplay();
714746
}
715747
}
748+
else if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN){
749+
SG -> deleteThisNode();
750+
//SG -> deleteAllNodes();
751+
// SG -> delete();
752+
numberOfObjects --;
753+
}
754+
//bool temp = SG->deleteNode();
755+
//temp = false;
716756
glutPostRedisplay();
717757
}
718758

@@ -785,6 +825,7 @@ void display(void){
785825
glColor3f(1,1,1);
786826

787827
SG->draw();
828+
printf("End of iteration\n");
788829
// runGraph();
789830

790831
// apply light

nodeModel.cpp

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,60 +17,62 @@ NodeModel::NodeModel(ModelType whatType){ //constructor
1717
isDrawable = true;
1818
}
1919

20+
void NodeModel::drawWireFrame(){
21+
//if(frameOn == true){
22+
glColor3f(0,1,0);
23+
glutWireCube(2);
24+
//}
25+
}
26+
2027
//as the node moves down through it, we want to perform down action
2128
//which in this case means drawing the model
2229
void NodeModel::nodeSpecificCodeDown(){
2330
switch (modelType){
2431
case Sphere:
32+
// frameOn = true;
33+
if(frameOn){drawWireFrame();}
2534
glColor3f(0,0,1);
2635
glutSolidSphere(1, 12, 10);
2736
break;
2837
case Cube:
38+
frameOn = true;
39+
if(frameOn){drawWireFrame();}
2940
glColor3f(1,0,1);
3041
glutSolidCube(1);
3142
break;
3243
case Teapot:
3344
frameOn = true;
34-
if(frameOn == true){
35-
printf("frameOn\n");
36-
glColor3f(0,1,0);
37-
glBegin(GL_LINE_LOOP);
38-
//draw a line loop for the wire map
39-
/* glVertex3f(0,0,0);
40-
glVertex3f(2,0,2);
41-
glVertex3f(2,2,0);
42-
glVertex3f(0,0,0);
43-
glVertex3f(0,2,2);
44-
glVertex3f(2,0,2);
45-
glVertex3f(2,2,0);
46-
glVertex3f(0,2,2);
47-
//glVertex3f(2,2,2);*/
48-
49-
glutWireCube(2);
50-
glEnd();
51-
}
45+
if(frameOn){drawWireFrame();}
5246
glColor3f(0,1,1);
53-
//glutSolidTeapot(1);
47+
glutSolidTeapot(1);
5448
break;
5549
case Cone:
50+
frameOn = true;
51+
if(frameOn){drawWireFrame();}
5652
glColor3f(1,1,0);
57-
glutSolidCone(1,2,40,1);
53+
glutSolidCone(1,1,40,1);
5854
break;
5955
case Cylinder:
56+
frameOn = true;
57+
if(frameOn){drawWireFrame();}
6058
glColor3f(1,0.5,1);
6159
GLUquadricObj *quadratic;
6260
quadratic = gluNewQuadric();
63-
glutSolidCone(1,1,40,1);
61+
glutSolidCone(1,0.5,40,1);
6462
glRotatef(180, 1.0, 0.0, 0.0);
65-
glTranslatef(0,0,-2);
66-
glutSolidCone(1,1,40,1);
67-
gluCylinder(quadratic,1,1, 2, 40,5);
63+
glTranslatef(0,0,-0.5);
64+
glutSolidCone(1,0.5,40,1);
65+
gluCylinder(quadratic,1,1, 1, 40,5);
6866
break;
6967
case Torus:
68+
frameOn = true;
69+
if(frameOn){drawWireFrame();}
7070
glColor3f(0,1,0);
71-
glutSolidTorus(0.5,1,30, 30);
71+
glutSolidTorus(0.2,0.6,30, 30);
7272
break;
7373
case Tetrahedron:
74+
frameOn = true;
75+
if(frameOn){drawWireFrame();}
7476
glColor3f(1,0,0);
7577
glutSolidTetrahedron();
7678
break;

nodeModel.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ enum ModelType{
2727
class NodeModel:public Node{
2828
public:
2929
NodeModel(ModelType whatType); //constructor
30-
ModelType modelType;
3130

31+
ModelType modelType;
32+
void drawWireFrame();
3233
virtual void nodeSpecificCodeDown();
3334
};
3435

nodeTransform.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,27 @@ NodeTransform::NodeTransform(transformType whatType, Vector4D vec4){
2525
amount4 = vec4;
2626
}
2727

28+
void NodeTransform::nodeSpecificCodeUp(){
29+
//printf("UP : amount3.x: %1f amount3.y %1f amount3.z %1f \n", amount3.x, amount3.y, amount3.z);
30+
31+
switch (transformationType){
32+
case Translate:
33+
glTranslatef(-amount3.x, -amount3.y, -amount3.z);
34+
break;
35+
case Rotate:
36+
glRotatef(-amount4.w, -amount4.x, -amount4.y, -amount4.z);
37+
break;
38+
case Scale:
39+
glScalef(-amount3.x, -amount3.y, -amount3.z);
40+
break;
41+
}
42+
//amount3.x=0;
43+
//amount3.y=0;
44+
//amount3.z=0;
45+
46+
47+
}
48+
2849
void NodeTransform::nodeSpecificCodeDown(){
2950
switch (transformationType){
3051
case Translate:

nodeTransform.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class NodeTransform:public Node{
1818
Vector3D amount3;
1919
Vector4D amount4;
2020

21+
virtual void nodeSpecificCodeUp();
2122
virtual void nodeSpecificCodeDown();
2223
};
2324

0 commit comments

Comments
 (0)