Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10651 was 10618, checked in by bknecht, 18 years ago

merged cleanup into trunk (only improvements)

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