Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5030 was 5029, checked in by patrick, 19 years ago

orxonox/trunk: some changes in the NPC interface class

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