Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: collision-gui implemented

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