]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
moved Collision Mesh into SceneObject
authorPeter Schaefer <schaeferpm@gmail.com>
Wed, 30 Mar 2016 10:57:16 +0000 (12:57 +0200)
committerPeter Schaefer <schaeferpm@gmail.com>
Wed, 30 Mar 2016 10:57:16 +0000 (12:57 +0200)
badhack use Same Mesh for collision

19 files changed:
Weave/GLM.cpp
Weave/GLM.h
Weave/Graphix/Model/BBox.cpp
Weave/Graphix/Model/BBox.h
Weave/Graphix/Model/IAnimMesh.cpp
Weave/Graphix/Model/IMesh.cpp
Weave/Graphix/Model/IMesh.h
Weave/Graphix/Model/IMetaMesh.cpp
Weave/Graphix/Model/IMetaMesh.h
Weave/Graphix/Model/Model.cpp
Weave/Graphix/Model/Model.h
Weave/Graphix/Model/SkyBox.cpp
Weave/Graphix/Model/SkyBox.h
Weave/Scene/EventBox.cpp
Weave/Scene/Level.cpp
Weave/Scene/SceneObject.cpp
Weave/Scene/SceneObject.h
Weave/Weave.vcxproj
Weave/Weave.vcxproj.filters

index 170257e5f32b916f652a81c56b93e3049f5a8846..bd2203655e5b01926bb684734498b3486795081f 100644 (file)
@@ -105,3 +105,12 @@ void scaleVec3(vec3& _vec, const vec3& _scale)
                _vec[i] *= _scale[i];
 }
 
+//#include <assimp/Importer.hpp>
+#include <assimp/scene.h>
+//#include <assimp/postprocess.h>
+
+mat4 aiMat2mat4(const aiMatrix4x4 * aimat)
+{
+       return 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);
+}
+
index 45c9f19f4df47e59e2d753d44389ca1e7ca3deca..5617289ada67572419ba41aa572ee08c21be3d21 100644 (file)
@@ -31,6 +31,11 @@ using glm::sign;
 using glm::min;
 using glm::max;
 
+//#include <assimp/scene.h>
+template<typename TReal>
+class aiMatrix4x4t;
+typedef aiMatrix4x4t<float> aiMatrix4x4;
+
 #define M_PI        3.14159265358979323846264338327950288   /* pi */
 #define M_PI_2      1.57079632679489661923132169163975144   /* pi/2 */
 #define M_PI_4      0.785398163397448309615660845819875721  /* pi/4 */
@@ -52,3 +57,5 @@ void updateVec3MinMax(vec3& updMin, vec3& updMax, const vec3& inpMin, const vec3
 
 void scaleVec3(vec3& _vec, const vec3& _scale);
 
+
+mat4 aiMat2mat4(const aiMatrix4x4*);
\ No newline at end of file
index 5de0e97bc063300df3505ab92cb66943269d983e..6d6646ee99949493320aae8aff59a8626c3f16f6 100644 (file)
@@ -13,11 +13,10 @@ BBox::BBox()
        //import("skybox.dae", numvertices, numfaces, vertex, uvs, normals, index, 0);\r
 \r
        bindModel();\r
+       bt_init();\r
 \r
        name = "BBox";\r
 \r
-       bt_collision_shape = new btBoxShape(btVector3(.5f,.5f,.5f));\r
-\r
 }\r
 \r
 BBox::~BBox()\r
@@ -39,6 +38,12 @@ void BBox::drawModel() const
        glBindVertexArray(0);\r
 }\r
 \r
+void BBox::bt_init(bool isConvex)\r
+{\r
+       if(bt_collision_shape==nullptr)\r
+               bt_collision_shape = new btBoxShape(btVector3(.5f, .5f, .5f));\r
+}\r
+\r
 \r
 std::string BBox::type2str() const\r
 {\r
index 3d99b2ddb5884612d41ea5711b9c9c4331939926..3f68bd52c47188d5d0913f342739c53a61f7a1ce 100644 (file)
@@ -11,6 +11,8 @@ public:
 \r
        void drawModel() const override;\r
 \r
+       void bt_init(bool isConvex = true) override;\r
+\r
        std::string type2str() const override;\r
 };\r
 \r
