9 #include <gl\gl.h> // Header File For The OpenGL32 Library
10 #include <gl\glu.h> // Header File For The GLu32 Library
11 #include <gl\glaux.h> // Header File For The Glaux Library
14 #include "gldrawlib.h"
20 #define CURRENT_OBJECT pheromone
23 #define CURRENT_PTR StaticBotPtr
26 #define CURRENT_OBJ StaticBot
29 #define CURRENT_BOT trail_set
32 //=====================================
33 static void init_pheromone(int list_id
);
34 static void compile_pheromone(void);
35 static void draw_pheromone(void);
36 static void render_pheromone(void);
37 static void draw_pheromone(void);
40 static CURRENT_PTR
CreatePheromone(int bot_id
);
41 static void RenderPheromone(CURRENT_PTR boid
);
42 static void DestroyPheromone(CURRENT_PTR b
);
43 static void ProcessPheromone(CURRENT_PTR b
);
46 static void Draw_Pheromones(void);
47 static void Generate_Pheromones(void);
48 static void Shutdown_Pheromones(void);
52 // simple objects library
53 // - make sure to change the number of objects
56 DriverObjects CURRENT_OBJECT
=
58 init_pheromone
, // init, must be called first
59 compile_pheromone
, // compile
60 draw_pheromone
, // draw
61 render_pheromone
, // render to scene
66 // call 1. garden.generate
67 // call 2. garden.drawall
68 // call 3. garden.shutdown
69 DriverSentinel CURRENT_BOT
=
72 CreatePheromone
, // create
73 DestroyPheromone
, // destroy
74 RenderPheromone
, // render
75 ProcessPheromone
, // process
77 Generate_Pheromones
, // generate
78 Shutdown_Pheromones
, // shutdown
79 Draw_Pheromones
, // drawall
82 0 // this value is faulty! MAX_PHEROMONES
88 // Note: this is a cpu hog, it will find an open
89 // slot searching to the max possibly
90 // implement a better method like some sort cache
92 void ActivatePheromone(float x
, float y
, float dir
)
95 for (i
= 0; i
< MAX_PHEROMONES
; i
++)
97 if (CURRENT_BOT
.objects
[i
]->state
== DEAD_STATE
)
101 if (i
>= MAX_PHEROMONES
)
105 CURRENT_BOT
.objects
[i
]->position
[0] =x
;
106 CURRENT_BOT
.objects
[i
]->position
[2] =y
;
107 CURRENT_BOT
.objects
[i
]->rotation
[1] = dir
;
108 CURRENT_BOT
.objects
[i
]->state
= ALIVE_STATE
;
109 CURRENT_BOT
.objects
[i
]->food
= PHEROMONE_LIFE
;
111 CURRENT_BOT
.objects
[i
]->delete_flag
= false;
114 } // end of the function
119 static void Generate_Pheromones(void)
124 // This has to be set here because
125 // of a config file bug
126 CURRENT_BOT
.max_items
= MAX_PHEROMONES
;
128 // create the array of pointers
129 CURRENT_BOT
.objects
= (CURRENT_OBJ
**)malloc(
130 sizeof(CURRENT_OBJ
*)*CURRENT_BOT
.max_items
);
132 for (index
= 0; index
< CURRENT_BOT
.max_items
; index
++)
136 // this bordering on insane
137 // allocate an array of bot pointers, duh for nest
138 CURRENT_BOT
.objects
[index
] = CURRENT_BOT
.create(index
);
144 } // end of the function
149 static void Shutdown_Pheromones(void)
153 for (index
= 0; index
< CURRENT_BOT
.max_items
; index
++)
155 CURRENT_BOT
.destroy( CURRENT_BOT
.objects
[index
]);
159 // Shrug, free the ptr-to-ptrs
160 //free(CURRENT_BOT.objects);
161 RELEASE_OBJECT(CURRENT_BOT
.objects
);
164 } // end of the function
170 static void Draw_Pheromones(void)
174 for (index
= 0; index
< CURRENT_BOT
.max_items
; index
++)
176 CURRENT_BOT
.process( CURRENT_BOT
.objects
[index
]);
178 CURRENT_BOT
.render( CURRENT_BOT
.objects
[index
]);
182 } // end of the function
188 static void ProcessPheromone(CURRENT_PTR b
)
193 b
->state
= DEAD_STATE
; // pheromone is dead
198 } // end of the function
204 static CURRENT_PTR
CreatePheromone(int bot_id
)
208 bot
= (CURRENT_PTR
)malloc(sizeof(CURRENT_OBJ
));
210 // I like to be extra careful
211 ZeroMemory((CURRENT_PTR
)bot
,
212 sizeof(CURRENT_OBJ
));
214 bot
->position
[0] = 0;
215 bot
->position
[1] = 0;
216 bot
->position
[2] = 0;
218 bot
->list_id
= bot_id
;
221 bot
->rotation
[0] = 0;
222 bot
->rotation
[1] = 0;
223 bot
->rotation
[2] = 0;
229 bot
->color
[0] = 1.0f
;
230 bot
->color
[1] = 1.0f
;
231 bot
->color
[2] = 1.0f
;
233 bot
->state
= DEAD_STATE
;
235 bot
->food
= PHEROMONE_LIFE
;
237 bot
->delete_flag
= false;
244 } // end of the function
249 static void DestroyPheromone(CURRENT_PTR b
)
253 } // end of the functino
258 static void RenderPheromone(CURRENT_PTR boid
)
261 if (boid
->state
== DEAD_STATE
)
265 glDisable(GL_LIGHTING
);
270 // Translate then rotate
271 glTranslatef(boid
->position
[0],boid
->position
[1],
274 // rotate based on the ship struct
275 glRotatef(boid
->rotation
[1], 0.0f
, 1.0f
, 0.0f
);
276 glRotatef(boid
->rotation
[0], 1.0f
, 0.0f
, 0.0f
);
277 glRotatef(boid
->rotation
[2], 0.0f
, 0.0f
, 1.0f
);
281 glScalef(boid
->size
[0], boid
->size
[1], boid
->size
[2]);
284 // This may or may not change the color
285 glColor3f(boid
->color
[0], boid
->color
[1], boid
->color
[2]);
288 driver_objects
[SQUARE_OBJECT
]->render();
293 glEnable(GL_LIGHTING
);
296 } // end of the function
299 //---------------------------------------------------------
301 //=========================================================
302 //=========================================================
303 static void draw_pheromone(void)
309 glBegin(GL_LINE_LOOP
);
312 glVertex3f(-h
, 0.0f
, h
); // left bottom
313 glVertex3f( h
, 0.0f
, h
); // right bottom
314 glVertex3f( h
, 0.0f
, -h
); // top right
315 glVertex3f(-h
, 0.0f
,-h
); // top left
319 } // end of the function
324 // - load anything special about the
325 // one important function
327 static void init_pheromone(int list_id
)
330 CURRENT_OBJECT
.visible
= 1;
332 // store the id through the function
333 // there is probably a better way to do this
334 CURRENT_OBJECT
.call_id
= list_id
;
336 } // end of the functino
339 //=========================================================
340 // Now the function to actually draw it
341 //=========================================================
342 static void render_pheromone(void)
346 glCallList(CURRENT_OBJECT
.call_id
);
350 } // end of the function
352 //=========================================================
354 //=========================================================
355 static void compile_pheromone(void)
358 // setup a spot for display list for background
359 //object = getcurrentobject();
360 id
= CURRENT_OBJECT
.call_id
;
363 glNewList(id
, GL_COMPILE
);
365 // call drawing function
366 // but this may method make it a little better
367 CURRENT_OBJECT
.draw();
371 } // end of the function