]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
added KeyToggles (Events)
authorPeter Schaefer <schaeferpm@gmail.com>
Thu, 23 Apr 2015 16:26:53 +0000 (18:26 +0200)
committerPeter Schaefer <schaeferpm@gmail.com>
Thu, 23 Apr 2015 16:26:53 +0000 (18:26 +0200)
BoundingBox will be Drawn (wrong Size and relativ Position)

Weave/Events.cpp
Weave/Events.h
Weave/Game.cpp
Weave/Graphix/Model/BBox.cpp
Weave/Graphix/Model/Model.cpp
Weave/Graphix/Model/Model.h
Weave/Graphix/Model/SkyBox.cpp
Weave/Graphix/Model/SkyBox.h
Weave/Graphix/SceneObject.cpp

index 00d076cef3d043207757b32c24099de2f09b1d27..14baa4ad3a47fd27dbb6ab686649edf9562e263e 100644 (file)
@@ -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<int, bool> Events::key_held;
 map<int, bool> Events::mouse_held;
 map<int, bool> Events::pad_held;
 
+map<int, bool> Events::key_toggle;
+
 int Events::view_x = 0;
 int Events::view_y = 0;
 
index b0158f53b342b80cbfb85c123219ce315266265b..905624bfd64bab07cb27e9bd7cb9cdbe2c4f7331 100644 (file)
@@ -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<int, bool> static mouse_held;
        map<int, bool> static pad_held;
 
+       map<int, bool> static key_toggle;
+
        int static view_x;
        int static view_y;
 
index a44fbbde80cca03c466b6f5951292d77d8c81e02..ae0a98047d292d28b25400900d658c33453e21af 100644 (file)
@@ -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");
index af07531c73fef9fe58a447324e6a51be04986298..4f28d328ee891e3218afcd70a53c026908190072 100644 (file)
@@ -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
index 408d571733f9eaabce265731e49f4cc7f3a06ade..e7addf9a760eacdae2bc91d7b1a972cb25dfa8ab 100644 (file)
@@ -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
index 19b7a93e0ec1ee569da27bf31276d09431a614a3..6b901c4fba99a407c2da07058c416afd98b87596 100644 (file)
@@ -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;
 
index 7cb27086922ea9bf96e591b4cb9c5e85c5cff3c4..9c37e0c8861c5c0dd5538ec61a8ba7c625fed0da 100644 (file)
@@ -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
+{
 }
 
index be5e88b3e477454886a3d1018c42987bc77a8908..5bf15525a5d63c50ed73324a056a2d5de6ae2264 100644 (file)
@@ -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;
+
 };
 
index 8201e5f1ecb68723ea2fcf4dbd0b1add4f8be6f5..7f153ef1c23cef21423aadaea1a0cc4881007460 100644 (file)
@@ -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)