Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: now used the player model to do an obb on it - works greatly and it realy makes sense! im so excited…

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