Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4667 was 4661, checked in by patrick, 20 years ago

orxonox/trunk: center is calculated more precisly now

File size: 6.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
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 = 2;
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
234int treeDepth(GtkWidget* nonInterest, void* widget)
235{
236  Option* option = (Option*) widget;
237  const char* name = option->getTitle();
238  char* value = option->save();
239
240  depth = atoi(value);
241  printf("Setting tree depth = %i\n", depth);
242  int temp = drawMode & DRAW_ALL;
243  drawMode ^= temp;
244  drawMode |= DRAW_SINGLE;
245
246  delete value;
247}
248
249
250void Framework::moduleInitGui(int argc, char** argv)
251{
252  Window* guiMainWindow = NULL;
253
254  initGUI(0, NULL);
255
256  guiMainWindow = new Window("Collision_detection");
257  {
258    Box* windowBox = new Box('v');
259    {
260      CheckButton* BoxPolygons = new CheckButton("BoxPolygons");
261      BoxPolygons->connectSignal("clicked", (void*)BoxPolygons, boxPolygons);
262      windowBox->fill(BoxPolygons);
263
264
265      CheckButton* SeperatingPlanes = new CheckButton("SeperatingPlanes");
266      SeperatingPlanes->connectSignal("clicked", (void*)SeperatingPlanes, seperatingPlanes);
267      windowBox->fill(SeperatingPlanes);
268
269      Slider* TreeDepth = new Slider("TreeDepth", 0, 5);
270      TreeDepth->connectSignal("value_changed", (void*)TreeDepth, treeDepth);
271      windowBox->fill(TreeDepth);
272    }
273    guiMainWindow->fill(windowBox);
274  }
275  Window::mainWindow->showall();
276  Window::mainWindow->setSize(300, 500);
277}
Note: See TracBrowser for help on using the repository browser.