4 // - note: at present pyramid is not really a pyramid
11 #include <gl\gl.h> // Header File For The OpenGL32 Library
12 #include <gl\glu.h> // Header File For The GLu32 Library
13 #include <gl\glaux.h> // Header File For The Glaux Library
15 #include "gldrawlib.h"
19 #include "collision.h"
23 #define CURRENT_OBJECT pyramid
25 static void init_pyramid(int list_id
);
26 static void compile_pyramid(void);
27 static void draw_pyramid(void);
28 static void render_pyramid(void);
29 static void draw_pyramid(void);
32 GLfloat dmat_ambient
[] = { 0.0f
, 0.0f
, 0.9f
, 1.0f
};
33 GLfloat dmat_diffuse
[] = { 0.3f
, 0.8f
, 0.8f
, 1.0f
};
34 GLfloat dmat_specular
[] = { 1.0f
, 1.0f
, 1.0f
, 1.0f
};
35 GLfloat dno_shininess
[] = { 0.0f
};
36 GLfloat dlow_shininess
[] = { 5.0f
};
37 GLfloat dhigh_shininess
[] = { 100.0f
};
38 GLfloat dmat_emission
[] = {0.3f
, 0.2f
, 0.2f
, 0.0f
};
44 // 60.0f is a good height
46 #define LEVEL_MAX_WALLS 10
47 static float level_0
[LEVEL_MAX_WALLS
][5] =
48 { { -200.0f
, 260.0f
, 100.0f
, 30.0f
, 70.0f
}, // 1
49 { -110.0f
, 200.0f
, 50.0f
, 40.0f
, 70.0f
}, // 2
50 { -70.0f
, 0.0f
, 20.0f
, 40.0f
, 80.0f
}, // 3
51 { 70.0f
, 0.0f
, 20.0f
, 40.0f
, 56.0f
}, // 4
52 { 0.0f
, 70.0f
, 50.0f
, 30.0f
, 66.0f
}, // 5
53 { 0.0f
, -70.0f
,50.0f
, 30.0f
, 60.0f
}, // 6
54 { -220.0f
, -240.0f
, 70.0f
, 40.0f
, 70.0f
}, // 7
55 { 180.0f
, -100.0f
, 50.0f
, 30.0f
, 55.0f
}, // 8
56 { 260.0f
, 100.0f
, 80.0f
, 30.0f
, 68.0f
}, // 9
57 { 220.0f
, 80.0f
, 40.0f
, 30.0f
, 55.0f
} // 10
63 // simple objects library
64 // - make sure to change the number of objects
67 DriverObjects CURRENT_OBJECT
=
69 init_pyramid
, // init, must be called first
70 compile_pyramid
, // compile
72 render_pyramid
, // render to scene
77 static CollisionList
*wall_list
;
80 // WALLSOBJECTS GO HERE
81 //=========================================================
84 static void SetupWall(CollisionObj
**ptr
)
86 (*ptr
) = CreateCollisionObj();
88 (*ptr
)->id
= wall_list
->objects
;
90 InsertColFront(wall_list
, *ptr
);
92 } // end of the function
98 void InsertWall(float x
, float y
,
99 float width
, float height
, float height_2
)
101 float x_min
,x_max
, y_min
, y_max
;
104 CollisionObj
*ptr
= NULL
;
106 SetupWall(&(ptr
)); // inserted into standard list
108 ptr
->movement_type
= PLANE_COL_TYPE
; // moves
119 ptr
->size
[0] = width
;
120 ptr
->size
[1] = height_2
;
121 ptr
->size
[2] = height
;
123 // increase the width a little so it doesnt
124 // look like the objects are crossing over
128 x_min
= x
- (width
/ 2.0f
);
129 x_max
= x
+ (width
/ 2.0f
);
131 y_min
= y
- (height
/ 2.0f
);
132 y_max
= y
+ (height
/ 2.0f
);
135 // In order to insert a wall of the box
136 // we need the xmins and maxes and the normals
141 InsertColSegment(x_min
, y_max
, x_max
, y_max
);
144 InsertColSegment(x_max
, y_min
, x_max
, y_max
);
147 InsertColSegment(x_min
, y_min
, x_max
, y_min
);
150 InsertColSegment(x_min
, y_min
, x_min
, y_max
);
153 } // end of the function
158 void CreateWalls(void)
161 //InsertWall(4.0f, -10.0f, 20.0f, 0.5f, 55.0f);
163 for (i
= 0; i
< LEVEL_MAX_WALLS
; i
++)
166 InsertWall(level_0
[i
][0], level_0
[i
][1],
167 level_0
[i
][2], level_0
[i
][3],
171 } // end of teh fucntion
177 void Draw_Walls(CollisionList
*list
)
180 CollisionObj
*current_ptr
;
182 if (list
->front
== NULL
)
185 current_ptr
= list
->front
;
187 while(current_ptr
!= NULL
)
193 glTranslatef(current_ptr
->box_x
, 0.0f
, current_ptr
->box_y
);
195 glScalef(current_ptr
->size
[0], current_ptr
->size
[1],
196 current_ptr
->size
[2]);
198 driver_objects
[PYRAMID_OBJECT
]->render();
202 current_ptr
= current_ptr
->next
;
206 } // end of the function
212 void Create_Wall_List(void)
214 wall_list
= CreateCollisionList();
215 } // end of the function
220 void Delete_Wall_List(void)
222 DestroyColList(wall_list
);
223 } // end of the function
228 void Print_Wall_List(void)
230 PrintCollisionList(wall_list
);
232 } // end of the function
237 void Draw_Wall_List(void)
239 Draw_Walls(wall_list
);
240 } // end of the functino
244 //=========================================================
245 static void draw_pyramid(void)
247 float v
[3][3] = { 0 };
254 // set the material for this object
255 setmaterial(dmat_ambient
, dmat_diffuse
,
256 dmat_specular
, dlow_shininess
, dmat_emission
);
261 // Note: normals are messed up for now
262 // select between n0-n3
264 // change the size here
265 // Note: starts from ground
267 glBegin(GL_TRIANGLES
);
284 // Calc normal and draw
290 glVertex3fv(v
[2]); // triangle left bottom front
306 // Calc normal and draw
312 glVertex3fv(v
[2]); // triangle left bottom front
314 // Draw the back triangle
315 //-----------------------------
329 // Calc normal and draw
334 glVertex3fv(v
[2]); // triangle left bottom bac
350 // Calc normal and draw
355 glVertex3fv(v
[2]); // triangle left bottom front
357 //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx?
358 // Draw the right side
373 // Calc normal and draw
378 glVertex3fv(v
[2]); // triangle left bottom bac
380 // FINISh the right side of the box
394 // Calc normal and draw
399 glVertex3fv(v
[2]); // triangle left bottom bac
401 // FINISh the left side of the box
416 // Calc normal and draw
421 glVertex3fv(v
[2]); // triangle left bottom bac
423 // Draw the left side
438 // Calc normal and draw
443 glVertex3fv(v
[2]); // triangle left side
445 // Draw the top and bottom
459 // Calc normal and draw
464 glVertex3fv(v
[2]); // triangle left side
466 // Draw one of the bottom triangles
481 // Calc normal and draw
486 glVertex3fv(v
[2]); // triangle left side
488 // Lets finish the bottom with the second triangle
501 // Calc normal and draw
506 glVertex3fv(v
[2]); // triangle left side
508 // Go back and finish the top
521 // Calc normal and draw
526 glVertex3fv(v
[2]); // triangle left side
530 } // end of the function
536 // - load anything special about the
537 // one important function
539 static void init_pyramid(int list_id
)
542 CURRENT_OBJECT
.visible
= 1;
544 // store the id through the function
545 // there is probably a better way to do this
546 CURRENT_OBJECT
.call_id
= list_id
;
548 } // end of the functino
551 //=========================================================
552 // Now the function to actually draw it
553 //=========================================================
554 static void render_pyramid(void)
558 glCallList(CURRENT_OBJECT
.call_id
);
562 } // end of the function
564 //=========================================================
566 //=========================================================
567 static void compile_pyramid(void)
570 // setup a spot for display list for background
571 //object = getcurrentobject();
572 id
= CURRENT_OBJECT
.call_id
;
575 glNewList(id
, GL_COMPILE
);
577 // call drawing function
578 // but this may method make it a little better
579 CURRENT_OBJECT
.draw();
583 } // end of the function