[4615] | 1 | /* |
---|
[4333] | 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 | |
---|
[4378] | 20 | #include "fields.h" |
---|
[4381] | 21 | #include "stdlibincl.h" |
---|
[4552] | 22 | #include "light.h" |
---|
[4333] | 23 | |
---|
[4546] | 24 | #include "cd_engine.h" |
---|
[4635] | 25 | #include "bv_tree.h" |
---|
[4333] | 26 | |
---|
[4615] | 27 | #include "md2Model.h" |
---|
| 28 | |
---|
[4646] | 29 | #include "graphics_engine.h" |
---|
[4636] | 30 | |
---|
| 31 | |
---|
| 32 | |
---|
[4615] | 33 | MD2Model* model; |
---|
[4636] | 34 | int drawMode; |
---|
| 35 | int depth; |
---|
[4615] | 36 | |
---|
[4343] | 37 | void Framework::moduleInit(int argc, char** argv) |
---|
[4333] | 38 | { |
---|
[4646] | 39 | GraphicsEngine::getInstance()->setWindowName("Collision Cluster", "collision"); |
---|
| 40 | |
---|
[4546] | 41 | CDEngine::getInstance(); |
---|
[4646] | 42 | //CDEngine::getInstance()->debug(); |
---|
[4552] | 43 | |
---|
[4646] | 44 | model = new MD2Model("models/tris.md2", "models/tris.pcx"); |
---|
| 45 | model->tick(0.1f); |
---|
[4552] | 46 | |
---|
[4626] | 47 | |
---|
[4646] | 48 | CDEngine::getInstance()->debugSpawnTree(9, model->data->pVertices, model->data->numVertices); |
---|
[4630] | 49 | |
---|
| 50 | |
---|
[4552] | 51 | LightManager* lightMan = LightManager::getInstance(); |
---|
| 52 | lightMan->setAmbientColor(.1,.1,.1); |
---|
| 53 | lightMan->addLight(); |
---|
[4638] | 54 | lightMan->setPosition(30, 30, 30); |
---|
[4552] | 55 | lightMan->addLight(); |
---|
[4638] | 56 | lightMan->setPosition(-30, -30, -30); |
---|
[4636] | 57 | |
---|
| 58 | drawMode = DRAW_MODEL; |
---|
| 59 | depth = 2; |
---|
| 60 | |
---|
[4647] | 61 | moduleHelp(); |
---|
[4333] | 62 | } |
---|
| 63 | |
---|
[4546] | 64 | |
---|
[4334] | 65 | void Framework::moduleEventHandler(SDL_Event* event) |
---|
| 66 | { |
---|
| 67 | switch (event->type) |
---|
[4622] | 68 | { |
---|
[4334] | 69 | case SDL_KEYDOWN: |
---|
| 70 | switch (event->key.keysym.sym) |
---|
[4622] | 71 | { |
---|
[4636] | 72 | case SDLK_a: |
---|
| 73 | drawMode |= DRAW_ALL; |
---|
[4615] | 74 | break; |
---|
[4638] | 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 | } |
---|
[4622] | 84 | case SDLK_1: |
---|
[4636] | 85 | { |
---|
| 86 | printf("Setting tree depth = 1\n"); |
---|
| 87 | depth = 1; |
---|
| 88 | int temp = drawMode & DRAW_ALL; |
---|
| 89 | drawMode ^= temp; |
---|
| 90 | drawMode |= DRAW_SINGLE; |
---|
[4622] | 91 | break; |
---|
[4636] | 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 | |
---|
[4622] | 166 | } |
---|
| 167 | } |
---|
[4333] | 168 | } |
---|
| 169 | |
---|
[4546] | 170 | |
---|
[4333] | 171 | void Framework::moduleTick(float dt) |
---|
| 172 | { |
---|
| 173 | } |
---|
| 174 | |
---|
[4546] | 175 | |
---|
[4349] | 176 | void Framework::moduleDraw() const |
---|
[4334] | 177 | { |
---|
[4636] | 178 | CDEngine::getInstance()->drawBV(depth, drawMode); |
---|
[4552] | 179 | |
---|
| 180 | LightManager::getInstance()->draw(); |
---|
[4615] | 181 | |
---|
[4622] | 182 | //model->draw(); |
---|
[4334] | 183 | } |
---|
[4333] | 184 | |
---|
[4334] | 185 | |
---|
[4333] | 186 | void Framework::moduleHelp(void) const |
---|
| 187 | { |
---|
[4647] | 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 | |
---|
[4333] | 202 | } |
---|
| 203 | |
---|
[4646] | 204 | int 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 | |
---|
| 219 | int 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 | int 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 | |
---|
[4343] | 250 | void Framework::moduleInitGui(int argc, char** argv) |
---|
[4333] | 251 | { |
---|
[4626] | 252 | Window* guiMainWindow = NULL; |
---|
| 253 | |
---|
| 254 | initGUI(0, NULL); |
---|
| 255 | |
---|
| 256 | guiMainWindow = new Window("Collision_detection"); |
---|
| 257 | { |
---|
[4646] | 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); |
---|
[4626] | 274 | } |
---|
| 275 | Window::mainWindow->showall(); |
---|
| 276 | Window::mainWindow->setSize(300, 500); |
---|
[4333] | 277 | } |
---|