From 0dfed0983ce2b2c7dabc166eef8ae23c482dc5fb Mon Sep 17 00:00:00 2001 From: Peter Schaefer Date: Wed, 30 Mar 2016 12:57:16 +0200 Subject: [PATCH] moved Collision Mesh into SceneObject badhack use Same Mesh for collision --- Weave/GLM.cpp | 9 ++++ Weave/GLM.h | 7 +++ Weave/Graphix/Model/BBox.cpp | 9 +++- Weave/Graphix/Model/BBox.h | 2 + Weave/Graphix/Model/IAnimMesh.cpp | 2 +- Weave/Graphix/Model/IMesh.cpp | 26 ++------- Weave/Graphix/Model/IMesh.h | 5 +- Weave/Graphix/Model/IMetaMesh.cpp | 75 +++++++++++++++----------- Weave/Graphix/Model/IMetaMesh.h | 5 +- Weave/Graphix/Model/Model.cpp | 89 +++++++++++++++++++------------ Weave/Graphix/Model/Model.h | 12 ++--- Weave/Graphix/Model/SkyBox.cpp | 6 +-- Weave/Graphix/Model/SkyBox.h | 2 +- Weave/Scene/EventBox.cpp | 12 +++-- Weave/Scene/Level.cpp | 7 ++- Weave/Scene/SceneObject.cpp | 32 ++++++++--- Weave/Scene/SceneObject.h | 1 + Weave/Weave.vcxproj | 2 - Weave/Weave.vcxproj.filters | 6 --- 19 files changed, 185 insertions(+), 124 deletions(-) diff --git a/Weave/GLM.cpp b/Weave/GLM.cpp index 170257e..bd22036 100644 --- a/Weave/GLM.cpp +++ b/Weave/GLM.cpp @@ -105,3 +105,12 @@ void scaleVec3(vec3& _vec, const vec3& _scale) _vec[i] *= _scale[i]; } +//#include +#include +//#include + +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); +} + diff --git a/Weave/GLM.h b/Weave/GLM.h index 45c9f19..5617289 100644 --- a/Weave/GLM.h +++ b/Weave/GLM.h @@ -31,6 +31,11 @@ using glm::sign; using glm::min; using glm::max; +//#include +template +class aiMatrix4x4t; +typedef aiMatrix4x4t 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 diff --git a/Weave/Graphix/Model/BBox.cpp b/Weave/Graphix/Model/BBox.cpp index 5de0e97..6d6646e 100644 --- a/Weave/Graphix/Model/BBox.cpp +++ b/Weave/Graphix/Model/BBox.cpp @@ -13,11 +13,10 @@ BBox::BBox() //import("skybox.dae", numvertices, numfaces, vertex, uvs, normals, index, 0); bindModel(); + bt_init(); name = "BBox"; - bt_collision_shape = new btBoxShape(btVector3(.5f,.5f,.5f)); - } BBox::~BBox() @@ -39,6 +38,12 @@ void BBox::drawModel() const glBindVertexArray(0); } +void BBox::bt_init(bool isConvex) +{ + if(bt_collision_shape==nullptr) + bt_collision_shape = new btBoxShape(btVector3(.5f, .5f, .5f)); +} + std::string BBox::type2str() const { diff --git a/Weave/Graphix/Model/BBox.h b/Weave/Graphix/Model/BBox.h index 3d99b2d..3f68bd5 100644 --- a/Weave/Graphix/Model/BBox.h +++ b/Weave/Graphix/Model/BBox.h @@ -11,6 +11,8 @@ public: void drawModel() const override; + void bt_init(bool isConvex = true) override; + std::string type2str() const override; }; diff --git a/Weave/Graphix/Model/IAnimMesh.cpp b/Weave/Graphix/Model/IAnimMesh.cpp index 7a513eb..2e818c8 100644 --- a/Weave/Graphix/Model/IAnimMesh.cpp +++ b/Weave/Graphix/Model/IAnimMesh.cpp @@ -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) { } diff --git a/Weave/Graphix/Model/IMesh.cpp b/Weave/Graphix/Model/IMesh.cpp index f9b04a3..65f6146 100644 --- a/Weave/Graphix/Model/IMesh.cpp +++ b/Weave/Graphix/Model/IMesh.cpp @@ -39,28 +39,12 @@ using std::array; // //} -IMesh::IMesh(const aiMesh* _mesh, const vec3& _scale, bool _isConvex) : modelpath("IMesh") +IMesh::IMesh(const aiMesh* _mesh, const vec3& _scale) : modelpath("IMesh") { loadMesh(_mesh, numvertices, numfaces, vertex, uvs, normals, index, name, _scale); - btTriangleIndexVertexArray* meshInterface = new btTriangleIndexVertexArray(); - btIndexedMesh part; - part.m_vertexBase = (const unsigned char*)vertex; - part.m_vertexStride = sizeof(float) * 3; - part.m_numVertices = numvertices; - part.m_triangleIndexBase = (const unsigned char*)index; - part.m_triangleIndexStride = sizeof(uint) * 3; - part.m_numTriangles = numfaces; - part.m_indexType = PHY_INTEGER; - meshInterface->addIndexedMesh(part, PHY_INTEGER); - - if (_isConvex) - bt_collision_shape = new btConvexTriangleMeshShape(meshInterface, true); - else - bt_collision_shape = new btBvhTriangleMeshShape(meshInterface, true); bindModel(); - } IMesh::~IMesh() @@ -78,10 +62,10 @@ IMesh::~IMesh() //} -void IMesh::drawBBox(const mat4& _modelMat, const vec4& _color) const -{ - Model::drawBBox(_modelMat, _color); -} +//void IMesh::drawBBox(const mat4& _modelMat, const vec4& _color) const +//{ +// Model::drawBBox(_modelMat, _color); +//} string IMesh::type2str() const diff --git a/Weave/Graphix/Model/IMesh.h b/Weave/Graphix/Model/IMesh.h index e3c4401..6a4fd24 100644 --- a/Weave/Graphix/Model/IMesh.h +++ b/Weave/Graphix/Model/IMesh.h @@ -3,7 +3,6 @@ #include #include #include "../../GLM.h" -#include "../../Overlap.h" #include "Model.h" @@ -16,13 +15,13 @@ public: // class Node; // IMesh(const std::string& modelpath, uint index=0); - IMesh(const aiMesh* mesh, const vec3& scale = vec3(1.f), bool isConvex=true); + IMesh(const aiMesh* mesh, const vec3& scale = vec3(1.f)); virtual ~IMesh(); //void useModelMat(const mat4& model, Shader* shader) const override; - void drawBBox(const mat4& modelMat, const vec4& color = vec4(0.9f, 0.f, 0.f, 1.f)) const override; + //void drawBBox(const mat4& modelMat, const vec4& color = vec4(0.9f, 0.f, 0.f, 1.f)) const override; std::string type2str() const override; diff --git a/Weave/Graphix/Model/IMetaMesh.cpp b/Weave/Graphix/Model/IMetaMesh.cpp index 062e9f5..0d7c1f3 100644 --- a/Weave/Graphix/Model/IMetaMesh.cpp +++ b/Weave/Graphix/Model/IMetaMesh.cpp @@ -30,42 +30,27 @@ IMetaMesh::IMetaMesh(const string& _modelpath, const vec3& _scale, bool _isConve if (scene->HasMeshes())// && scene->mNumMeshes > mindex) { - aiMatrix4x4* aimat; mat4 tmpModelMat, tmpModelMatClean; - btTransform tmpModelMatBT; //vec3 BBmin, BBmax, tmpMin, tmpMax; + IMesh* tmpIMesh; - btCompoundShape* tmp_shape = new btCompoundShape(); - - aimat = &(root->mChildren[0]->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); - tmpModelMatClean = removeScale(tmpModelMat); - tmpModelMatBT.setFromOpenGLMatrix(value_ptr(tmpModelMatClean)); - + //if (!scene->HasAnimations()) { - IMesh* tmpIMesh; - tmpIMesh = new IMesh(scene->mMeshes[0], _scale* getScale(tmpModelMat), _isConvex); - models.push_back(std::pair(tmpIMesh, tmpModelMatClean)); - tmp_shape->addChildShape(tmpModelMatBT, *tmpIMesh); - for (uint i = 1; i < scene->mNumMeshes; i++) + for (uint i = 0; i < scene->mNumMeshes; i++) { - 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); + tmpModelMat = aiMat2mat4(&(root->mChildren[i]->mTransformation)); tmpModelMatClean = removeScale(tmpModelMat); - tmpModelMatBT.setFromOpenGLMatrix(value_ptr(tmpModelMatClean)); - tmpIMesh = new IMesh(scene->mMeshes[i], _scale* getScale(tmpModelMat), _isConvex); + tmpIMesh = new IMesh(scene->mMeshes[i], _scale* getScale(tmpModelMat)); models.push_back(std::pair(tmpIMesh, tmpModelMatClean)); - tmp_shape->addChildShape(tmpModelMatBT, *tmpIMesh); + } - bt_collision_shape = tmp_shape; + } /* @@ -128,6 +113,9 @@ IMetaMesh::IMetaMesh(const string& _modelpath, const vec3& _scale, bool _isConve IMetaMesh::~IMetaMesh() { + if (bt_collision_shape != nullptr) + delete bt_collision_shape; + for (auto i = models.begin(); i != models.end(); ++i) { delete i->first; @@ -174,6 +162,33 @@ void IMetaMesh::drawModel(Shader* _shader, Texture* _texture, const mat4& _model } } +void IMetaMesh::bt_init(bool _isConvex) +{ + if (bt_collision_shape == nullptr) + { + if (models.size() == 1) + { + auto tmp = models.front().first; + tmp->bt_init(_isConvex); + bt_collision_shape = *tmp; + } + else + { + btCompoundShape* tmp_shape = new btCompoundShape(); + btTransform tmpModelMatBT; + + for (auto i = models.begin(); i != models.end(); ++i) + { + tmpModelMatBT.setFromOpenGLMatrix(value_ptr(i->second)); + i->first->bt_init(_isConvex); + tmp_shape->addChildShape(tmpModelMatBT, *(i->first)); + } + + bt_collision_shape = tmp_shape; + } + } +} + void IMetaMesh::drawBBox(const mat4& _modelMat, const vec4& _color) const { @@ -201,11 +216,11 @@ string IMetaMesh::type2str() const { return "IMetaMesh"; } - -void IMetaMesh::setMargin(btScalar _margin) -{ - for (auto i = models.begin(); i != models.end(); ++i) - { - i->first->setMargin(_margin); - } -} \ No newline at end of file +// +//void IMetaMesh::setMargin(btScalar _margin) +//{ +// for (auto i = models.begin(); i != models.end(); ++i) +// { +// i->first->setMargin(_margin); +// } +//} \ No newline at end of file diff --git a/Weave/Graphix/Model/IMetaMesh.h b/Weave/Graphix/Model/IMetaMesh.h index c5e79ca..b1219fb 100644 --- a/Weave/Graphix/Model/IMetaMesh.h +++ b/Weave/Graphix/Model/IMetaMesh.h @@ -5,7 +5,6 @@ #include #include #include "../../GLM.h" -#include "../../Overlap.h" class IMesh; class Shader; @@ -28,9 +27,9 @@ public: void drawBBox(const mat4& modelMat, const vec4& color = vec4(0.9f, 0.f, 0.f, 1.f)) const override; - std::string type2str() const override; + virtual void bt_init(bool isConvex = true) override; - void setMargin(btScalar margin) override; + std::string type2str() const override; protected: diff --git a/Weave/Graphix/Model/Model.cpp b/Weave/Graphix/Model/Model.cpp index b9bb475..589ede7 100644 --- a/Weave/Graphix/Model/Model.cpp +++ b/Weave/Graphix/Model/Model.cpp @@ -33,7 +33,7 @@ bt_collision_shape(nullptr) Model::~Model() { - if (bt_collision_shape!=nullptr) + if (bt_collision_shape != nullptr) delete bt_collision_shape; for (auto i = shader_map.begin(); i != shader_map.end(); ++i) { glDeleteVertexArrays(1, &(i->second)); @@ -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)); // } -void Model::getBBcs(vec3& _center, vec3& _size) const -{ - btVector3 minB, maxB; - btTransform trans; - trans.setIdentity(); - bt_collision_shape->getAabb(trans, minB, maxB); - - vec3 min = vec3(minB.getX(), minB.getY(), minB.getZ()); - vec3 max = vec3(maxB.getX(), maxB.getY(), maxB.getZ()); - - _size = (max - min) * .5f; - _center = (max + min) * .5f; -} +//void Model::getBBcs(vec3& _center, vec3& _size) const +//{ +// btVector3 minB, maxB; +// btTransform trans; +// trans.setIdentity(); +// bt_collision_shape->getAabb(trans, minB, maxB); +// +// vec3 min = vec3(minB.getX(), minB.getY(), minB.getZ()); +// vec3 max = vec3(maxB.getX(), maxB.getY(), maxB.getZ()); +// +// _size = (max - min) * .5f; +// _center = (max + min) * .5f; +//} void Model::genBuffer(uint &buffer, uint size, void* value) { @@ -235,11 +235,6 @@ void Model::useModelMat(const mat4& _model, Shader* _shader) const glUniformMatrix4fv(tmp, 1, GL_FALSE, value_ptr(_model)); } -Model::operator btCollisionShape*() const -{ - return bt_collision_shape; -} - vec3 Model::rotateSize(const vec3& _size, const mat4& _modelMat) { vec3 newSize(0.f); @@ -325,18 +320,18 @@ void Model::deleteIMetaModel(const string& _modelpath) } -float Model::getPDistHit(const vec3& _P, const vec3& _direction) const -{ - - vec3 posA, sizeA; - getBBcs(posA, sizeA); - - //vec3 posAR = (vec3)(modelAR*vec4(posA, 1.f)); - //vec3 posBR = (vec3)(modelBR*vec4(posB, 1.f)); - - - return 1; -} +//float Model::getPDistHit(const vec3& _P, const vec3& _direction) const +//{ +// +// vec3 posA, sizeA; +// getBBcs(posA, sizeA); +// +// //vec3 posAR = (vec3)(modelAR*vec4(posA, 1.f)); +// //vec3 posBR = (vec3)(modelBR*vec4(posB, 1.f)); +// +// +// return 1; +//} bool Model::loadMesh(const string& _modelpath, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, string& name, uint _mindex) @@ -406,9 +401,37 @@ bool Model::loadMesh(const aiMesh* mesh, uint& numvertices, uint& numfaces, floa return true; } -void Model::setMargin(btScalar _margin) +Model::operator btCollisionShape*() const { - bt_collision_shape->setMargin(_margin); + return bt_collision_shape; +} + +void Model::bt_setMargin(btScalar _margin) +{ + if(bt_collision_shape!=nullptr) + bt_collision_shape->setMargin(_margin); +} + +void Model::bt_init(bool _isConvex) +{ + if (bt_collision_shape == nullptr) + { + btTriangleIndexVertexArray* meshInterface = new btTriangleIndexVertexArray(); + btIndexedMesh part; + part.m_vertexBase = (const unsigned char*)vertex; + part.m_vertexStride = sizeof(float) * 3; + part.m_numVertices = numvertices; + part.m_triangleIndexBase = (const unsigned char*)index; + part.m_triangleIndexStride = sizeof(uint) * 3; + part.m_numTriangles = numfaces; + part.m_indexType = PHY_INTEGER; + meshInterface->addIndexedMesh(part, PHY_INTEGER); + + if (_isConvex) + bt_collision_shape = new btConvexTriangleMeshShape(meshInterface, true); + else + bt_collision_shape = new btBvhTriangleMeshShape(meshInterface, true); + } } diff --git a/Weave/Graphix/Model/Model.h b/Weave/Graphix/Model/Model.h index 7002089..abea013 100644 --- a/Weave/Graphix/Model/Model.h +++ b/Weave/Graphix/Model/Model.h @@ -4,8 +4,6 @@ #include #include -#include "../../Overlap.h" - #include class Shader; @@ -37,9 +35,7 @@ public: /* Get min&max from BBox */ // virtual void getBBmm(vec3& min, vec3& max) const; /* Get size&position from BBox */ - void getBBcs(vec3& center, vec3& size) const; - - virtual void setMargin(btScalar margin); + //void getBBcs(vec3& center, vec3& size) const; static Model* getBBoxModel(); static Model* getSkyBoxModel(); @@ -49,12 +45,15 @@ public: static void deleteSkyBoxModel(); static void deleteIMetaModel(const std::string& modelpath); - virtual float getPDistHit(const vec3& P, const vec3& direction) const; + //virtual float getPDistHit(const vec3& P, const vec3& direction) const; virtual operator std::string() const; virtual std::string type2str() const = 0; + virtual operator btCollisionShape*() const; + virtual void bt_init(bool _convex = true); + virtual void bt_setMargin(btScalar margin); // Mesh Speichern? 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); @@ -90,7 +89,6 @@ protected: static vec3 rotateSize(const vec3& size, const mat4& modelMat); static float directSize(const vec3& size, const vec3& direction); - //Bullet btCollisionShape* bt_collision_shape; private: diff --git a/Weave/Graphix/Model/SkyBox.cpp b/Weave/Graphix/Model/SkyBox.cpp index 4fdda6e..723a684 100644 --- a/Weave/Graphix/Model/SkyBox.cpp +++ b/Weave/Graphix/Model/SkyBox.cpp @@ -48,9 +48,9 @@ void SkyBox::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat //{ //} -void SkyBox::drawBBox(const mat4& _modelMat, const vec4& _color) const -{ -} +//void SkyBox::drawBBox(const mat4& _modelMat, const vec4& _color) const +//{ +//} std::string SkyBox::type2str() const { diff --git a/Weave/Graphix/Model/SkyBox.h b/Weave/Graphix/Model/SkyBox.h index 099226d..dd1cecb 100644 --- a/Weave/Graphix/Model/SkyBox.h +++ b/Weave/Graphix/Model/SkyBox.h @@ -16,7 +16,7 @@ public: //void useModelMat(const mat4& model, Shader* shader) const override; //void useTexture(Texture* texture, Shader* shader) const override; - void drawBBox(const mat4& modelMat, const vec4& color = vec4(0.f)) const override; + //void drawBBox(const mat4& modelMat, const vec4& color = vec4(0.f)) const override; std::string type2str() const override; diff --git a/Weave/Scene/EventBox.cpp b/Weave/Scene/EventBox.cpp index 9993ede..b320c05 100644 --- a/Weave/Scene/EventBox.cpp +++ b/Weave/Scene/EventBox.cpp @@ -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) diff --git a/Weave/Scene/Level.cpp b/Weave/Scene/Level.cpp index f9ae3ba..8db7f00 100644 --- a/Weave/Scene/Level.cpp +++ b/Weave/Scene/Level.cpp @@ -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)); diff --git a/Weave/Scene/SceneObject.cpp b/Weave/Scene/SceneObject.cpp index f1ba7fa..ceca5e9 100644 --- a/Weave/Scene/SceneObject.cpp +++ b/Weave/Scene/SceneObject.cpp @@ -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); } diff --git a/Weave/Scene/SceneObject.h b/Weave/Scene/SceneObject.h index 358d3e6..f05f299 100644 --- a/Weave/Scene/SceneObject.h +++ b/Weave/Scene/SceneObject.h @@ -90,6 +90,7 @@ protected: Shader* shader; Texture* texture; Model* model; + Model* collision; bool newModel; Scene* mainScene; diff --git a/Weave/Weave.vcxproj b/Weave/Weave.vcxproj index 8f95dbd..722b3c6 100644 --- a/Weave/Weave.vcxproj +++ b/Weave/Weave.vcxproj @@ -104,7 +104,6 @@ - @@ -134,7 +133,6 @@ - diff --git a/Weave/Weave.vcxproj.filters b/Weave/Weave.vcxproj.filters index 6795ff9..09a7867 100644 --- a/Weave/Weave.vcxproj.filters +++ b/Weave/Weave.vcxproj.filters @@ -72,9 +72,6 @@ Source Files - - Source Files - Source Files @@ -155,9 +152,6 @@ Header Files - - Header Files - Header Files -- 2.47.3