Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: the collision detection gui now works properly

File size: 6.8 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
29#include "graphics_engine.h"
30
31
32
33MD2Model* model;
34int drawMode;
35int depth;
36
37void Framework::moduleInit(int argc, char** argv)
38{
39  GraphicsEngine::getInstance()->setWindowName("Collision Cluster", "collision");
40
41  CDEngine::getInstance();
42  //CDEngine::getInstance()->debug();
43
44  model = new MD2Model("models/tris.md2", "models/tris.pcx");
45  model->tick(0.1f);
46
47
48  CDEngine::getInstance()->debugSpawnTree(9, model->data->pVertices, model->data->numVertices);
49
50
51  LightManager* lightMan = LightManager::getInstance();
52  lightMan->setAmbientColor(.1,.1,.1);
53  lightMan->addLight();
54  lightMan->setPosition(30, 30, 30);
55  lightMan->addLight();
56  lightMan->setPosition(-30, -30, -30);
57
58  drawMode = DRAW_MODEL;
59  depth = 0;
60
61  moduleHelp();
62}
63
64
65void Framework::moduleEventHandler(SDL_Event* event)
66{
67  switch (event->type)
68  {
69    case SDL_KEYDOWN:
70      switch (event->key.keysym.sym)
71      {
72        case SDLK_a:
73          drawMode |= DRAW_ALL;
74          break;
75        case SDLK_0:
76        {
77          printf("Setting tree depth = 0\n");
78          depth = 0;
79          int temp = drawMode & DRAW_ALL;
80          drawMode ^= temp;
81          drawMode |= DRAW_SINGLE;
82          break;
83        }
84        case SDLK_1:
85        {
86          printf("Setting tree depth = 1\n");
87          depth = 1;
88          int temp = drawMode & DRAW_ALL;
89          drawMode ^= temp;
90          drawMode |= DRAW_SINGLE;
91          break;
92        }
93        case SDLK_2:
94        {
95          printf("Setting tree depth = 2\n");
96          depth = 2;
97          int temp = drawMode & DRAW_ALL;
98          drawMode ^= temp;
99          drawMode |= DRAW_SINGLE;
100          break;
101        }
102        case SDLK_3:
103        {
104          printf("Setting tree depth = 3\n");
105          depth = 3;
106          int temp = drawMode & DRAW_ALL;
107          drawMode ^= temp;
108          drawMode |= DRAW_SINGLE;
109          break;
110        }
111        case SDLK_4:
112        {
113          printf("Setting tree depth = 4\n");
114          depth = 4;
115          int temp = drawMode & DRAW_ALL;
116          drawMode ^= temp;
117          drawMode |= DRAW_SINGLE;
118          break;
119        }
120        case SDLK_5:
121        {
122          printf("Setting tree depth = 5\n");
123          depth = 5;
124          int temp = drawMode & DRAW_ALL;
125          drawMode ^= temp;
126          drawMode |= DRAW_SINGLE;
127          break;
128        }
129        case SDLK_6:
130        {
131          printf("Setting tree depth = 6\n");
132          depth = 6;
133          int temp = drawMode & DRAW_ALL;
134          drawMode ^= temp;
135          drawMode |= DRAW_SINGLE;
136          break;
137        }
138        case SDLK_s:
139          if(drawMode & DRAW_SEPARATING_PLANE)
140          {
141            int temp = drawMode & DRAW_SEPARATING_PLANE;
142            drawMode ^= temp;
143            printf("Removing Separation Plane\n");
144          }
145          else
146          {
147            drawMode |= DRAW_SEPARATING_PLANE;
148            printf("Drawing Separation Plane\n");
149          }
150
151          break;
152        case SDLK_p:
153          if(drawMode & DRAW_BV_POLYGON)
154          {
155            int temp = drawMode & DRAW_BV_POLYGON;
156            drawMode ^= temp;
157            printf("Removing OBB Polygons\n");
158          }
159          else
160          {
161            drawMode |= DRAW_BV_POLYGON;
162            printf("Drawing OBB Polygons\n");
163          }
164          break;
165
166      }
167  }
168}
169
170
171void Framework::moduleTick(float dt)
172{
173}
174
175
176void Framework::moduleDraw() const
177{
178  CDEngine::getInstance()->drawBV(depth, drawMode);
179
180  LightManager::getInstance()->draw();
181
182  //model->draw();
183}
184
185
186void Framework::moduleHelp(void) const
187{
188  printf("\n\n===========================");
189  printf("Collision Detection Modler:\n");
190  printf("Key Bindings:\n");
191  printf(" -| Displaying Polygons\t\t p\n");
192  printf(" -| Displaying Separation Plane\t s\n");
193  printf("\n");
194  printf(" -| Tree Depth 0\t\t 0\n");
195  printf(" -| Tree Depth 1\t\t 1\n");
196  printf(" -| Tree Depth 2\t\t 2\n");
197  printf(" -| Tree Depth 3\t\t 3\n");
198  printf(" -| Tree Depth 4\t\t 4\n");
199  printf(" -| Tree Depth 5\t\t 5\n");
200  printf("===========================\n\n");
201
202}
203
204int boxPolygons(GtkWidget* nonInterest, void* widget)
205{
206  if(drawMode & DRAW_BV_POLYGON)
207  {
208    int temp = drawMode & DRAW_BV_POLYGON;
209    drawMode ^= temp;
210    printf("Removing OBB Polygons\n");
211  }
212  else
213  {
214    drawMode |= DRAW_BV_POLYGON;
215    printf("Drawing OBB Polygons\n");
216  }
217}
218
219int seperatingPlanes(GtkWidget* nonInterest, void* widget)
220{
221  if(drawMode & DRAW_SEPARATING_PLANE)
222  {
223    int temp = drawMode & DRAW_SEPARATING_PLANE;
224    drawMode ^= temp;
225    printf("Removing Separation Plane\n");
226  }
227  else
228  {
229    drawMode |= DRAW_SEPARATING_PLANE;
230    printf("Drawing Separation Plane\n");
231  }
232}
233
234
235int blendedBox(GtkWidget* nonInterest, void* widget)
236{
237  if(drawMode & DRAW_BV_BLENDED)
238  {
239    int temp = drawMode & DRAW_BV_BLENDED;
240    drawMode ^= temp;
241    printf("Removing OBB Polygons\n");
242  }
243  else
244  {
245    drawMode |= DRAW_BV_BLENDED;
246    printf("Drawing OBB Polygons\n");
247  }
248}
249
250
251int treeDepth(GtkWidget* nonInterest, void* widget)
252{
253  Option* option = (Option*) widget;
254  const char* name = option->getTitle();
255  char* value = option->save();
256
257  depth = atoi(value);
258  printf("Setting tree depth = %i\n", depth);
259  int temp = drawMode & DRAW_ALL;
260  drawMode ^= temp;
261  drawMode |= DRAW_SINGLE;
262
263  delete value;
264}
265
266
267void Framework::moduleInitGui(int argc, char** argv)
268{
269  Window* guiMainWindow = NULL;
270
271  initGUI(0, NULL);
272
273  guiMainWindow = new Window("Collision_detection");
274  {
275    Box* windowBox = new Box('v');
276    {
277      CheckButton* BoxPolygons = new CheckButton("Draw OBB Polygons");
278      BoxPolygons->connectSignal("clicked", (void*)BoxPolygons, boxPolygons);
279      windowBox->fill(BoxPolygons);
280
281
282      CheckButton* BlendedBox = new CheckButton("Draw OBB Blended");
283      BlendedBox->connectSignal("clicked", (void*)BlendedBox, blendedBox);
284      windowBox->fill(BlendedBox);
285
286
287      CheckButton* SeperatingPlanes = new CheckButton("SeperatingPlanes");
288      SeperatingPlanes->connectSignal("clicked", (void*)SeperatingPlanes, seperatingPlanes);
289      windowBox->fill(SeperatingPlanes);
290
291
292      Slider* TreeDepth = new Slider("TreeDepth", 0, 5);
293      TreeDepth->connectSignal("value_changed", (void*)TreeDepth, treeDepth);
294      windowBox->fill(TreeDepth);
295    }
296    guiMainWindow->fill(windowBox);
297  }
298  Window::mainWindow->showall();
299  Window::mainWindow->setSize(300, 500);
300}
Note: See TracBrowser for help on using the repository browser.