Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4773 was 4741, checked in by bensch, 19 years ago

orxonox/trunk: all subprojects working again

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