index 7a513ebf8efd9c12c92824aaa85ca8fa10c04028..2e818c8b897629ecfe1f60022adcad16a679a636 100644 (file)
@@ -1,6 +1,6 @@
 #include "IAnimMesh.h"
 
-IAnimMesh::IAnimMesh(const aiMesh* mesh, const vec3& scale, bool isConvex) : IMesh(mesh, scale, isConvex)
+IAnimMesh::IAnimMesh(const aiMesh* mesh, const vec3& scale, bool isConvex) : IMesh(mesh, scale)
 {
 
 }
index f9b04a3071f14b3d0d9eda01de604f9056278c39..65f61466c5c91cbd419ba3e7a040d13a5d9a75cd 100644 (file)
@@ -39,28 +39,12 @@ using std::array;
 //\r
 //}\r
 \r
-IMesh::IMesh(const aiMesh* _mesh, const vec3& _scale, bool _isConvex) : modelpath("IMesh")\r
+IMesh::IMesh(const aiMesh* _mesh, const vec3& _scale) : modelpath("IMesh")\r
 {\r
        loadMesh(_mesh, numvertices, numfaces, vertex, uvs, normals, index, name, _scale);\r
-       btTriangleIndexVertexArray* meshInterface = new btTriangleIndexVertexArray();\r
-       btIndexedMesh part;\r
-       part.m_vertexBase = (const unsigned char*)vertex;\r
-       part.m_vertexStride = sizeof(float) * 3;\r
-       part.m_numVertices = numvertices;\r
-       part.m_triangleIndexBase = (const unsigned char*)index;\r
-       part.m_triangleIndexStride = sizeof(uint) * 3;\r
-       part.m_numTriangles = numfaces;\r
-       part.m_indexType = PHY_INTEGER;\r
-       meshInterface->addIndexedMesh(part, PHY_INTEGER);\r
-\r
-       if (_isConvex)\r
-               bt_collision_shape = new btConvexTriangleMeshShape(meshInterface, true);\r
-       else\r
-               bt_collision_shape = new btBvhTriangleMeshShape(meshInterface, true);\r
 \r
        bindModel();\r
 \r
-\r
 }\r
 \r
 IMesh::~IMesh()\r
@@ -78,10 +62,10 @@ IMesh::~IMesh()
 //}\r
 \r
 \r
-void IMesh::drawBBox(const mat4& _modelMat, const vec4& _color) const\r
-{\r
-       Model::drawBBox(_modelMat, _color);\r
-}\r
+//void IMesh::drawBBox(const mat4& _modelMat, const vec4& _color) const\r
+//{\r
+//     Model::drawBBox(_modelMat, _color);\r
+//}\r
 \r
 \r
 string IMesh::type2str() const\r
index e3c44019a12c8a0b4ae35321f3a96054ada23d55..6a4fd2437904bf69800a33f515be393b8c8c5f61 100644 (file)
@@ -3,7 +3,6 @@
 #include <string>\r
 #include <list>\r
 #include "../../GLM.h"\r
-#include "../../Overlap.h"\r
 \r
 #include "Model.h"\r
 \r
@@ -16,13 +15,13 @@ public:
 //     class Node;\r
 \r
 //     IMesh(const std::string& modelpath, uint index=0);\r
-       IMesh(const aiMesh* mesh, const vec3& scale = vec3(1.f), bool isConvex=true);\r
+       IMesh(const aiMesh* mesh, const vec3& scale = vec3(1.f));\r
 \r
        virtual ~IMesh();\r
 \r
        //void useModelMat(const mat4& model, Shader* shader) const override;\r
 \r
