Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5848 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
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"
[4675]33#include "list.h"
[4636]34
35
[4675]36Model* mod;
[4615]37MD2Model* model;
[4636]38int drawMode;
39int depth;
[4704]40float iterata;
[4675]41tList<WorldEntity>* entityList;
[4615]42
[4679]43int lastFrame, currentFrame, dt;
[4719]44bool drawModel = false;
[4679]45
[4710]46WorldEntity* a;
47WorldEntity* b;
48//Terrain* c;
[4719]49bool animateModel = false;
[4701]50
[4343]51void Framework::moduleInit(int argc, char** argv)
[4333]52{
[4646]53  GraphicsEngine::getInstance()->setWindowName("Collision Cluster", "collision");
54
[4546]55  CDEngine::getInstance();
[4679]56
[4710]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);
[4552]67
[4679]68  /* MD2 Model Test */
[4675]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);
[4552]72
[4679]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
[4675]79  entityList = new tList<WorldEntity>();
[4626]80
[4903]81//   a = new TestEntity(); a->setName("Clown1");
[5486]82   b = new CollisionTestEntity(); b->setName("Jaeger");
[5819]83   if (argc > 1)
84   {
85     printf("Loading model %s\n", argv[1]);
86     b->loadModel(argv[1]);
87   }
[5029]88//   a = new Terrain();
[4708]89
[4903]90//   b->setRelCoor(0.0, 0.0, -20.0);
91//   b->setRelDir(Quaternion(-M_PI/2.0f, Vector(0.0, 1.0, 0.0)));
[4630]92
[5029]93  entityList->add(b);
[4903]94//   entityList->add(b);
[4630]95
[4688]96  CDEngine::getInstance()->setEntityList(entityList);
[4675]97
[4552]98  LightManager* lightMan = LightManager::getInstance();
[4717]99  lightMan->setAmbientColor(.1,.1,.1);
[4741]100  (new Light())->setAbsCoor(-5.0, 50.0, -40.0);
101  (new Light())->setAbsCoor(100, 80, 60);
[4636]102
[4710]103
[4675]104  /* properties */
[4636]105  drawMode = DRAW_MODEL;
[4673]106  depth = 0;
[4679]107  dt = lastFrame = currentFrame = 0;
[4704]108  iterata = 0.05f;
[4636]109
[4647]110  moduleHelp();
[4333]111}
112
[4546]113
[4334]114void Framework::moduleEventHandler(SDL_Event* event)
115{
116  switch (event->type)
[4622]117  {
[4334]118    case SDL_KEYDOWN:
119      switch (event->key.keysym.sym)
[4622]120      {
[4636]121        case SDLK_a:
122          drawMode |= DRAW_ALL;
[4615]123          break;
[4638]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        }
[4622]133        case SDLK_1:
[4636]134        {
135          printf("Setting tree depth = 1\n");
136          depth = 1;
137          int temp = drawMode & DRAW_ALL;
138          drawMode ^= temp;
139          drawMode |= DRAW_SINGLE;
[4622]140          break;
[4636]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;
[4704]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;
[4636]224
[4622]225      }
226  }
[4333]227}
228
[4546]229
[4333]230void Framework::moduleTick(float dt)
231{
[4679]232
[4696]233  CDEngine::getInstance()->checkCollisions();
[4688]234
[4679]235
[5033]236 // b->shiftCoor(Vector(0.0, 0.0, iterata * dt * 12.0f));
[4679]237
[4701]238
[4708]239  tIterator<WorldEntity>* iterator = entityList->getIterator();
[5115]240  WorldEntity* entity = iterator->firstElement();
[4708]241  while( entity != NULL)
[4675]242  {
[4721]243    if( unlikely(animateModel))
[4719]244      entity->tick(dt);
[4708]245    entity = iterator->nextElement();
[4675]246  }
247  delete iterator;
[4333]248}
249
[4546]250
[4349]251void Framework::moduleDraw() const
[4334]252{
[4718]253  //CDEngine::getInstance()->debugDraw(depth, drawMode);
[4710]254
[4708]255  tIterator<WorldEntity>* iterator = entityList->getIterator();
[5115]256  WorldEntity* entity = iterator->firstElement();
[4708]257  while( entity != NULL)
[4679]258  {
[4707]259    if( likely(drawModel))
[5482]260      entity->draw();
[4707]261    entity->drawBVTree(depth, drawMode);
[5034]262    printf("%i, %i\n", depth, drawMode);
[4708]263    entity = iterator->nextElement();
[4679]264  }
265  delete iterator;
[4707]266
267  LightManager::getInstance()->draw();
[4334]268}
[4333]269
[4334]270
[4333]271void Framework::moduleHelp(void) const
272{
[4647]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
[4333]287}
288
[4646]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
[4671]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
[4686]336int drawModels(GtkWidget* nonInterest, void* widget)
337{
338  drawModel = !drawModel;
339}
340
341
[4719]342int animateModels(GtkWidget* nonInterest, void* widget)
343{
344  animateModel = !animateModel;
345}
346
347
[4712]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
[4646]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
[4343]380void Framework::moduleInitGui(int argc, char** argv)
[4333]381{
[4626]382  Window* guiMainWindow = NULL;
383
384  initGUI(0, NULL);
385
386  guiMainWindow = new Window("Collision_detection");
387  {
[4646]388    Box* windowBox = new Box('v');
389    {
[4671]390      CheckButton* BoxPolygons = new CheckButton("Draw OBB Polygons");
[4646]391      BoxPolygons->connectSignal("clicked", (void*)BoxPolygons, boxPolygons);
392      windowBox->fill(BoxPolygons);
393
394
[4671]395      CheckButton* BlendedBox = new CheckButton("Draw OBB Blended");
396      BlendedBox->connectSignal("clicked", (void*)BlendedBox, blendedBox);
397      windowBox->fill(BlendedBox);
398
399
[4686]400      CheckButton* DrawModels = new CheckButton("Draw Models");
401      DrawModels->connectSignal("clicked", (void*)DrawModels, drawModels);
402      windowBox->fill(DrawModels);
403
404
[4719]405
406      CheckButton* AnimateModels = new CheckButton("Animate Models");
407      AnimateModels->connectSignal("clicked", (void*)AnimateModels, animateModels);
408      windowBox->fill(AnimateModels);
409
410
[4712]411      CheckButton* DrawPoints = new CheckButton("Draw Points");
412      DrawPoints->connectSignal("clicked", (void*)DrawPoints, drawPoints);
413      windowBox->fill(DrawPoints);
414
415
[4646]416      CheckButton* SeperatingPlanes = new CheckButton("SeperatingPlanes");
417      SeperatingPlanes->connectSignal("clicked", (void*)SeperatingPlanes, seperatingPlanes);
418      windowBox->fill(SeperatingPlanes);
419
[4671]420
[4712]421      Slider* TreeDepth = new Slider("TreeDepth", 0, 17);
[4646]422      TreeDepth->connectSignal("value_changed", (void*)TreeDepth, treeDepth);
423      windowBox->fill(TreeDepth);
424    }
425    guiMainWindow->fill(windowBox);
[4626]426  }
427  Window::mainWindow->showall();
428  Window::mainWindow->setSize(300, 500);
[4333]429}
Note: See TracBrowser for help on using the repository browser.