Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4707 was 4707, checked in by patrick, 20 years ago

orxonox/trunk: there where some redundances in the drawing process… now the app executes much faster

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