-       void drawBBox(const mat4& modelMat, const vec4& color = vec4(0.9f, 0.f, 0.f, 1.f)) const override;\r
+       //void drawBBox(const mat4& modelMat, const vec4& color = vec4(0.9f, 0.f, 0.f, 1.f)) const override;\r
 \r
        std::string type2str() const override;\r
 \r
index 062e9f5d72782cb382a0d59c7c85583dd7dfd199..0d7c1f3869c1d39b306acf5dc424f1f8dc68ef6a 100644 (file)
@@ -30,42 +30,27 @@ IMetaMesh::IMetaMesh(const string& _modelpath, const vec3& _scale, bool _isConve
 \r
        if (scene->HasMeshes())// && scene->mNumMeshes > mindex)\r
        {\r
-               aiMatrix4x4* aimat;\r
                mat4 tmpModelMat, tmpModelMatClean;\r
-               btTransform tmpModelMatBT;\r
                //vec3 BBmin, BBmax, tmpMin, tmpMax;\r
+               IMesh* tmpIMesh;\r
 \r
-               btCompoundShape* tmp_shape = new btCompoundShape();\r
-\r
-               aimat = &(root->mChildren[0]->mTransformation);\r
-\r
-               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);\r
-               tmpModelMatClean = removeScale(tmpModelMat);\r
-               tmpModelMatBT.setFromOpenGLMatrix(value_ptr(tmpModelMatClean));\r
-\r
+               \r
 \r
                //if (!scene->HasAnimations())\r
                {\r
 \r
-                       IMesh* tmpIMesh;\r
-                       tmpIMesh = new IMesh(scene->mMeshes[0], _scale* getScale(tmpModelMat), _isConvex);\r
-                       models.push_back(std::pair<IMesh*, mat4>(tmpIMesh, tmpModelMatClean));\r
-                       tmp_shape->addChildShape(tmpModelMatBT, *tmpIMesh);\r
 \r
-                       for (uint i = 1; i < scene->mNumMeshes; i++)\r
+                       for (uint i = 0; i < scene->mNumMeshes; i++)\r
                        {\r
-                               aimat = &(root->mChildren[i]->mTransformation);\r
-\r
-                               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);\r
+                               tmpModelMat = aiMat2mat4(&(root->mChildren[i]->mTransformation));\r
                                tmpModelMatClean = removeScale(tmpModelMat);\r
-                               tmpModelMatBT.setFromOpenGLMatrix(value_ptr(tmpModelMatClean));\r
-                               tmpIMesh = new IMesh(scene->mMeshes[i], _scale* getScale(tmpModelMat), _isConvex);\r
+                               tmpIMesh = new IMesh(scene->mMeshes[i], _scale* getScale(tmpModelMat));\r
                                models.push_back(std::pair<IMesh*, mat4>(tmpIMesh, tmpModelMatClean));\r
 \r
-                               tmp_shape->addChildShape(tmpModelMatBT, *tmpIMesh);\r
+                               \r
                        }\r
 \r
-                       bt_collision_shape = tmp_shape;\r
+                       \r
 \r
                }\r
                /*\r
@@ -128,6 +113,9 @@ IMetaMesh::IMetaMesh(const string& _modelpath, const vec3& _scale, bool _isConve
 \r
 IMetaMesh::~IMetaMesh()\r
 {\r
+       if (bt_collision_shape != nullptr)\r
+               delete bt_collision_shape;\r
+\r
        for (auto i = models.begin(); i != models.end(); ++i)\r
        {\r
                delete i->first;\r
@@ -174,6 +162,33 @@ void IMetaMesh::drawModel(Shader* _shader, Texture* _texture, const mat4& _model
        }\r
 }\r
 \r
+void IMetaMesh::bt_init(bool _isConvex)\r
+{\r
+       if (bt_collision_shape == nullptr)\r
+       {\r
+               if (models.size() == 1)\r
+               {\r
+                       auto tmp = models.front().first;\r
+                       tmp->bt_init(_isConvex);\r
+                       bt_collision_shape = *tmp;\r
+               }\r
+               else\r
+               {\r
+                       btCompoundShape* tmp_shape = new btCompoundShape();\r
+                       btTransform tmpModelMatBT;\r
+\r
+                       for (auto i = models.begin(); i != models.end(); ++i)\r
+                       {\r
+                               tmpModelMatBT.setFromOpenGLMatrix(value_ptr(i->second));\r
+                               i->first->bt_init(_isConvex);\r
+                               tmp_shape->addChildShape(tmpModelMatBT, *(i->first));\r
+                       }\r
+\r
+                       bt_collision_shape = tmp_shape;\r
+               }\r
+       }\r
+}\r
+\r
 \r
 void IMetaMesh::drawBBox(const mat4& _modelMat, const vec4& _color) const\r
 {\r
@@ -201,11 +216,11 @@ string IMetaMesh::type2str() const
 {\r
        return "IMetaMesh";\r
 }\r
-\r
-void IMetaMesh::setMargin(btScalar _margin)\r
-{\r
-       for (auto i = models.begin(); i != models.end(); ++i)\r
-       {\r
-               i->first->setMargin(_margin);\r
-       }\r
-}
\ No newline at end of file
+//\r
+//void IMetaMesh::setMargin(btScalar _margin)\r
+//{\r
+//     for (auto i = models.begin(); i != models.end(); ++i)\r
+//     {\r
+//             i->first->setMargin(_margin);\r
+//     }\r
+//}
\ No newline at end of file
index c5e79ca6fb84fe3fd5faeee3bdfd8a47d6c410f0..b1219fbe648e1fdc78bae708100b6b26302a76fa 100644 (file)
@@ -5,7 +5,6 @@
 #include <string>\r
 #include <list>\r
 #include "../../GLM.h"\r
-#include "../../Overlap.h"\r
 \r
 class IMesh;\r
 class Shader;\r
@@ -28,9 +27,9 @@ public:
 \r
        void drawBBox(const mat4& modelMat, const vec4& color = vec4(0.9f, 0.f, 0.f, 1.f)) const override;\r
 \r
-       std::string type2str() const override;\r
+       virtual void bt_init(bool isConvex = true) override;\r
 \r
-       void setMargin(btScalar margin) override;\r
+       std::string type2str() const override;\r
 \r
 protected:\r
 \r
index b9bb47547872964d80e92f291e23011d20b81b9a..589ede7a42daa4a780e42e06200dc616604269d1 100644 (file)
@@ -33,7 +33,7 @@ bt_collision_shape(nullptr)
 \r
 Model::~Model()\r
 {\r
-       if (bt_collision_shape!=nullptr)\r
+       if (bt_collision_shape != nullptr)\r
                delete bt_collision_shape;\r
        for (auto i = shader_map.begin(); i != shader_map.end(); ++i) {\r
                glDeleteVertexArrays(1, &(i->second));\r
@@ -158,19 +158,19 @@ void Model::drawBBox(const mat4& _modelMat, const vec4& _color) const
        getBBoxModel()->drawModel(Graphix::shader_BBox, NULL, _modelMat*translate(center)*glm::scale(size)); //\r
 }\r
 \r
-void Model::getBBcs(vec3& _center, vec3& _size) const\r
-{\r
-       btVector3 minB, maxB;\r
-       btTransform trans;\r
-       trans.setIdentity();\r
-       bt_collision_shape->getAabb(trans, minB, maxB);\r
-\r
-       vec3 min = vec3(minB.getX(), minB.getY(), minB.getZ());\r
-       vec3 max = vec3(maxB.getX(), maxB.getY(), maxB.getZ());\r
-\r
-       _size = (max - min) * .5f;\r
-       _center = (max + min) * .5f;\r
-}\r
+//void Model::getBBcs(vec3& _center, vec3& _size) const\r
+//{\r
+//     btVector3 minB, maxB;\r
+//     btTransform trans;\r
+//     trans.setIdentity();\r
+//     bt_collision_shape->getAabb(trans, minB, maxB);\r
+//\r
+//     vec3 min = vec3(minB.getX(), minB.getY(), minB.getZ());\r
+//     vec3 max = vec3(maxB.getX(), maxB.getY(), maxB.getZ());\r
+//\r
+//     _size = (max - min) * .5f;\r
+//     _center = (max + min) * .5f;\r
+//}\r
 \r
 void Model::genBuffer(uint &buffer, uint size, void* value)\r
 {\r
@@ -235,11 +235,6 @@ void Model::useModelMat(const mat4& _model, Shader* _shader) const
                glUniformMatrix4fv(tmp, 1, GL_FALSE, value_ptr(_model));\r
 }\r
 \r
-Model::operator btCollisionShape*() const\r
-{\r
-       return bt_collision_shape;\r
-}\r
-\r
 vec3 Model::rotateSize(const vec3& _size, const mat4& _modelMat)\r
 {\r
        vec3 newSize(0.f);\r
@@ -325,18 +320,18 @@ void Model::deleteIMetaModel(const string& _modelpath)
 }\r
 \r
 \r
-float Model::getPDistHit(const vec3& _P, const vec3& _direction) const\r
-{\r
-\r
-       vec3 posA, sizeA;\r
-       getBBcs(posA, sizeA);\r
-\r
-       //vec3 posAR = (vec3)(modelAR*vec4(posA, 1.f));\r
-       //vec3 posBR = (vec3)(modelBR*vec4(posB, 1.f));\r
-\r
-\r
-       return 1;\r
-}\r
+//float Model::getPDistHit(const vec3& _P, const vec3& _direction) const\r
+//{\r
+//\r
+//     vec3 posA, sizeA;\r
+//     getBBcs(posA, sizeA);\r
+//\r
+//     //vec3 posAR = (vec3)(modelAR*vec4(posA, 1.f));\r
+//     //vec3 posBR = (vec3)(modelBR*vec4(posB, 1.f));\r
+//\r
+//\r
+//     return 1;\r
+//}\r
 \r
 \r
 bool Model::loadMesh(const string& _modelpath, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, string& name, uint _mindex)\r
@@ -406,9 +401,37 @@ bool Model::loadMesh(const aiMesh* mesh, uint& numvertices, uint& numfaces, floa
        return true;\r
 }\r
 \r
-void Model::setMargin(btScalar _margin)\r
+Model::operator btCollisionShape*() const\r
 {\r
-       bt_collision_shape->setMargin(_margin);\r
+       return bt_collision_shape;\r
+}\r
+\r
+void Model::bt_setMargin(btScalar _margin)\r
+{\r
+       if(bt_collision_shape!=nullptr)\r
+               bt_collision_shape->setMargin(_margin);\r
+}\r
+\r
+void Model::bt_init(bool _isConvex)\r
+{\r
+       if (bt_collision_shape == nullptr)\r
+       {\r
+               btTriangleIndexVertexArray* meshInterface = new btTriangleIndexVertexArray();\r
+               btIndexedMesh part;\r
+               part.m_vertexBase = (const unsigned char*)vertex;\r
+               part.m_vertexStride = sizeof(float) * 3;\r
+               part.m_numVertices = numvertices;\r
+               part.m_triangleIndexBase = (const unsigned char*)index;\r
+               part.m_triangleIndexStride = sizeof(uint) * 3;\r
+               part.m_numTriangles = numfaces;\r
+               part.m_indexType = PHY_INTEGER;\r
+               meshInterface->addIndexedMesh(part, PHY_INTEGER);\r
+\r
+               if (_isConvex)\r
+                       bt_collision_shape = new btConvexTriangleMeshShape(meshInterface, true);\r
+               else\r
+                       bt_collision_shape = new btBvhTriangleMeshShape(meshInterface, true);\r
+       }\r
 }\r
 \r
 \r
index 70020892617b586ac796a81b9b7e8a0a44d2bd3c..abea0134ad33fcc7e07f4a03e0f67eb258851692 100644 (file)
@@ -4,8 +4,6 @@
 #include <unordered_map>\r
 #include <string>\r
 \r
-#include "../../Overlap.h"\r
-\r
 #include <btBulletDynamicsCommon.h>\r
 \r
 class Shader;\r
@@ -37,9 +35,7 @@ public:
        /* Get min&max from BBox */\r
 //     virtual void getBBmm(vec3& min, vec3& max) const;\r
        /* Get size&position from BBox */\r
