Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: now the stuff isnt drawed anymore

File size: 9.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: ...
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  currentFrame = SDL_GetTicks();
224  dt = currentFrame - lastFrame;
225
226
227  b->shiftCoor(Vector(0.0, 0.0, iterata));
228
229
230  tIterator<WorldEntity>* iterator = entityList->getIterator(); /* get the iterator - JAVA style */
231  WorldEntity* entity = iterator->nextElement();   /* this returns the FIRST element */
232  while( entity != NULL)                        /* nextElement() will return NULL at the end */
233  {
234    entity->tick(dt);
235    entity = iterator->nextElement();       /* give back the next element or NULL if last */
236  }
237  delete iterator;
238
239  lastFrame = currentFrame;
240}
241
242
243void Framework::moduleDraw() const
244{
245  CDEngine::getInstance()->drawBV(depth, drawMode);
246  LightManager::getInstance()->draw();
247
248  tIterator<WorldEntity>* iterator = entityList->getIterator(); /* get the iterator - JAVA style */
249  WorldEntity* entity = iterator->nextElement();   /* this returns the FIRST element */
250  while( entity != NULL)                        /* nextElement() will return NULL at the end */
251  {
252    if( drawModel)
253    entity->draw();
254    //entity->drawBVTree(depth, drawMode);
255    entity = iterator->nextElement();       /* give back the next element or NULL if last */
256  }
257  delete iterator;
258  //model->draw();
259}
260
261
262void Framework::moduleHelp(void) const
263{
264  printf("\n\n===========================");
265  printf("Collision Detection Modler:\n");
266  printf("Key Bindings:\n");
267  printf(" -| Displaying Polygons\t\t p\n");
268  printf(" -| Displaying Separation Plane\t s\n");
269  printf("\n");
270  printf(" -| Tree Depth 0\t\t 0\n");
271  printf(" -| Tree Depth 1\t\t 1\n");
272  printf(" -| Tree Depth 2\t\t 2\n");
273  printf(" -| Tree Depth 3\t\t 3\n");
274  printf(" -| Tree Depth 4\t\t 4\n");
275  printf(" -| Tree Depth 5\t\t 5\n");
276  printf("===========================\n\n");
277
278}
279
280int boxPolygons(GtkWidget* nonInterest, void* widget)
281{
282  if(drawMode & DRAW_BV_POLYGON)
283  {
284    int temp = drawMode & DRAW_BV_POLYGON;
285    drawMode ^= temp;
286    printf("Removing OBB Polygons\n");
287  }
288  else
289  {
290    drawMode |= DRAW_BV_POLYGON;
291    printf("Drawing OBB Polygons\n");
292  }
293}
294
295int seperatingPlanes(GtkWidget* nonInterest, void* widget)
296{
297  if(drawMode & DRAW_SEPARATING_PLANE)
298  {
299    int temp = drawMode & DRAW_SEPARATING_PLANE;
300    drawMode ^= temp;
301    printf("Removing Separation Plane\n");
302  }
303  else
304  {
305    drawMode |= DRAW_SEPARATING_PLANE;
306    printf("Drawing Separation Plane\n");
307  }
308}
309
310
311int blendedBox(GtkWidget* nonInterest, void* widget)
312{
313  if(drawMode & DRAW_BV_BLENDED)
314  {
315    int temp = drawMode & DRAW_BV_BLENDED;
316    drawMode ^= temp;
317    printf("Removing OBB Polygons\n");
318  }
319  else
320  {
321    drawMode |= DRAW_BV_BLENDED;
322    printf("Drawing OBB Polygons\n");
323  }
324}
325
326
327int drawModels(GtkWidget* nonInterest, void* widget)
328{
329  drawModel = !drawModel;
330}
331
332
333int treeDepth(GtkWidget* nonInterest, void* widget)
334{
335  Option* option = (Option*) widget;
336  const char* name = option->getTitle();
337  char* value = option->save();
338
339  depth = atoi(value);
340  printf("Setting tree depth = %i\n", depth);
341  int temp = drawMode & DRAW_ALL;
342  drawMode ^= temp;
343  drawMode |= DRAW_SINGLE;
344
345  delete value;
346}
347
348
349void Framework::moduleInitGui(int argc, char** argv)
350{
351  Window* guiMainWindow = NULL;
352
353  initGUI(0, NULL);
354
355  guiMainWindow = new Window("Collision_detection");
356  {
357    Box* windowBox = new Box('v');
358    {
359      CheckButton* BoxPolygons = new CheckButton("Draw OBB Polygons");
360      BoxPolygons->connectSignal("clicked", (void*)BoxPolygons, boxPolygons);
361      windowBox->fill(BoxPolygons);
362
363
364      CheckButton* BlendedBox = new CheckButton("Draw OBB Blended");
365      BlendedBox->connectSignal("clicked", (void*)BlendedBox, blendedBox);
366      windowBox->fill(BlendedBox);
367
368
369      CheckButton* DrawModels = new CheckButton("Draw Models");
370      DrawModels->connectSignal("clicked", (void*)DrawModels, drawModels);
371      windowBox->fill(DrawModels);
372
373
374      CheckButton* SeperatingPlanes = new CheckButton("SeperatingPlanes");
375      SeperatingPlanes->connectSignal("clicked", (void*)SeperatingPlanes, seperatingPlanes);
376      windowBox->fill(SeperatingPlanes);
377
378
379      Slider* TreeDepth = new Slider("TreeDepth", 0, 5);
380      TreeDepth->connectSignal("value_changed", (void*)TreeDepth, treeDepth);
381      windowBox->fill(TreeDepth);
382    }
383    guiMainWindow->fill(windowBox);
384  }
385  Window::mainWindow->showall();
386  Window::mainWindow->setSize(300, 500);
387}
Note: See TracBrowser for help on using the repository browser.