]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
added collision detection on outer BBox
authorPeter Schaefer <schaeferpm@gmail.com>
Wed, 29 Apr 2015 08:35:41 +0000 (10:35 +0200)
committerPeter Schaefer <schaeferpm@gmail.com>
Wed, 29 Apr 2015 08:35:41 +0000 (10:35 +0200)
isOverlapping & isInside

Weave/Graphix/GLM.h
Weave/Graphix/Model/IMetaMesh.cpp
Weave/Graphix/Model/Model.h
Weave/Scene/Scene.cpp
Weave/Scene/Scene.h
Weave/Scene/SceneObject.cpp
Weave/Scene/SceneObject.h

index 4c95c5e1daf424a3f480a911ec141b4fda69e589..34f0073680f6e1802f79b8319d93e75ef3da683f 100644 (file)
@@ -32,7 +32,7 @@ using glm::sign;
 #define M_2_PI      0.636619772367581343075535053490057448  /* 2/pi */
 #define M_D_R       57.2957795131                                                      /* 180/pi */
 
-
+__declspec(deprecated)
 float VektorAbs(const vec3& vek);
 
 //#include "matM.h"
index 9ef7481fcbc115a043371e46baa2881c64d1c86a..d9a05d4ee2d0b6420fa14bb6af2d51436a86baed 100644 (file)
@@ -34,14 +34,12 @@ IMetaMesh::IMetaMesh(const string& _modelpath)
                IMesh* tmpIMesh = new IMesh(scene->mMeshes[0], tmpModelMat);
                models.push_back(tmpIMesh);
                tmpIMesh->getBBmm(BBmin, BBmax);
-
+               
                for (uint i = 1; i < scene->mNumMeshes; i++)
                {
-                       //delete tmpIMesh;
                        aimat = &(root->mChildren[i]->mTransformation);
 
                        tmpModelMat = mat4(aimat->a1, aimat->c1, -aimat->b1, aimat->d1, aimat->a2, aimat->c2, -aimat->b2, aimat->d2, aimat->a3, aimat->c3, -aimat->b3, aimat->d3, aimat->a4, aimat->c4, -aimat->b4, aimat->d4);
-
                        tmpIMesh = new IMesh(scene->mMeshes[i], tmpModelMat);
                        models.push_back(tmpIMesh);
                        tmpIMesh->getBBmm(tmpMin, tmpMax);
@@ -53,7 +51,6 @@ IMetaMesh::IMetaMesh(const string& _modelpath)
                                        BBmax[j] = tmpMax[j];
                        }
                }
-               //delete tmpIMesh;
                updateBB(BBmin, BBmax);
        }
        else
@@ -61,7 +58,6 @@ IMetaMesh::IMetaMesh(const string& _modelpath)
                Message::error("The file " + _modelpath + " doesn't contain any nodes.");
                return;
        }
-
 }
 
 IMetaMesh::~IMetaMesh()
index 9a83e9318ed017d6c166c23e5ac00c9d69b08a3a..9336b8c67d66cb7291718d0e61ce3bd727c515b5 100644 (file)
@@ -23,7 +23,9 @@ public:
        /* Draws a BoundingBox around the Model */
        virtual void drawBBox(Shader* shader, const mat4& modelMat) const;
 
+       /* Get min&max from BBox */
        void getBBmm(vec3& min, vec3& max) const;
+       /* Get size&position from BBox */
        void getBBsp(vec3& size, vec3& pos) const;
 
 protected:
index 2f6f36240a4f6d0045f8d094a0638a103304049a..a710152d20f921e8a2b9d88eae34ad76b7cd7b7e 100644 (file)
@@ -25,13 +25,11 @@ using std::set;
 
 
 Scene::Scene(unsigned int x, unsigned int y, unsigned int width, unsigned int height, float fovy, float zNear, float zFar, vec3 pos, SceneObject* _lookat) :
-viewPort(new ViewPort(x, y, width, height, fovy, zNear, zFar)),
+viewPort(x, y, width, height, fovy, zNear, zFar),
 lookat(_lookat),
-move_delta(0),
-SkyBox(new Sky())
+move_delta(0)
 {
 
-
 }
 
 
@@ -46,8 +44,10 @@ Scene::~Scene()
 
 
 
