Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/cd/src/subprojects/collision_detection/collision_detection.cc @ 7422

Last change on this file since 7422 was 7365, checked in by bensch, 19 years ago

orxonox/branches/cd: merged the new collision-detection back.
merged and collissions resolved.

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