Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/cd/src/subprojects/collision_detection/collision_detection.cc @ 7536

Last change on this file since 7536 was 7533, checked in by patrick, 19 years ago

collision: subproject up

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