Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/subprojects/collision_detection/collision_detection.cc @ 5577

Last change on this file since 5577 was 5486, checked in by bensch, 19 years ago

orxonox/trunk: subproject Collision Detection: now has its own WorldEntity

File size: 9.9 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14
15   this file extends the framework file, so it renders what i want.
16*/
17
18#include "framework.h"
19
20#include "fields.h"
21#include "stdlibincl.h"
22#include "light.h"
23
24#include "cd_engine.h"
25#include "bv_tree.h"
26
27#include "md2Model.h"
28#include "model.h"
29#include "collision_test_entity.h"
30
31
32#include "graphics_engine.h"
33#include "list.h"
34
35
36Model* mod;
37MD2Model* model;
38int drawMode;
39int depth;
40float iterata;
41tList<WorldEntity>* entityList;
42
43int lastFrame, currentFrame, dt;
44bool drawModel = false;
45
46WorldEntity* a;
47WorldEntity* b;
48//Terrain* c;
49bool animateModel = false;
50
51void Framework::moduleInit(int argc, char** argv)
52{
53  GraphicsEngine::getInstance()->setWindowName("Collision Cluster", "collision");
54
55  CDEngine::getInstance();
56
57  /* Primitive Data Test */
58//   sVec3D* data = new sVec3D[6];
59//   float tmp[6][3] = {{0.0, 4.2, 2.4}, {3.0, 3.0, 2.0}, {5.0, 1.0, 6.0}, {6.5, 1.0, 3.0}, {7.0, 3.0, 5.0}, {8.0, 6.0, 6.0}};
60//   for(int i = 0; i < 6; ++i)
61//   {
62//     data[i][0] = tmp[i][0];
63//     data[i][1] = tmp[i][1];
64//     data[i][2] = tmp[i][2];
65//   }
66//   CDEngine::getInstance()->debugSpawnTree(5, data, 6);
67
68  /* MD2 Model Test */
69//   model = new MD2Model("models/tris.md2", "models/tris.pcx");
70//   model->tick(0.1f);
71//   CDEngine::getInstance()->debugSpawnTree(9, model->data->pVertices, model->data->numVertices);
72
73  /* OBJ - Model Test */
74//   mod = (Model*)ResourceManager::getInstance()->load("models/reaplow.obj", OBJ, RP_CAMPAIGN);
75//   CDEngine::getInstance()->debugSpawnTree(9, (sVec3D*)mod->getVertexArray(), mod->getVertexArrayCount());
76
77
78
79  entityList = new tList<WorldEntity>();
80
81//   a = new TestEntity(); a->setName("Clown1");
82   b = new CollisionTestEntity(); b->setName("Jaeger");
83//   a = new Terrain();
84
85//   b->setRelCoor(0.0, 0.0, -20.0);
86//   b->setRelDir(Quaternion(-M_PI/2.0f, Vector(0.0, 1.0, 0.0)));
87
88  entityList->add(b);
89//   entityList->add(b);
90
91  CDEngine::getInstance()->setEntityList(entityList);
92
93  LightManager* lightMan = LightManager::getInstance();
94  lightMan->setAmbientColor(.1,.1,.1);
95  (new Light())->setAbsCoor(-5.0, 50.0, -40.0);
96  (new Light())->setAbsCoor(100, 80, 60);
97
98
99  /* properties */
100  drawMode = DRAW_MODEL;
101  depth = 0;
102  dt = lastFrame = currentFrame = 0;
103  iterata = 0.05f;
104
105  moduleHelp();
106}
107
108
109void Framework::moduleEventHandler(SDL_Event* event)
110{
111  switch (event->type)
112  {
113    case SDL_KEYDOWN:
114      switch (event->key.keysym.sym)
115      {
116        case SDLK_a:
117          drawMode |= DRAW_ALL;
118          break;
119        case SDLK_0:
120        {
121          printf("Setting tree depth = 0\n");
122          depth = 0;
123          int temp = drawMode & DRAW_ALL;
124          drawMode ^= temp;
125          drawMode |= DRAW_SINGLE;
126          break;
127        }
128        case SDLK_1:
129        {
130          printf("Setting tree depth = 1\n");
131          depth = 1;
132          int temp = drawMode & DRAW_ALL;
133          drawMode ^= temp;
134          drawMode |= DRAW_SINGLE;
135          break;
136        }
137        case SDLK_2:
138        {
139          printf("Setting tree depth = 2\n");
140          depth = 2;
141          int temp = drawMode & DRAW_ALL;
142          drawMode ^= temp;
143          drawMode |= DRAW_SINGLE;
144          break;
145        }
146        case SDLK_3:
147        {
148          printf("Setting tree depth = 3\n");
149          depth = 3;
150          int temp = drawMode & DRAW_ALL;
151          drawMode ^= temp;
152          drawMode |= DRAW_SINGLE;
153          break;
154        }
155        case SDLK_4:
156        {
157          printf("Setting tree depth = 4\n");
158          depth = 4;
159          int temp = drawMode & DRAW_ALL;
160          drawMode ^= temp;
161          drawMode |= DRAW_SINGLE;
162          break;
163        }
164        case SDLK_5:
165        {
166          printf("Setting tree depth = 5\n");
167          depth = 5;
168          int temp = drawMode & DRAW_ALL;
169          drawMode ^= temp;
170          drawMode |= DRAW_SINGLE;
171          break;
172        }
173        case SDLK_6:
174        {
175          printf("Setting tree depth = 6\n");
176          depth = 6;
177          int temp = drawMode & DRAW_ALL;
178          drawMode ^= temp;
179          drawMode |= DRAW_SINGLE;
180          break;
181        }
182        case SDLK_s:
183          if(drawMode & DRAW_SEPARATING_PLANE)
184          {
185            int temp = drawMode & DRAW_SEPARATING_PLANE;
186            drawMode ^= temp;
187            printf("Removing Separation Plane\n");
188          }
189          else
190          {
191            drawMode |= DRAW_SEPARATING_PLANE;
192            printf("Drawing Separation Plane\n");
193          }
194
195          break;
196        case SDLK_p:
197          if(drawMode & DRAW_BV_POLYGON)
198          {
199            int temp = drawMode & DRAW_BV_POLYGON;
200            drawMode ^= temp;
201            printf("Removing OBB Polygons\n");
202          }
203          else
204          {
205            drawMode |= DRAW_BV_POLYGON;
206            printf("Drawing OBB Polygons\n");
207          }
208          break;
209        case SDLK_o:
210          if(iterata == 0.0f)
211          {
212            iterata = 0.05f;
213          }
214          else
215          {
216            iterata = 0.0f;
217          }
218          break;
219
220      }
221  }
222}
223
224
225void Framework::moduleTick(float dt)
226{
227
228  CDEngine::getInstance()->checkCollisions();
229
230
231 // b->shiftCoor(Vector(0.0, 0.0, iterata * dt * 12.0f));
232
233
234  tIterator<WorldEntity>* iterator = entityList->getIterator();
235  WorldEntity* entity = iterator->firstElement();
236  while( entity != NULL)
237  {
238    if( unlikely(animateModel))
239      entity->tick(dt);
240    entity = iterator->nextElement();
241  }
242  delete iterator;
243}
244
245
246void Framework::moduleDraw() const
247{
248  //CDEngine::getInstance()->debugDraw(depth, drawMode);
249
250  tIterator<WorldEntity>* iterator = entityList->getIterator();
251  WorldEntity* entity = iterator->firstElement();
252  while( entity != NULL)
253  {
254    if( likely(drawModel))
255      entity->draw();
256    entity->drawBVTree(depth, drawMode);
257    printf("%i, %i\n", depth, drawMode);
258    entity = iterator->nextElement();
259  }
260  delete iterator;
261
262  LightManager::getInstance()->draw();
263}
264
265
266void Framework::moduleHelp(void) const
267{
268  printf("\n\n===========================");
269  printf("Collision Detection Modler:\n");
270  printf("Key Bindings:\n");
271  printf(" -| Displaying Polygons\t\t p\n");
272  printf(" -| Displaying Separation Plane\t s\n");
273  printf("\n");
274  printf(" -| Tree Depth 0\t\t 0\n");
275  printf(" -| Tree Depth 1\t\t 1\n");
276  printf(" -| Tree Depth 2\t\t 2\n");
277  printf(" -| Tree Depth 3\t\t 3\n");
278  printf(" -| Tree Depth 4\t\t 4\n");
279  printf(" -| Tree Depth 5\t\t 5\n");
280  printf("===========================\n\n");
281
282}
283
284int boxPolygons(GtkWidget* nonInterest, void* widget)
285{
286  if(drawMode & DRAW_BV_POLYGON)
287  {
288    int temp = drawMode & DRAW_BV_POLYGON;
289    drawMode ^= temp;
290    printf("Removing OBB Polygons\n");
291  }
292  else
293  {
294    drawMode |= DRAW_BV_POLYGON;
295    printf("Drawing OBB Polygons\n");
296  }
297}
298
299int seperatingPlanes(GtkWidget* nonInterest, void* widget)
300{
301  if(drawMode & DRAW_SEPARATING_PLANE)
302  {
303    int temp = drawMode & DRAW_SEPARATING_PLANE;
304    drawMode ^= temp;
305    printf("Removing Separation Plane\n");
306  }
307  else
308  {
309    drawMode |= DRAW_SEPARATING_PLANE;
310    printf("Drawing Separation Plane\n");
311  }
312}
313
314
315int blendedBox(GtkWidget* nonInterest, void* widget)
316{
317  if(drawMode & DRAW_BV_BLENDED)
318  {
319    int temp = drawMode & DRAW_BV_BLENDED;
320    drawMode ^= temp;
321    printf("Removing OBB Polygons\n");
322  }
323  else
324  {
325    drawMode |= DRAW_BV_BLENDED;
326    printf("Drawing OBB Polygons\n");
327  }
328}
329
330
331int drawModels(GtkWidget* nonInterest, void* widget)
332{
333  drawModel = !drawModel;
334}
335
336
337int animateModels(GtkWidget* nonInterest, void* widget)
338{
339  animateModel = !animateModel;
340}
341
342
343int drawPoints(GtkWidget* nonInterest, void* widget)
344{
345  if(drawMode & DRAW_POINTS)
346  {
347    int temp = drawMode & DRAW_POINTS;
348    drawMode ^= temp;
349
350  }
351  else
352  {
353    drawMode |= DRAW_POINTS;
354    printf("Drawing OBB Polygons\n");
355  }
356}
357
358
359int treeDepth(GtkWidget* nonInterest, void* widget)
360{
361  Option* option = (Option*) widget;
362  const char* name = option->getTitle();
363  char* value = option->save();
364
365  depth = atoi(value);
366  printf("Setting tree depth = %i\n", depth);
367  int temp = drawMode & DRAW_ALL;
368  drawMode ^= temp;
369  drawMode |= DRAW_SINGLE;
370
371  delete value;
372}
373
374
375void Framework::moduleInitGui(int argc, char** argv)
376{
377  Window* guiMainWindow = NULL;
378
379  initGUI(0, NULL);
380
381  guiMainWindow = new Window("Collision_detection");
382  {
383    Box* windowBox = new Box('v');
384    {
385      CheckButton* BoxPolygons = new CheckButton("Draw OBB Polygons");
386      BoxPolygons->connectSignal("clicked", (void*)BoxPolygons, boxPolygons);
387      windowBox->fill(BoxPolygons);
388
389
390      CheckButton* BlendedBox = new CheckButton("Draw OBB Blended");
391      BlendedBox->connectSignal("clicked", (void*)BlendedBox, blendedBox);
392      windowBox->fill(BlendedBox);
393
394
395      CheckButton* DrawModels = new CheckButton("Draw Models");
396      DrawModels->connectSignal("clicked", (void*)DrawModels, drawModels);
397      windowBox->fill(DrawModels);
398
399
400
401      CheckButton* AnimateModels = new CheckButton("Animate Models");
402      AnimateModels->connectSignal("clicked", (void*)AnimateModels, animateModels);
403      windowBox->fill(AnimateModels);
404
405
406      CheckButton* DrawPoints = new CheckButton("Draw Points");
407      DrawPoints->connectSignal("clicked", (void*)DrawPoints, drawPoints);
408      windowBox->fill(DrawPoints);
409
410
411      CheckButton* SeperatingPlanes = new CheckButton("SeperatingPlanes");
412      SeperatingPlanes->connectSignal("clicked", (void*)SeperatingPlanes, seperatingPlanes);
413      windowBox->fill(SeperatingPlanes);
414
415
416      Slider* TreeDepth = new Slider("TreeDepth", 0, 17);
417      TreeDepth->connectSignal("value_changed", (void*)TreeDepth, treeDepth);
418      windowBox->fill(TreeDepth);
419    }
420    guiMainWindow->fill(windowBox);
421  }
422  Window::mainWindow->showall();
423  Window::mainWindow->setSize(300, 500);
424}
Note: See TracBrowser for help on using the repository browser.