-       void getBBcs(vec3& center, vec3& size) const;\r
-\r
-       virtual void setMargin(btScalar margin);\r
+       //void getBBcs(vec3& center, vec3& size) const;\r
 \r
        static Model* getBBoxModel();\r
        static Model* getSkyBoxModel();\r
@@ -49,12 +45,15 @@ public:
        static void deleteSkyBoxModel();\r
        static void deleteIMetaModel(const std::string& modelpath);\r
 \r
-       virtual float getPDistHit(const vec3& P, const vec3& direction) const;\r
+       //virtual float getPDistHit(const vec3& P, const vec3& direction) const;\r
 \r
        virtual operator std::string() const;\r
        virtual std::string type2str() const = 0;\r
 \r
+       \r
        virtual operator btCollisionShape*() const;\r
+       virtual void bt_init(bool _convex = true);\r
+       virtual void bt_setMargin(btScalar margin);\r
 \r
        // Mesh Speichern?\r
        static bool loadMesh(const std::string& modelpath, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, std::string& name, uint mindex = 0);\r
@@ -90,7 +89,6 @@ protected:
        static vec3 rotateSize(const vec3& size, const mat4& modelMat);\r
        static float directSize(const vec3& size, const vec3& direction);\r
 \r
-       //Bullet\r
        btCollisionShape* bt_collision_shape;\r
 \r
 private:\r
