/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Benjamin Grauer co-programmer: ... this file extends the framework file, so it renders what i want. */ #include "framework.h" #include "fields.h" #include "stdlibincl.h" #include "light.h" #include "cd_engine.h" #include "bv_tree.h" #include "md2Model.h" #include "graphics_engine.h" MD2Model* model; int drawMode; int depth; void Framework::moduleInit(int argc, char** argv) { GraphicsEngine::getInstance()->setWindowName("Collision Cluster", "collision"); CDEngine::getInstance(); //CDEngine::getInstance()->debug(); model = new MD2Model("models/tris.md2", "models/tris.pcx"); model->tick(0.1f); // int const length = 6; // sVec3D* vertList = new sVec3D[length]; // 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}}; // // for(int i = 0; i < length; ++i) // { // vertList[i][0] = data[i][0]; // vertList[i][1] = data[i][1]; // vertList[i][2] = data[i][2]; // } CDEngine::getInstance()->debugSpawnTree(9, model->data->pVertices, model->data->numVertices); LightManager* lightMan = LightManager::getInstance(); lightMan->setAmbientColor(.1,.1,.1); lightMan->addLight(); lightMan->setPosition(30, 30, 30); lightMan->addLight(); lightMan->setPosition(-30, -30, -30); drawMode = DRAW_MODEL; depth = 2; printf("\n\n==========================="); printf("Collision Detection Modler:\n"); printf("Key Bindings:\n"); printf(" -| Displaying Polygons\t\t p\n"); printf(" -| Displaying Separation Plane\t s\n"); printf("\n"); printf(" -| Tree Depth 0\t\t 0\n"); printf(" -| Tree Depth 1\t\t 1\n"); printf(" -| Tree Depth 2\t\t 2\n"); printf(" -| Tree Depth 3\t\t 3\n"); printf(" -| Tree Depth 4\t\t 4\n"); printf(" -| Tree Depth 5\t\t 5\n"); printf("===========================\n\n"); } void Framework::moduleEventHandler(SDL_Event* event) { switch (event->type) { case SDL_KEYDOWN: switch (event->key.keysym.sym) { case SDLK_a: drawMode |= DRAW_ALL; break; case SDLK_0: { printf("Setting tree depth = 0\n"); depth = 0; int temp = drawMode & DRAW_ALL; drawMode ^= temp; drawMode |= DRAW_SINGLE; break; } case SDLK_1: { printf("Setting tree depth = 1\n"); depth = 1; int temp = drawMode & DRAW_ALL; drawMode ^= temp; drawMode |= DRAW_SINGLE; break; } case SDLK_2: { printf("Setting tree depth = 2\n"); depth = 2; int temp = drawMode & DRAW_ALL; drawMode ^= temp; drawMode |= DRAW_SINGLE; break; } case SDLK_3: { printf("Setting tree depth = 3\n"); depth = 3; int temp = drawMode & DRAW_ALL; drawMode ^= temp; drawMode |= DRAW_SINGLE; break; } case SDLK_4: { printf("Setting tree depth = 4\n"); depth = 4; int temp = drawMode & DRAW_ALL; drawMode ^= temp; drawMode |= DRAW_SINGLE; break; } case SDLK_5: { printf("Setting tree depth = 5\n"); depth = 5; int temp = drawMode & DRAW_ALL; drawMode ^= temp; drawMode |= DRAW_SINGLE; break; } case SDLK_6: { printf("Setting tree depth = 6\n"); depth = 6; int temp = drawMode & DRAW_ALL; drawMode ^= temp; drawMode |= DRAW_SINGLE; break; } case SDLK_s: if(drawMode & DRAW_SEPARATING_PLANE) { int temp = drawMode & DRAW_SEPARATING_PLANE; drawMode ^= temp; printf("Removing Separation Plane\n"); } else { drawMode |= DRAW_SEPARATING_PLANE; printf("Drawing Separation Plane\n"); } break; case SDLK_p: if(drawMode & DRAW_BV_POLYGON) { int temp = drawMode & DRAW_BV_POLYGON; drawMode ^= temp; printf("Removing OBB Polygons\n"); } else { drawMode |= DRAW_BV_POLYGON; printf("Drawing OBB Polygons\n"); } break; } } } void Framework::moduleTick(float dt) { } void Framework::moduleDraw() const { CDEngine::getInstance()->drawBV(depth, drawMode); LightManager::getInstance()->draw(); //model->draw(); } void Framework::moduleHelp(void) const { PRINT(0)("\n"); PRINT(0)("i - print debug information of Collision-detection\n"); PRINT(0)("\n"); } int boxPolygons(GtkWidget* nonInterest, void* widget) { if(drawMode & DRAW_BV_POLYGON) { int temp = drawMode & DRAW_BV_POLYGON; drawMode ^= temp; printf("Removing OBB Polygons\n"); } else { drawMode |= DRAW_BV_POLYGON; printf("Drawing OBB Polygons\n"); } } int seperatingPlanes(GtkWidget* nonInterest, void* widget) { if(drawMode & DRAW_SEPARATING_PLANE) { int temp = drawMode & DRAW_SEPARATING_PLANE; drawMode ^= temp; printf("Removing Separation Plane\n"); } else { drawMode |= DRAW_SEPARATING_PLANE; printf("Drawing Separation Plane\n"); } } int treeDepth(GtkWidget* nonInterest, void* widget) { Option* option = (Option*) widget; const char* name = option->getTitle(); char* value = option->save(); depth = atoi(value); printf("Setting tree depth = %i\n", depth); int temp = drawMode & DRAW_ALL; drawMode ^= temp; drawMode |= DRAW_SINGLE; delete value; } void Framework::moduleInitGui(int argc, char** argv) { Window* guiMainWindow = NULL; initGUI(0, NULL); guiMainWindow = new Window("Collision_detection"); { Box* windowBox = new Box('v'); { CheckButton* BoxPolygons = new CheckButton("BoxPolygons"); BoxPolygons->connectSignal("clicked", (void*)BoxPolygons, boxPolygons); windowBox->fill(BoxPolygons); CheckButton* SeperatingPlanes = new CheckButton("SeperatingPlanes"); SeperatingPlanes->connectSignal("clicked", (void*)SeperatingPlanes, seperatingPlanes); windowBox->fill(SeperatingPlanes); Slider* TreeDepth = new Slider("TreeDepth", 0, 5); TreeDepth->connectSignal("value_changed", (void*)TreeDepth, treeDepth); windowBox->fill(TreeDepth); } guiMainWindow->fill(windowBox); } Window::mainWindow->showall(); Window::mainWindow->setSize(300, 500); }