Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: minor update with the brightness of the background

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