index 4fdda6e097d4176c05a9fa767d5877e286d7c784..723a684ae8b0a051b1bb1af62ccf3c3081eb3441 100644 (file)
@@ -48,9 +48,9 @@ void SkyBox::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat
 //{\r
 //}\r
 \r
-void SkyBox::drawBBox(const mat4& _modelMat, const vec4& _color) const\r
-{\r
-}\r
+//void SkyBox::drawBBox(const mat4& _modelMat, const vec4& _color) const\r
+//{\r
+//}\r
 \r
 std::string SkyBox::type2str() const\r
 {\r
index 099226da5a229c52c5517f63325f8c64b1feae3e..dd1cecbe8dfd2e11fd66927c101307d33cc58a3a 100644 (file)
@@ -16,7 +16,7 @@ public:
        //void useModelMat(const mat4& model, Shader* shader) const override;\r
        //void useTexture(Texture* texture, Shader* shader) const override;\r
 \r
-       void drawBBox(const mat4& modelMat, const vec4& color = vec4(0.f)) const override;\r
+       //void drawBBox(const mat4& modelMat, const vec4& color = vec4(0.f)) const override;\r
 \r
        std::string type2str() const override;\r
 \r
index 9993ede6785aba86bd203dacb0460a8c4c877e42..b320c051cf69ca51b6abedb055ab52ea0502335b 100644 (file)
@@ -18,12 +18,18 @@ EventBox::EventBox(const mat4& _modelMat, uint _EB_TYPE) :
        collide_group = COL_EVENT;
        collide_with = COL_MARVIN;
 
+       collision = model;
+       collision->bt_init();
+       bt_collision_object->setCollisionShape(*collision);
+       bt_collision_object->setUserPointer(this);
+
+
        btTransform btModelMat;
        btModelMat.setFromOpenGLMatrix(value_ptr(modelMat));
 
        btDefaultMotionState* MotionState =
                new btDefaultMotionState(btModelMat);
-       btRigidBody::btRigidBodyConstructionInfo RigidBodyCI(0, MotionState, *model, btVector3(0, 0, 0));
+       btRigidBody::btRigidBodyConstructionInfo RigidBodyCI(0, MotionState, *collision, btVector3(0, 0, 0));
 
        bt_rigid_body = new btRigidBody(RigidBodyCI);
 
@@ -43,8 +49,8 @@ void EventBox::update(float _deltaT)
 
 void EventBox::draw() const
 {
-       if (Events::isKToggleActive(SDLK_F6))
-               model->drawBBox(modelMat,vec4(.3f,.9f,.9f,1.f));
+if (Events::isKToggleActive(SDLK_F6))
+               collision->drawBBox(modelMat,vec4(.3f,.9f,.9f,1.f));
 }
 
 void EventBox::collides(SceneObject* _other, btPersistentManifold* _contactManifold, float _deltaT)
index f9ae3bab23c19ae8fd4b0faec2f5b5a925eb6329..8db7f00a4ef1ed9aa242ee2b4319a6492776f47a 100644 (file)
@@ -7,11 +7,16 @@
 #include "../GLM.h"
 
 
-Level::Level(Shader* _shader, std::string _modelpath, std::string _texturepath) : SceneObject(_shader, mat4(1.f), vec4(1.f), Model::newIMetaModel(_modelpath,false), _texturepath)
+Level::Level(Shader* _shader, std::string _modelpath, std::string _texturepath) : SceneObject(_shader, mat4(1.f), vec4(1.f), Model::newIMetaModel(_modelpath), _texturepath)
 {
        collide_group = COL_LEVEL;
        collide_with = COL_MARVIN | COL_ENEMY;
 
+       collision = model;
+       collision->bt_init(false);
+       bt_collision_object->setCollisionShape(*collision);
+       bt_collision_object->setUserPointer(this);
+
 
        btTransform btModelMat;
        btModelMat.setFromOpenGLMatrix(value_ptr(modelMat));
index f1ba7fa6205a4106b81907e0ca942a3c2c2286a2..ceca5e96716a08eeb0bd32eed009c508cb6632f6 100644 (file)
@@ -23,6 +23,7 @@ using std::string;
 
 SceneObject::SceneObject(Shader* _shader, const mat4& _modelMat, const vec4& _material, string _modelpath, string texturepath) :
 model(nullptr),
+collision(nullptr),
 modelMat(_modelMat),
 shader(_shader),
 mainScene(NULL),
@@ -47,7 +48,12 @@ move_delta(0)
        if (_modelpath != "")
        {
                model = Model::newIMetaModel(_modelpath);
+               model->bindModel();
                model->bindShader(shader);
+
+               /* BADHACK */
+               collision = model;
+               collision->bt_init();
                        
        }
 
@@ -74,13 +80,13 @@ move_delta(0)
                new btDefaultMotionState(btModelMat);
        btScalar mass = 1;
        btVector3 fallInertia(0, 0, 0);
-       model->operator btCollisionShape *()->calculateLocalInertia(mass, fallInertia);
-       btRigidBody::btRigidBodyConstructionInfo RigidBodyCI(mass, MotionState, *model, fallInertia);
+       collision->operator btCollisionShape *()->calculateLocalInertia(mass, fallInertia);
+       btRigidBody::btRigidBodyConstructionInfo RigidBodyCI(mass, MotionState, *collision, fallInertia);
 
 
        bt_rigid_body = new btRigidBody(RigidBodyCI);
 
-       bt_collision_object->setCollisionShape(*model);
+       bt_collision_object->setCollisionShape(*collision);
        bt_collision_object->setUserPointer(this);
 
 //     bt_rigid_body
@@ -88,6 +94,7 @@ move_delta(0)
 
 SceneObject::SceneObject(Shader* _shader, const mat4& _modelMat, const vec4& _material, Model* _model, string texturepath) :
 model(_model),
+collision(nullptr),
 modelMat(_modelMat),
 shader(_shader),
 mainScene(NULL),
@@ -120,14 +127,19 @@ move_delta(0)
                collide_group = COL_ENEMY;
        }
 
+       model->bindModel();
        model->bindShader(shader);
        //Message::info("Binding Shader");
        //Graphix::getGlError();
        //Message::info("Done");
        
        //TypeCast btCollisionShape
-       bt_collision_object->setCollisionShape(*model);
-       bt_collision_object->setUserPointer(this);
+       if (collision != nullptr)
+       {
+               bt_collision_object->setCollisionShape(*collision);
+               bt_collision_object->setUserPointer(this);
+       }
+       
 }
 
 SceneObject::~SceneObject()
