Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7138 was 7130, checked in by bensch, 19 years ago

orxonox/trunk: removed some std::list

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