Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/spaceshipcontrol/src/subprojects/collision_detection/collision_detection.cc @ 6134

Last change on this file since 6134 was 5819, checked in by bensch, 19 years ago

orxonox/trunk: merged branches world_entities to trunk again
merged with command
svn merge -r5795:HEAD branches/world_entities/ trunk/
no conflicts (what a wonder)

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