@@ -143,7 +155,11 @@ SceneObject::~SceneObject()
        if (texture!=nullptr)
                Texture::deleteTexture(*texture);
        if (newModel)
+       {
                Model::deleteIMetaModel(*model);
+               Model::deleteIMetaModel(*collision);
+       }
+               
 }
 
 
@@ -176,7 +192,7 @@ void SceneObject::update(float deltaT)
 
 void SceneObject::setMargin(btScalar _margin)
 {
-       model->setMargin(_margin);
+       collision->bt_setMargin(_margin);
 }
 
 void SceneObject::draw() const
@@ -192,8 +208,8 @@ void SceneObject::draw() const
        //      drawModel();
 
        model->drawModel(shader, texture, modelMat);
-       if (Events::isKToggleActive(SDLK_F6))
-               model->drawBBox(modelMat);
+       if (Events::isKToggleActive(SDLK_F6)&&collision!=nullptr)
+               collision->drawBBox(modelMat);
 }
 
 
index 358d3e6b68c21df8179eacb1c1a4bee06e5b047d..f05f29988fc18f3c6cddfdb9549de7036d2c389d 100644 (file)
@@ -90,6 +90,7 @@ protected:
        Shader* shader;
        Texture* texture;
        Model* model;
+       Model* collision;
        bool newModel;
 
        Scene* mainScene;
