From: Peter Schaefer Date: Sun, 3 May 2015 19:47:35 +0000 (+0200) Subject: new function removeNormalize X-Git-Url: https://git.leopard-lacewing.eu/?a=commitdiff_plain;h=68e76e302fa22961e1c7ef39580dc492c345c889;p=cgue_weave.git new function removeNormalize new Scene HEADER new EventBox --- diff --git a/Weave/Game.cpp b/Weave/Game.cpp index 7cc1437..b899a6a 100644 --- a/Weave/Game.cpp +++ b/Weave/Game.cpp @@ -10,10 +10,8 @@ #include #include -#include "Scene\Scene.h" -#include "Scene\SceneObject.h" -#include "Scene\Marvin.h" +#include "Scene.h" #include "Graphix\Shader.h" #include "Graphix\Graphix.h" @@ -69,6 +67,8 @@ Game::Game() : playing(true) //current_world->addObject(new SceneObject(shader1, translate(vec3(-3.f, .4f, 0.f))*scale(vec3(3.f)), "cow/cow.dae", "model_cow_2D.jpg")); current_world->addObject(new SceneObject(shader1, translate(vec3(-3.f, .4f, 0.f)), vec4(3.0f, 0.5f, 0.4f, 1.5f), "duck.dae", "model_duck_2D.png", vec3(.3f))); + current_world->addObject(new EventBox(translate(vec3(3.f, .4f, 0.f)), vec3(1.f))); + } diff --git a/Weave/Graphix/GLM.cpp b/Weave/Graphix/GLM.cpp index 801f0aa..59c1c85 100644 --- a/Weave/Graphix/GLM.cpp +++ b/Weave/Graphix/GLM.cpp @@ -5,8 +5,14 @@ float VektorAbs(const vec3& vek) return sqrt(vek.x*vek.x + vek.y*vek.y + vek.z*vek.z); } -mat4 removeScale(const mat4& _mat) + +mat4 removeScale(const mat4& matrix) { - return _mat*(mat4)inverse(transpose((mat3)_mat)*(mat3)_mat); -} + mat3 scalingM = transpose((mat3)matrix) * (mat3)matrix; + vec3 scalingV; + for (int i = 0; i < 3; ++i) + scalingV[i] = 1.f / sqrt(scalingM[i][i]); + + return matrix * scale(scalingV); +} diff --git a/Weave/Graphix/GLM.h b/Weave/Graphix/GLM.h index 2f3e470..35c208a 100644 --- a/Weave/Graphix/GLM.h +++ b/Weave/Graphix/GLM.h @@ -14,6 +14,7 @@ using glm::vec4; using glm::translate; using glm::rotate; //using glm::scale; +using glm::determinant; using glm::perspective; using glm::normalize; using glm::inverse; @@ -39,6 +40,5 @@ using glm::max; __declspec(deprecated) float VektorAbs(const vec3& vek); -mat4 removeScale(const mat4& mat); +mat4 removeScale(const mat4& matrix); -//#include "matM.h" diff --git a/Weave/Graphix/Model/BBox.cpp b/Weave/Graphix/Model/BBox.cpp index 99dba6d..796866f 100644 --- a/Weave/Graphix/Model/BBox.cpp +++ b/Weave/Graphix/Model/BBox.cpp @@ -17,7 +17,6 @@ BBox::BBox() } - BBox::~BBox() { } @@ -33,4 +32,4 @@ void BBox::drawModel() const glDrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_INT, indexL2); 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 5973b83..8e9fd77 100644 --- a/Weave/Graphix/Model/Model.cpp +++ b/Weave/Graphix/Model/Model.cpp @@ -325,6 +325,16 @@ void Model::scaleVec3(vec3& _vec, const vec3& _scale) _vec[i] *= _scale[i]; } +Model* Model::getBBoxModel() +{ + if (BoundingBox == nullptr) + { + BoundingBox = new BBox(); + BoundingBox->bindShader(Graphix::shader_BBox); + } + return BoundingBox; +} + 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 fec1a11..be8a302 100644 --- a/Weave/Graphix/Model/Model.h +++ b/Weave/Graphix/Model/Model.h @@ -34,6 +34,8 @@ public: virtual void scale(const vec3& scale); virtual void unScale(); + static Model* getBBoxModel(); + protected: uint numvertices, numfaces; uint vertexBuffer, indexBuffer, normalBuffer, uvBuffer; diff --git a/Weave/Scene.h b/Weave/Scene.h new file mode 100644 index 0000000..5405d0b --- /dev/null +++ b/Weave/Scene.h @@ -0,0 +1,8 @@ +#pragma once + +#include "Scene/Scene.h" +#include "Scene/SceneObject.h" +#include "Scene/EventBox.h" +#include "Scene/Marvin.h" +#include "Scene/Sky.h" + diff --git a/Weave/Scene/EventBox.cpp b/Weave/Scene/EventBox.cpp new file mode 100644 index 0000000..71ed690 --- /dev/null +++ b/Weave/Scene/EventBox.cpp @@ -0,0 +1,27 @@ +#include "EventBox.h" + +#include "../Graphix/Graphix.h" +#include "../Graphix/Model.h" + +#include "../Events.h" + + +EventBox::EventBox(const mat4& _modelMat, const vec3& _size) : SceneObject(Graphix::shader_BBox,_modelMat,vec4(0.f),Model::getBBoxModel(),"",_size) +{ + +} + + +EventBox::~EventBox() +{ +} + +void EventBox::update(float _deltaT) +{ +} + +void EventBox::draw() const +{ + if (Events::isKToggleActive(SDLK_F6)) + model->drawBBox(shader, modelMat); +} \ No newline at end of file diff --git a/Weave/Scene/EventBox.h b/Weave/Scene/EventBox.h new file mode 100644 index 0000000..ced8388 --- /dev/null +++ b/Weave/Scene/EventBox.h @@ -0,0 +1,18 @@ +#pragma once +#include "SceneObject.h" + + +#define EB_WINZONE 1; +#define EB_LOSTZONE 0; + +class EventBox : + public SceneObject +{ +public: + EventBox(const mat4& modelMat, const vec3& size); + ~EventBox(); + + virtual void update(float); + virtual void draw() const; +}; + diff --git a/Weave/Scene/SceneObject.cpp b/Weave/Scene/SceneObject.cpp index 3cfd3f8..4e84a88 100644 --- a/Weave/Scene/SceneObject.cpp +++ b/Weave/Scene/SceneObject.cpp @@ -29,7 +29,8 @@ collision_ignore(false), texture(nullptr), ySpeed(0), yStatic(true), -ignore(false) +ignore(false), +modelScale(_scale) { //Message::info("Error from befor?"); //Graphix::getGlError(); @@ -55,7 +56,7 @@ ignore(false) } -SceneObject::SceneObject(Shader* _shader, const mat4& _modelMat, const vec4& _material, Model* _model, string texturepath) : +SceneObject::SceneObject(Shader* _shader, const mat4& _modelMat, const vec4& _material, Model* _model, string texturepath, const vec3& _scale) : model(_model), modelMat(_modelMat), shader(_shader), @@ -64,7 +65,8 @@ collision_ignore(false), texture(nullptr), ySpeed(0), yStatic(true), -ignore(false) +ignore(false), +modelScale(_scale) { //Message::info("Error from befor?"); //Graphix::getGlError(); @@ -84,22 +86,6 @@ ignore(false) } -//SceneObject::SceneObject(Shader* _shader, mat4& _modelMat, IMesh* model_obj, string texturepath) : -//IMesh(*model_obj), -//modelMat(_modelMat), -//shader(_shader), -//mainScene(NULL), -//collision_ignore(false), -//texture(nullptr) -//{ -// modelID = _shader->getUniformLocation("modelMat"); -// if (texturepath != "") -// texture = new Texture(texturepath); -// -// bindShader(shader); -//} - - SceneObject::~SceneObject() { // delete texture; diff --git a/Weave/Scene/SceneObject.h b/Weave/Scene/SceneObject.h index 4fb127c..f3dde27 100644 --- a/Weave/Scene/SceneObject.h +++ b/Weave/Scene/SceneObject.h @@ -18,8 +18,8 @@ class SceneObject public: //SceneObject(Shader* _shader, mat4& model); - SceneObject(Shader* _shader, const mat4& model, const vec4& material, string modelpath, string texturepath, const vec3& scale=vec3(1.f)); - SceneObject(Shader* _shader, const mat4& modelMat, const vec4& material, Model* model, string texturepath); + SceneObject(Shader* _shader, const mat4& modelMat, const vec4& material, string modelpath, string texturepath, const vec3& scale=vec3(1.f)); + SceneObject(Shader* _shader, const mat4& modelMat, const vec4& material, Model* model, string texturepath, const vec3& scale = vec3(1.f)); virtual ~SceneObject(); @@ -63,9 +63,9 @@ public: protected: - - mat4 modelMat; + vec3 modelScale; + Shader* shader; Texture* texture; Model* model; @@ -74,9 +74,5 @@ protected: bool collision_ignore; - - Shader* shader_BBox; - - }; diff --git a/Weave/Weave.vcxproj b/Weave/Weave.vcxproj index 1e07713..6ca484d 100644 --- a/Weave/Weave.vcxproj +++ b/Weave/Weave.vcxproj @@ -100,6 +100,7 @@ + @@ -123,6 +124,8 @@ + + diff --git a/Weave/Weave.vcxproj.filters b/Weave/Weave.vcxproj.filters index 606740a..10ea336 100644 --- a/Weave/Weave.vcxproj.filters +++ b/Weave/Weave.vcxproj.filters @@ -72,6 +72,9 @@ Source Files + + Source Files + @@ -134,5 +137,11 @@ Header Files + + Header Files + + + Header Files + \ No newline at end of file diff --git a/Weave/main.cpp b/Weave/main.cpp index da01542..4f84b32 100644 --- a/Weave/main.cpp +++ b/Weave/main.cpp @@ -2,7 +2,7 @@ #include #include -//#include "Graphix\GLM.h" +#include "Graphix\GLM.h" //#include //glew32.dll @@ -41,6 +41,7 @@ void logSDLerror(ostream &os, const char *msg) int main(int argc, char *argv[]) { + Graphix::init(); Game spiel1;