Initial Import
[glAntsMech.git] / glants_mech / win32 / glAntsV05 / pyramid.cpp
blobe8b87834a4006b09ac54d8e4c17de0cb85898e68
1 //
2 // pyramid.cpp
3 //
4 // - note: at present pyramid is not really a pyramid
5 // but a box
6 //
7 #include <windows.h>
8 #include <stdio.h>
9 #include <stdlib.h>
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"
16 #include "objects.h"
17 #include "lights.h"
18 #include "plist.h"
19 #include "collision.h"
20 #include "walls.h"
22 #undef CURRENT_OBJECT
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};
42 // here is the level
43 // 14 walls, 5 cols
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
65 // in objects.h
67 DriverObjects CURRENT_OBJECT =
69 init_pyramid, // init, must be called first
70 compile_pyramid, // compile
71 draw_pyramid, // draw
72 render_pyramid, // render to scene
73 0 // loaded by INIT
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
96 // InsertWall
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;
103 // set up the struct
104 CollisionObj *ptr = NULL;
106 SetupWall(&(ptr)); // inserted into standard list
108 ptr->movement_type = PLANE_COL_TYPE; // moves
110 ptr->box_x = x;
111 ptr->box_y = y;
113 if (width <= 0)
114 width = 1.0f;
116 if (height <= 0)
117 height = 1.0f;
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
125 width *= 1.1f;
126 height *= 1.1f;
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
137 // 4 differnt walls
140 // front wall
141 InsertColSegment(x_min, y_max, x_max, y_max);
143 // right wall
144 InsertColSegment(x_max, y_min, x_max, y_max);
146 // back wall (top)
147 InsertColSegment(x_min, y_min, x_max, y_min);
149 // left wall
150 InsertColSegment(x_min, y_min, x_min, y_max);
153 } // end of the function
156 // Create Walls
158 void CreateWalls(void)
160 int i = 0;
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],
168 level_0[i][4]);
169 } // end of the for
171 } // end of teh fucntion
175 // PrintList
177 void Draw_Walls(CollisionList *list)
180 CollisionObj *current_ptr;
182 if (list->front == NULL)
183 return;
185 current_ptr = list->front;
187 while(current_ptr != NULL)
190 // draw the wall
191 glPushMatrix();
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();
200 glPopMatrix();
202 current_ptr = current_ptr->next;
204 } // end of while
206 } // end of the function
210 // Create wall list
212 void Create_Wall_List(void)
214 wall_list = CreateCollisionList();
215 } // end of the function
218 // Delelet Col List
220 void Delete_Wall_List(void)
222 DestroyColList(wall_list);
223 } // end of the function
226 // Print_Col_List
228 void Print_Wall_List(void)
230 PrintCollisionList(wall_list);
232 } // end of the function
235 // Draw_Wall_List
237 void Draw_Wall_List(void)
239 Draw_Walls(wall_list);
240 } // end of the functino
243 // END WALLOBJECTS
244 //=========================================================
245 static void draw_pyramid(void)
247 float v[3][3] = { 0 };
248 float n[3] = { 0 };
250 float size = 0.5f;
253 #if ENABLE_LIGHTS
254 // set the material for this object
255 setmaterial(dmat_ambient, dmat_diffuse,
256 dmat_specular, dlow_shininess, dmat_emission);
259 #endif
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);
269 // left bottom front
270 v[0][0] = -size;
271 v[0][1] = 0.0f;
272 v[0][2] = size;
274 v[1][0] = size;
275 v[1][1] = 0.0f;
276 v[1][2] = size;
278 v[2][0] = size;
279 v[2][1] = size;
280 v[2][2] = size;
283 CLR_0;
284 // Calc normal and draw
285 N_2;
286 GET_NORMAL;
288 glVertex3fv(v[0]);
289 glVertex3fv(v[1]);
290 glVertex3fv(v[2]); // triangle left bottom front
292 // Finish the front
293 v[0][0] = size;
294 v[0][1] = size;
295 v[0][2] = size;
297 v[1][0] = -size;
298 v[1][1] = size;
299 v[1][2] = size;
301 v[2][0] = -size;
302 v[2][1] = 0.0f;
303 v[2][2] = size;
305 CLR_1;
306 // Calc normal and draw
307 N_2;
308 GET_NORMAL;
310 glVertex3fv(v[0]);
311 glVertex3fv(v[1]);
312 glVertex3fv(v[2]); // triangle left bottom front
314 // Draw the back triangle
315 //-----------------------------
316 v[0][0] = -size;
317 v[0][1] = 0.0f;
318 v[0][2] = -size;
320 v[1][0] = size;
321 v[1][1] = 0.0f;
322 v[1][2] = -size;
324 v[2][0] = size;
325 v[2][1] = size;
326 v[2][2] = -size;
328 CLR_2;
329 // Calc normal and draw
330 N_2;
331 GET_NORMAL;
332 glVertex3fv(v[0]);
333 glVertex3fv(v[1]);
334 glVertex3fv(v[2]); // triangle left bottom bac
336 // Finish the back
337 v[0][0] = size;
338 v[0][1] = size;
339 v[0][2] = -size;
341 v[1][0] = -size;
342 v[1][1] = size;
343 v[1][2] = -size;
345 v[2][0] = -size;
346 v[2][1] = 0.0f;
347 v[2][2] = -size;
349 MED_PURPLE;
350 // Calc normal and draw
351 N_2;
352 GET_NORMAL;
353 glVertex3fv(v[0]);
354 glVertex3fv(v[1]);
355 glVertex3fv(v[2]); // triangle left bottom front
357 //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx?
358 // Draw the right side
359 // Triangle
360 v[0][0] = size;
361 v[0][1] = 0.0f;
362 v[0][2] = size;
364 v[1][0] = size;
365 v[1][1] = 0.0f;
366 v[1][2] = -size;
368 v[2][0] = size;
369 v[2][1] = size;
370 v[2][2] = size;
372 MED_BLUE;
373 // Calc normal and draw
374 N_2;
375 GET_NORMAL;
376 glVertex3fv(v[0]);
377 glVertex3fv(v[1]);
378 glVertex3fv(v[2]); // triangle left bottom bac
380 // FINISh the right side of the box
381 v[0][0] = size;
382 v[0][1] = 0.0f;
383 v[0][2] = -size;
385 v[1][0] = size;
386 v[1][1] = size;
387 v[1][2] = -size;
389 v[2][0] = size;
390 v[2][1] = size;
391 v[2][2] = size;
393 MED_GREEN;
394 // Calc normal and draw
395 N_2;
396 GET_NORMAL;
397 glVertex3fv(v[0]);
398 glVertex3fv(v[1]);
399 glVertex3fv(v[2]); // triangle left bottom bac
401 // FINISh the left side of the box
402 v[0][0] = -size;
403 v[0][1] = 0.0f;
404 v[0][2] = -size;
406 v[1][0] = -size;
407 v[1][1] = size;
408 v[1][2] = -size;
410 v[2][0] = -size;
411 v[2][1] = size;
412 v[2][2] = size;
415 MED_PURPLE;
416 // Calc normal and draw
417 N_2;
418 GET_NORMAL;
419 glVertex3fv(v[0]);
420 glVertex3fv(v[1]);
421 glVertex3fv(v[2]); // triangle left bottom bac
423 // Draw the left side
424 // Triangle
425 v[0][0] = -size;
426 v[0][1] = 0.0f;
427 v[0][2] = size;
429 v[1][0] = -size;
430 v[1][1] = 0.0f;
431 v[1][2] = -size;
433 v[2][0] = -size;
434 v[2][1] = size;
435 v[2][2] = size;
437 MED_RED;
438 // Calc normal and draw
439 N_2;
440 GET_NORMAL;
441 glVertex3fv(v[0]);
442 glVertex3fv(v[1]);
443 glVertex3fv(v[2]); // triangle left side
445 // Draw the top and bottom
446 v[0][0] = size;
447 v[0][1] = size;
448 v[0][2] = size;
450 v[1][0] = size;
451 v[1][1] = size;
452 v[1][2] = -size;
454 v[2][0] = -size;
455 v[2][1] = size;
456 v[2][2] = -size;
458 CLR_0;
459 // Calc normal and draw
460 N_2;
461 GET_NORMAL;
462 glVertex3fv(v[0]);
463 glVertex3fv(v[1]);
464 glVertex3fv(v[2]); // triangle left side
466 // Draw one of the bottom triangles
467 v[0][0] = size;
468 v[0][1] = 0.0f;
469 v[0][2] = size;
471 v[1][0] = size;
472 v[1][1] = 0.0f;
473 v[1][2] = -size;
475 v[2][0] = -size;
476 v[2][1] = 0.0f;
477 v[2][2] = -size;
480 CLR_3;
481 // Calc normal and draw
482 N_2;
483 GET_NORMAL;
484 glVertex3fv(v[0]);
485 glVertex3fv(v[1]);
486 glVertex3fv(v[2]); // triangle left side
488 // Lets finish the bottom with the second triangle
489 v[0][0] = -size;
490 v[0][1] = 0.0f;
491 v[0][2] = size;
493 v[1][0] = size;
494 v[1][1] = 0.0f;
495 v[1][2] = size;
497 v[2][0] = -size;
498 v[2][1] = 0.0f;
499 v[2][2] = -size;
501 // Calc normal and draw
502 N_2;
503 GET_NORMAL;
504 glVertex3fv(v[0]);
505 glVertex3fv(v[1]);
506 glVertex3fv(v[2]); // triangle left side
508 // Go back and finish the top
509 v[0][0] = -size;
510 v[0][1] = size;
511 v[0][2] = size;
513 v[1][0] = size;
514 v[1][1] = size;
515 v[1][2] = size;
517 v[2][0] = -size;
518 v[2][1] = size;
519 v[2][2] = -size;
521 // Calc normal and draw
522 N_2;
523 GET_NORMAL;
524 glVertex3fv(v[0]);
525 glVertex3fv(v[1]);
526 glVertex3fv(v[2]); // triangle left side
528 glEnd();
530 } // end of the function
535 // init
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)
556 //glPushMatrix();
558 glCallList(CURRENT_OBJECT.call_id);
560 //glPopMatrix();
562 } // end of the function
564 //=========================================================
565 // compile
566 //=========================================================
567 static void compile_pyramid(void)
569 int id;
570 // setup a spot for display list for background
571 //object = getcurrentobject();
572 id = CURRENT_OBJECT.call_id;
574 // apply list
575 glNewList(id, GL_COMPILE);
577 // call drawing function
578 // but this may method make it a little better
579 CURRENT_OBJECT.draw();
581 glEndList();
583 } // end of the function