index 8f95dbda2dacee06c01e6d7cd608bce9ba876957..722b3c66bacaa866c11de6509409416444303971 100644 (file)
     <ClCompile Include="Graphix\Model\IMetaMesh.cpp" />\r
     <ClCompile Include="Graphix\Model\Model.cpp" />\r
     <ClCompile Include="Graphix\Model\SkyBox.cpp" />\r
-    <ClCompile Include="Overlap.cpp" />\r
     <ClCompile Include="Scene\EventBox.cpp" />\r
     <ClCompile Include="Scene\Level.cpp" />\r
     <ClCompile Include="Scene\Marvin.cpp" />\r
     <ClInclude Include="Graphix\Model\IMetaMesh.h" />\r
     <ClInclude Include="Graphix\Model\Model.h" />\r
     <ClInclude Include="Graphix\Model\SkyBox.h" />\r
-    <ClInclude Include="Overlap.h" />\r
     <ClInclude Include="Scene.h" />\r
     <ClInclude Include="Scene\EventBox.h" />\r
     <ClInclude Include="Scene\Level.h" />\r
index 6795ff96a986396f1c5a15d69162fe942e1ec97c..09a7867eabb96dd3ad8de59750a5b65e18c90672 100644 (file)
@@ -72,9 +72,6 @@
     <ClCompile Include="Graphix\Model\SkyBox.cpp">\r
       <Filter>Source Files</Filter>\r
     </ClCompile>\r
-    <ClCompile Include="Overlap.cpp">\r
-      <Filter>Source Files</Filter>\r
-    </ClCompile>\r
     <ClCompile Include="GLM.cpp">\r
       <Filter>Source Files</Filter>\r
     </ClCompile>\r
     <ClInclude Include="Graphix\Model\SkyBox.h">\r
       <Filter>Header Files</Filter>\r
     </ClInclude>\r
-    <ClInclude Include="Overlap.h">\r
-      <Filter>Header Files</Filter>\r
-    </ClInclude>\r
     <ClInclude Include="GLM.h">\r
       <Filter>Header Files</Filter>\r
     </ClInclude>\r