From: Peter Schaefer Date: Thu, 23 Apr 2015 16:26:53 +0000 (+0200) Subject: added KeyToggles (Events) X-Git-Url: https://git.leopard-lacewing.eu/?a=commitdiff_plain;h=0c78de55a70d76b34042a354ebbab92d64607f44;p=cgue_weave.git added KeyToggles (Events) BoundingBox will be Drawn (wrong Size and relativ Position) --- diff --git a/Weave/Events.cpp b/Weave/Events.cpp index 00d076c..14baa4a 100644 --- a/Weave/Events.cpp +++ b/Weave/Events.cpp @@ -47,8 +47,10 @@ void Events::processEvents() halt = true; } if (!isKHeld(sdl_event.key.keysym.sym)) + { KeyDown(sdl_event.key.keysym.sym); - + key_toggle[sdl_event.key.keysym.sym] = !key_toggle[sdl_event.key.keysym.sym]; + } key_held[sdl_event.key.keysym.sym] = true; break; case SDL_KEYUP: @@ -110,7 +112,7 @@ void Events::KeyDown(int _key) //MIPMAP QUALITY break; case SDLK_F6: - //??? BLOOM + //??? BoundingBox break; case SDLK_F7: //??? @@ -245,11 +247,17 @@ bool Events::isKHeld(int const _key) { return key_held[_key]; } + bool Events::isMHeld(int const _key) { return mouse_held[_key]; } +bool Events::isKToggleActive(int const _key) +{ + return key_toggle[_key]; +} + int Events::returnSet(int& value, int action2) { @@ -262,6 +270,8 @@ map Events::key_held; map Events::mouse_held; map Events::pad_held; +map Events::key_toggle; + int Events::view_x = 0; int Events::view_y = 0; diff --git a/Weave/Events.h b/Weave/Events.h index b0158f5..905624b 100644 --- a/Weave/Events.h +++ b/Weave/Events.h @@ -30,6 +30,8 @@ public: bool static isKHeld(int const); bool static isMHeld(int const); + bool static isKToggleActive(int const); + private: void static mousemotion(SDL_MouseMotionEvent sdl_motion); @@ -51,6 +53,8 @@ private: map static mouse_held; map static pad_held; + map static key_toggle; + int static view_x; int static view_y; diff --git a/Weave/Game.cpp b/Weave/Game.cpp index a44fbbd..ae0a980 100644 --- a/Weave/Game.cpp +++ b/Weave/Game.cpp @@ -60,6 +60,7 @@ Game::Game() : playing(true) // load LVL tmp_Scene->addObject(new SceneObject(shader1, scale(3.f * vec3(1.f,.3f,1.f)), "level_test.dae", "sample_2D.png")); + tmp_Scene->addObject(new SceneObject(shader1, translate(vec3(0.f,2.f,0.f)), new BBox() , "")); //Player SceneObject* tmp_playerObject = new SceneObject(shader1, translate(vec3(1.f, 0.f, 1.f)), "Player.dae", "model_player_2D.png"); diff --git a/Weave/Graphix/Model/BBox.cpp b/Weave/Graphix/Model/BBox.cpp index af07531..4f28d32 100644 --- a/Weave/Graphix/Model/BBox.cpp +++ b/Weave/Graphix/Model/BBox.cpp @@ -7,8 +7,7 @@ indexS1[8]{0, 4, 1, 5, 2, 6, 3, 7}; BBox::BBox() { - numvertices = 4; - numfaces = 2; + numvertices = 8; float vertex[] { -.5f, -.5f, -.5f, .5f, -.5f, -.5f, .5f, .5f, -.5f, -.5f, .5f, -.5f, -.5f, -.5f, .5f, .5f, -.5f, .5f, .5f, .5f, .5f, -.5f, .5f, .5f }; @@ -27,6 +26,6 @@ void BBox::drawModel() const { glDrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_INT, indexL1); glDrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_INT, indexL2); - glDrawElements(GL_LINE_STRIP, 8, GL_UNSIGNED_INT, indexS1); + glDrawElements(GL_LINES, 8, GL_UNSIGNED_INT, indexS1); glBindVertexArray(0); } \ No newline at end of file diff --git a/Weave/Graphix/Model/Model.cpp b/Weave/Graphix/Model/Model.cpp index 408d571..e7addf9 100644 --- a/Weave/Graphix/Model/Model.cpp +++ b/Weave/Graphix/Model/Model.cpp @@ -8,6 +8,10 @@ #include "../Graphix.h" +#include "BBox.h" + +#include "../../Events.h" + Model::Model() : numfaces(0), numvertices(0), @@ -70,18 +74,23 @@ void Model::bindShader(Shader* _shader) void Model::drawModel() const { - glDrawElements(GL_TRIANGLES, numfaces * 3, GL_UNSIGNED_INT, 0); + if(Events::isKToggleActive(SDLK_F3)) + glDrawElements(GL_LINE_LOOP, numfaces * 3, GL_UNSIGNED_INT, 0); + else + glDrawElements(GL_TRIANGLES, numfaces * 3, GL_UNSIGNED_INT, 0); glBindVertexArray(0); } void Model::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const { + bool wireframe = Events::isKToggleActive(SDLK_F3); //Message::info("Error from before?"); //Graphix::getGlError(); useModel(_shader); //Message::info("IMesh loading Coordinates"); //Graphix::getGlError(); - useTexture(_texture, _shader); + if (!wireframe) + useTexture(_texture, _shader); //Message::info("IMesh loading Texture"); //Graphix::getGlError(); useModelMat(_modelMat, _shader); @@ -93,9 +102,19 @@ void Model::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) //system("pause"); } -void Model::drawBBox() const +void Model::drawBBox(Shader* _shader,const mat4& _modelMat) const { - + if (BoundingBox==nullptr) + { + exBBox = true; + BoundingBox = new BBox(); +// BBoxShader = new Shader("basic_FS.hlsl", "basic_VS.hlsl"); +// BoundingBox->bindShader(BBoxShader); + + + } + BoundingBox->bindShader(_shader); + BoundingBox->drawModel(_shader, (Texture*)nullptr, _modelMat); } void Model::updateBB(const vec3& _min, const vec3& _max) @@ -161,3 +180,7 @@ void Model::useModelMat(const mat4& _model, Shader* _shader) const if (tmp >= 0) glUniformMatrix4fv(tmp, 1, GL_FALSE, value_ptr(_model)); } + +Model* Model::BoundingBox = nullptr; +Shader* Model::BBoxShader = nullptr; +bool Model::exBBox = false; \ No newline at end of file diff --git a/Weave/Graphix/Model/Model.h b/Weave/Graphix/Model/Model.h index 19b7a93..6b901c4 100644 --- a/Weave/Graphix/Model/Model.h +++ b/Weave/Graphix/Model/Model.h @@ -21,7 +21,7 @@ public: virtual void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const; /* Draws a BoundingBox around the Model */ - virtual void drawBBox() const; + virtual void drawBBox(Shader* shader,const mat4 & modelMat) const; protected: uint numvertices, numfaces; @@ -39,6 +39,10 @@ protected: virtual void useModelMat(const mat4& model, Shader* shader) const; virtual void drawModel() const; + static Model* BoundingBox; + static Shader* BBoxShader; + static bool exBBox; + private: vec3 BBsize, BBposition; diff --git a/Weave/Graphix/Model/SkyBox.cpp b/Weave/Graphix/Model/SkyBox.cpp index 7cb2708..9c37e0c 100644 --- a/Weave/Graphix/Model/SkyBox.cpp +++ b/Weave/Graphix/Model/SkyBox.cpp @@ -34,11 +34,13 @@ void SkyBox::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat void SkyBox::useModelMat(const mat4& _model, Shader* _shader) const { - } void SkyBox::useTexture(Texture* _texture, Shader* _shader) const { +} +void SkyBox::drawBBox(Shader* _shader, const mat4& _modelMat) const +{ } diff --git a/Weave/Graphix/Model/SkyBox.h b/Weave/Graphix/Model/SkyBox.h index be5e88b..5bf1552 100644 --- a/Weave/Graphix/Model/SkyBox.h +++ b/Weave/Graphix/Model/SkyBox.h @@ -15,5 +15,7 @@ public: void useModelMat(const mat4& model, Shader* shader) const; void useTexture(Texture* texture, Shader* shader) const; + void drawBBox(Shader* shader, const mat4& modelMat) const; + }; diff --git a/Weave/Graphix/SceneObject.cpp b/Weave/Graphix/SceneObject.cpp index 8201e5f..7f153ef 100644 --- a/Weave/Graphix/SceneObject.cpp +++ b/Weave/Graphix/SceneObject.cpp @@ -16,6 +16,8 @@ #include "Graphix.h" +#include "../Events.h" + using std::string; using std::cout; @@ -117,6 +119,8 @@ void SceneObject::draw() const // drawModel(); model->drawModel(shader, texture, modelMat); + if (Events::isKToggleActive(SDLK_F6)) + model->drawBBox(shader, modelMat); } void SceneObject::collisions(SceneObject* _other)