Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/cleanup/src/subprojects/collision_detection/collision_detection.cc @ 10759

Last change on this file since 10759 was 10618, checked in by bknecht, 18 years ago

merged cleanup into trunk (only improvements)

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