Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4682 was 4682, checked in by patrick, 19 years ago

orxonox/trunk: now there is a possibility to render the bvtree through the world entities, the bvtree is a member of the worldentity

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