Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5516 was 5486, checked in by bensch, 19 years ago

orxonox/trunk: subproject Collision Detection: now has its own WorldEntity

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"
[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");
[5029]83//   a = new Terrain();
[4708]84
[4903]85//   b->setRelCoor(0.0, 0.0, -20.0);
86//   b->setRelDir(Quaternion(-M_PI/2.0f, Vector(0.0, 1.0, 0.0)));
[4630]87
[5029]88  entityList->add(b);
[4903]89//   entityList->add(b);
[4630]90
[4688]91  CDEngine::getInstance()->setEntityList(entityList);
[4675]92
[4552]93  LightManager* lightMan = LightManager::getInstance();
[4717]94  lightMan->setAmbientColor(.1,.1,.1);
[4741]95  (new Light())->setAbsCoor(-5.0, 50.0, -40.0);
96  (new Light())->setAbsCoor(100, 80, 60);
[4636]97
[4710]98
[4675]99  /* properties */
[4636]100  drawMode = DRAW_MODEL;
[4673]101  depth = 0;
[4679]102  dt = lastFrame = currentFrame = 0;
[4704]103  iterata = 0.05f;
[4636]104
[4647]105  moduleHelp();
[4333]106}
107
[4546]108
[4334]109void Framework::moduleEventHandler(SDL_Event* event)
110{
111  switch (event->type)
[4622]112  {
[4334]113    case SDL_KEYDOWN:
114      switch (event->key.keysym.sym)
[4622]115      {
[4636]116        case SDLK_a:
117          drawMode |= DRAW_ALL;
[4615]118          break;
[4638]119        case SDLK_0:
120        {
121          printf("Setting tree depth = 0\n");
122          depth = 0;
123          int temp = drawMode & DRAW_ALL;
124          drawMode ^= temp;
125          drawMode |= DRAW_SINGLE;
126          break;
127        }
[4622]128        case SDLK_1:
[4636]129        {
130          printf("Setting tree depth = 1\n");
131          depth = 1;
132          int temp = drawMode & DRAW_ALL;
133          drawMode ^= temp;
134          drawMode |= DRAW_SINGLE;
[4622]135          break;
[4636]136        }
137        case SDLK_2:
138        {
139          printf("Setting tree depth = 2\n");
140          depth = 2;
141          int temp = drawMode & DRAW_ALL;
142          drawMode ^= temp;
143          drawMode |= DRAW_SINGLE;
144          break;
145        }
146        case SDLK_3:
147        {
148          printf("Setting tree depth = 3\n");
149          depth = 3;
150          int temp = drawMode & DRAW_ALL;
151          drawMode ^= temp;
152          drawMode |= DRAW_SINGLE;
153          break;
154        }
155        case SDLK_4:
156        {
157          printf("Setting tree depth = 4\n");
158          depth = 4;
159          int temp = drawMode & DRAW_ALL;
160          drawMode ^= temp;
161          drawMode |= DRAW_SINGLE;
162          break;
163        }
164        case SDLK_5:
165        {
166          printf("Setting tree depth = 5\n");
167          depth = 5;
168          int temp = drawMode & DRAW_ALL;
169          drawMode ^= temp;
170          drawMode |= DRAW_SINGLE;
171          break;
172        }
173        case SDLK_6:
174        {
175          printf("Setting tree depth = 6\n");
176          depth = 6;
177          int temp = drawMode & DRAW_ALL;
178          drawMode ^= temp;
179          drawMode |= DRAW_SINGLE;
180          break;
181        }
182        case SDLK_s:
183          if(drawMode & DRAW_SEPARATING_PLANE)
184          {
185            int temp = drawMode & DRAW_SEPARATING_PLANE;
186            drawMode ^= temp;
187            printf("Removing Separation Plane\n");
188          }
189          else
190          {
191            drawMode |= DRAW_SEPARATING_PLANE;
192            printf("Drawing Separation Plane\n");
193          }
194
195          break;
196        case SDLK_p:
197          if(drawMode & DRAW_BV_POLYGON)
198          {
199            int temp = drawMode & DRAW_BV_POLYGON;
200            drawMode ^= temp;
201            printf("Removing OBB Polygons\n");
202          }
203          else
204          {
205            drawMode |= DRAW_BV_POLYGON;
206            printf("Drawing OBB Polygons\n");
207          }
208          break;
[4704]209        case SDLK_o:
210          if(iterata == 0.0f)
211          {
212            iterata = 0.05f;
213          }
214          else
215          {
216            iterata = 0.0f;
217          }
218          break;
[4636]219
[4622]220      }
221  }
[4333]222}
223
[4546]224
[4333]225void Framework::moduleTick(float dt)
226{
[4679]227
[4696]228  CDEngine::getInstance()->checkCollisions();
[4688]229
[4679]230
[5033]231 // b->shiftCoor(Vector(0.0, 0.0, iterata * dt * 12.0f));
[4679]232
[4701]233
[4708]234  tIterator<WorldEntity>* iterator = entityList->getIterator();
[5115]235  WorldEntity* entity = iterator->firstElement();
[4708]236  while( entity != NULL)
[4675]237  {
[4721]238    if( unlikely(animateModel))
[4719]239      entity->tick(dt);
[4708]240    entity = iterator->nextElement();
[4675]241  }
242  delete iterator;
[4333]243}
244
[4546]245
[4349]246void Framework::moduleDraw() const
[4334]247{
[4718]248  //CDEngine::getInstance()->debugDraw(depth, drawMode);
[4710]249
[4708]250  tIterator<WorldEntity>* iterator = entityList->getIterator();
[5115]251  WorldEntity* entity = iterator->firstElement();
[4708]252  while( entity != NULL)
[4679]253  {
[4707]254    if( likely(drawModel))
[5482]255      entity->draw();
[4707]256    entity->drawBVTree(depth, drawMode);
[5034]257    printf("%i, %i\n", 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.