Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8457 was 7841, checked in by patrick, 18 years ago

trunk: collision handle introduced and other stuff

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