Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/script_engine/src/subprojects/collision_detection/collision_detection.cc @ 7653

Last change on this file since 7653 was 7157, checked in by bensch, 19 years ago

sync

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