Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4844 was 4741, checked in by bensch, 19 years ago

orxonox/trunk: all subprojects working again

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 "test_entity.h"
30#include "environment.h"
31
32
33#include "graphics_engine.h"
34#include "list.h"
35
36
37Model* mod;
38MD2Model* model;
39int drawMode;
40int depth;
41float iterata;
42tList<WorldEntity>* entityList;
43
44int lastFrame, currentFrame, dt;
45bool drawModel = false;
46
47WorldEntity* a;
48WorldEntity* b;
49//Terrain* c;
50bool animateModel = false;
51
52void Framework::moduleInit(int argc, char** argv)
53{
54  GraphicsEngine::getInstance()->setWindowName("Collision Cluster", "collision");
55
56  CDEngine::getInstance();
57
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 Environment(); b->setName("Jaeger");
84  //c = new Terrain();
85
86  b->setRelCoor(0.0, 0.0, -20.0);
87  b->setRelDir(Quaternion(-M_PI/2.0f, Vector(0.0, 1.0, 0.0)));
88
89  entityList->add(a);
90  entityList->add(b);
91
92  CDEngine::getInstance()->setEntityList(entityList);
93
94  LightManager* lightMan = LightManager::getInstance();
95  lightMan->setAmbientColor(.1,.1,.1);
96  (new Light())->setAbsCoor(-5.0, 50.0, -40.0);
97  (new Light())->setAbsCoor(100, 80, 60);
98
99
100  /* properties */
101  drawMode = DRAW_MODEL;
102  depth = 0;
103  dt = lastFrame = currentFrame = 0;
104  iterata = 0.05f;
105
106  moduleHelp();
107}
108
109
110void Framework::moduleEventHandler(SDL_Event* event)
111{
112  switch (event->type)
113  {
114    case SDL_KEYDOWN:
115      switch (event->key.keysym.sym)
116      {
117        case SDLK_a:
118          drawMode |= DRAW_ALL;
119          break;
120        case SDLK_0:
121        {
122          printf("Setting tree depth = 0\n");
123          depth = 0;
124          int temp = drawMode & DRAW_ALL;
125          drawMode ^= temp;
126          drawMode |= DRAW_SINGLE;
127          break;
128        }
129        case SDLK_1:
130        {
131          printf("Setting tree depth = 1\n");
132          depth = 1;
133          int temp = drawMode & DRAW_ALL;
134          drawMode ^= temp;
135          drawMode |= DRAW_SINGLE;
136          break;
137        }
138        case SDLK_2:
139        {
140          printf("Setting tree depth = 2\n");
141          depth = 2;
142          int temp = drawMode & DRAW_ALL;
143          drawMode ^= temp;
144          drawMode |= DRAW_SINGLE;
145          break;
146        }
147        case SDLK_3:
148        {
149          printf("Setting tree depth = 3\n");
150          depth = 3;
151          int temp = drawMode & DRAW_ALL;
152          drawMode ^= temp;
153          drawMode |= DRAW_SINGLE;
154          break;
155        }
156        case SDLK_4:
157        {
158          printf("Setting tree depth = 4\n");
159          depth = 4;
160          int temp = drawMode & DRAW_ALL;
161          drawMode ^= temp;
162          drawMode |= DRAW_SINGLE;
163          break;
164        }
165        case SDLK_5:
166        {
167          printf("Setting tree depth = 5\n");
168          depth = 5;
169          int temp = drawMode & DRAW_ALL;
170          drawMode ^= temp;
171          drawMode |= DRAW_SINGLE;
172          break;
173        }
174        case SDLK_6:
175        {
176          printf("Setting tree depth = 6\n");
177          depth = 6;
178          int temp = drawMode & DRAW_ALL;
179          drawMode ^= temp;
180          drawMode |= DRAW_SINGLE;
181          break;
182        }
183        case SDLK_s:
184          if(drawMode & DRAW_SEPARATING_PLANE)
185          {
186            int temp = drawMode & DRAW_SEPARATING_PLANE;
187            drawMode ^= temp;
188            printf("Removing Separation Plane\n");
189          }
190          else
191          {
192            drawMode |= DRAW_SEPARATING_PLANE;
193            printf("Drawing Separation Plane\n");
194          }
195
196          break;
197        case SDLK_p:
198          if(drawMode & DRAW_BV_POLYGON)
199          {
200            int temp = drawMode & DRAW_BV_POLYGON;
201            drawMode ^= temp;
202            printf("Removing OBB Polygons\n");
203          }
204          else
205          {
206            drawMode |= DRAW_BV_POLYGON;
207            printf("Drawing OBB Polygons\n");
208          }
209          break;
210        case SDLK_o:
211          if(iterata == 0.0f)
212          {
213            iterata = 0.05f;
214          }
215          else
216          {
217            iterata = 0.0f;
218          }
219          break;
220
221      }
222  }
223}
224
225
226void Framework::moduleTick(float dt)
227{
228
229  CDEngine::getInstance()->checkCollisions();
230
231
232  b->shiftCoor(Vector(0.0, 0.0, iterata * dt * 12.0f));
233
234
235  tIterator<WorldEntity>* iterator = entityList->getIterator();
236  WorldEntity* entity = iterator->nextElement();
237  while( entity != NULL)
238  {
239    if( unlikely(animateModel))
240      entity->tick(dt);
241    entity = iterator->nextElement();
242  }
243  delete iterator;
244}
245
246
247void Framework::moduleDraw() const
248{
249  //CDEngine::getInstance()->debugDraw(depth, drawMode);
250
251  tIterator<WorldEntity>* iterator = entityList->getIterator();
252  WorldEntity* entity = iterator->nextElement();
253  while( entity != NULL)
254  {
255    if( likely(drawModel))
256    entity->draw();
257    entity->drawBVTree(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.