-       if (viewPort != nullptr)
-               delete viewPort;
+       //if (viewPort != nullptr)
+       //      delete viewPort;
+       //if (SkyBox != nullptr)
+       //      delete SkyBox;
 }
 
 
@@ -68,7 +68,7 @@ void Scene::update(float deltaT)
        //int reset = Events::getAction2();
 
        // XYAchse um den Player
-       viewPort->rotateView(0.002f*Events::getViewX(), 0.001f*Events::getViewY());
+       viewPort.rotateView(0.002f*Events::getViewX(), 0.001f*Events::getViewY());
 
        //Jump
        if (Events::getJump() && lookat->floorBound())
@@ -78,7 +78,7 @@ void Scene::update(float deltaT)
 
        // MOVE Player
        if (move_x)
-               lookat->move(SPEED_MOVE_NORMAL *move_x * deltaT * viewPort->rotateDirection(vec3(-1.f, 0.f, 0.f)));
+               lookat->move(SPEED_MOVE_NORMAL *move_x * deltaT * viewPort.rotateDirection(vec3(-1.f, 0.f, 0.f)));
 
        if (move_y){
                if (move_y > 0){
@@ -86,10 +86,10 @@ void Scene::update(float deltaT)
                                move_delta += deltaT;
                        if (move_delta > TIME_TILL_MAX_MOVE)
                                move_delta = TIME_TILL_MAX_MOVE;
-                       lookat->move(SPEED_MOVE_NORMAL * (MOVE_FASTER * move_delta / TIME_TILL_MAX_MOVE + 1) *move_y * deltaT * viewPort->rotateDirection(vec3(0.f, 0.f, -1.f)));
+                       lookat->move(SPEED_MOVE_NORMAL * (MOVE_FASTER * move_delta / TIME_TILL_MAX_MOVE + 1) *move_y * deltaT * viewPort.rotateDirection(vec3(0.f, 0.f, -1.f)));
                }
                else
-                       lookat->move(SPEED_MOVE_NORMAL *move_y * deltaT * viewPort->rotateDirection(vec3(0.f, 0.f, -1.f)));
+                       lookat->move(SPEED_MOVE_NORMAL *move_y * deltaT * viewPort.rotateDirection(vec3(0.f, 0.f, -1.f)));
        }
        else
        {
@@ -99,7 +99,7 @@ void Scene::update(float deltaT)
        //Rotate Play in move direction
 
        if (move_x || move_y)
-               lookat->turnTo(viewPort->rotateDirection(vec3(0.f, 0.f, -1.f)), 3 * deltaT / TIME_TILL_DIRECTION_ROTATE);
+               lookat->turnTo(viewPort.rotateDirection(vec3(0.f, 0.f, -1.f)), 3 * deltaT / TIME_TILL_DIRECTION_ROTATE);
 
 
        //// Zoom auf Player
@@ -136,30 +136,19 @@ void Scene::update(float deltaT)
 
 void Scene::draw() const
 {
-       viewPort->useViewPort();
+       viewPort.useViewPort();
 
        //Skybox
-       viewPort->bindView(SkyBox->getShader(), lookat->getPosition() + vec3(0.0f, 1.0f, 0.0f));
+       viewPort.bindView(SkyBox.getShader(), lookat->getPosition() + vec3(0.0f, 1.0f, 0.0f));
        //BBox
-       viewPort->bindView(Graphix::shader_BBox, lookat->getPosition() + vec3(0.0f, 1.0f, 0.0f));
+       viewPort.bindView(Graphix::shader_BBox, lookat->getPosition() + vec3(0.0f, 1.0f, 0.0f));
 
        for (auto i = ShaderSet.cbegin(); i != ShaderSet.cend(); ++i)
        {
-               viewPort->bindView(*i, lookat->getPosition() + vec3(0.0f, 1.0f, 0.0f));
-
-               //don't know if this is really the right place to set the lighting
-               //add ambient light
-               //GLfloat ambientcolor[] = { 0.5f, 0.5f, 0.5f, 1.0f };
-               //glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientcolor);
-
-               //add positioned light
-               //GLfloat lightcolor0[] = { 1.5f, 1.5f, 1.5f, 1.0f };
-               //GLfloat lightposition0[] = { 1.0f, 1.0f, 1.0f, 1.0f };
-               //glLightfv(GL_LIGHT0, GL_DIFFUSE, lightcolor0);
-               //glLightfv(GL_LIGHT0, GL_POSITION, lightposition0);
+               viewPort.bindView(*i, lookat->getPosition() + vec3(0.0f, 1.0f, 0.0f));
        }
 
-       SkyBox->draw();
+       SkyBox.draw();
 
        for (auto i = SceneObjects.cbegin(); i != SceneObjects.cend(); ++i)
        {
index 41c29e9978d4fa4e60c226ddbd612efc5bce0e63..ae2402c1a5e19ef72da9e434f8cd72db2f1c934c 100644 (file)
@@ -2,11 +2,15 @@
 
 #include "../Graphix/GLM.h"
 
+#include "../Graphix/ViewPort.h"
+#include "Sky.h"
+
 #include <list>
 #include <set>
 
 class SceneObject;
 class ViewPort;
+class Sky;
 class Shader;
 
 class Scene
@@ -28,14 +32,13 @@ public:
        void setLookAt(SceneObject* _lookat);
 
 protected:
-       ViewPort* viewPort;
+       ViewPort viewPort;
+       Sky SkyBox;
        SceneObject* lookat;
 
        std::list<SceneObject*> SceneObjects;
        std::set<Shader*> ShaderSet;
 
-       SceneObject* SkyBox;
-
        float move_delta;
 
 };
index 51f8b1438e223ef50368f57d9507aa286774dfdf..8b4c5d93043e6a0d2a26d88768ec241c101ac34e 100644 (file)
@@ -21,7 +21,7 @@ using std::string;
 #define YFALL_SPEED 9.8f
 
 SceneObject::SceneObject(Shader* _shader, const mat4& _modelMat, const vec4& _material, string _modelpath, string texturepath, unsigned int _model_index) :
-model(new IMetaMesh(_modelpath)),
+model(nullptr),
 modelMat(_modelMat),
 material(_material),
 shader(_shader),
@@ -37,6 +37,9 @@ yStatic(true)
        //Message::info("Creating modelMat");
        //Graphix::getGlError();
        //modelID = _shader->getUniformLocation("modelMat");
+       if (_modelpath != "")
+               model = new IMetaMesh(_modelpath);
+
        if (texturepath != "")
                texture = new Texture(texturepath);
        //Message::info("Creating SkyBox Shader");
@@ -152,6 +155,35 @@ void SceneObject::collisions(SceneObject* _other)
        if (collision_ignore || _other->collision_ignore)
                return;
 
+       vec3 posA, sizeA, posB, sizeB;
+
+       model->getBBsp(sizeA, posA);
+       _other->model->getBBsp(sizeB, posB);
+
+       vec3 pDist, sDist;
+       vec3 overlap, inside;
+       int isOverlaping, isInside;
+
+       sizeA /= 2;
+       sizeB /= 2;
+
+       pDist = posB - posA;
+       pDist *= sign(pDist);
+
+       sDist = sizeB - sizeA;
+       sDist *= sign(sDist);
+       
+       overlap =(sizeA + sizeB) - pDist;
+       inside = sDist - pDist;
+
+
+       /* overlapping 1 yes, 0 touch, -1 no*/
+       isOverlaping = sign(glm::min(glm::min(overlap.x, overlap.y), overlap.z));
+       /* inside 1 yes, 0 touch, -1 no*/
+       isInside = sign(glm::min(glm::min(inside.x, inside.y), inside.z));
+
+
+
 }
 
 bool SceneObject::floorBound() const
@@ -225,7 +257,7 @@ void SceneObject::setMainScene(Scene* _scene)
 }
 
 
-Shader* SceneObject::getShader()
+Shader* SceneObject::getShader() const
 {
        return shader;
 }
index 5014fbe38c838954688866f9e280a7b8cb669730..8e221e663632a9c7729ab186af3facbdb87a137f 100644 (file)
@@ -45,7 +45,7 @@ public:
 
        void setCollision(bool);
 
-       Shader* getShader();
+       Shader* getShader() const;
 
        __declspec(deprecated)
        void setEnemy(bool isenemy);