From: Peter Schaefer Date: Mon, 1 Jun 2015 12:25:21 +0000 (+0200) Subject: creating btShapes (not Tested) X-Git-Url: https://git.leopard-lacewing.eu/?a=commitdiff_plain;h=05cda93f87347a32eede00968eee04015066641f;p=cgue_weave.git creating btShapes (not Tested) --- diff --git a/Weave/Graphix/Model/BBox.cpp b/Weave/Graphix/Model/BBox.cpp index 25f9cf7..5c65628 100644 --- a/Weave/Graphix/Model/BBox.cpp +++ b/Weave/Graphix/Model/BBox.cpp @@ -17,10 +17,14 @@ BBox::BBox() genBuffer(vertexBuffer, numvertices * 3 * sizeof(float), (void*)vertex); // genBuffer(indexBuffer, 4 * sizeof(float), (void*)indexL1); + bt_collision_shape = new btBoxShape(btVector3(.5f,.5f,.5f)); + } BBox::~BBox() { + //delete bt_collision_shape; //done inside Model.cpp + glDeleteBuffers(1, &vertexBuffer); //glDeleteBuffers(1, &indexBuffer); //glDeleteBuffers(1, &normalBuffer); diff --git a/Weave/Graphix/Model/IMesh.cpp b/Weave/Graphix/Model/IMesh.cpp index 0873f56..a3a621c 100644 --- a/Weave/Graphix/Model/IMesh.cpp +++ b/Weave/Graphix/Model/IMesh.cpp @@ -37,6 +37,13 @@ IMesh::IMesh(const string& _modelpath, uint _mindex) : modelpath(_modelpath), ro import(_modelpath, numvertices, numfaces, vertex, uvs, normals, index, _mindex); + btConvexHullShape* tmp_shape = new btConvexHullShape(); + + for (int i = 0; i < numvertices; i += 3) + tmp_shape->addPoint(btVector3(vertex[i], vertex[i + 1], vertex[i + 2])); + + bt_collision_shape = tmp_shape; + #ifdef COMPARE_MTREE root = buildMeshTree(mat4(1.f), numvertices, numfaces, vertex, normals, index); @@ -58,6 +65,13 @@ IMesh::IMesh(const aiMesh* _mesh, const mat4& _transformation) : modelMat(_trans import(_mesh, numvertices, numfaces, vertex, uvs, normals, index); + btConvexHullShape* tmp_shape = new btConvexHullShape(); + + for (int i = 0; i < numvertices; i += 3) + tmp_shape->addPoint(btVector3(vertex[i], vertex[i + 1], vertex[i + 2])); + + bt_collision_shape = tmp_shape; + #ifdef COMPARE_MTREE root = buildMeshTree(_transformation, numvertices, numfaces, vertex, normals, index); diff --git a/Weave/Graphix/Model/IMetaMesh.cpp b/Weave/Graphix/Model/IMetaMesh.cpp index 9ede5ac..407654e 100644 --- a/Weave/Graphix/Model/IMetaMesh.cpp +++ b/Weave/Graphix/Model/IMetaMesh.cpp @@ -33,6 +33,8 @@ IMetaMesh::IMetaMesh(const string& _modelpath) : modelpath(_modelpath) mat4 tmpModelMat; //vec3 BBmin, BBmax, tmpMin, tmpMax; + 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); @@ -41,6 +43,9 @@ IMetaMesh::IMetaMesh(const string& _modelpath) : modelpath(_modelpath) models.push_back(tmpIMesh); setBB(tmpIMesh->getBBox()); + + tmp_shape->addChildShape(btTransform(),*tmpIMesh); + for (uint i = 1; i < scene->mNumMeshes; i++) { aimat = &(root->mChildren[i]->mTransformation); @@ -49,6 +54,8 @@ IMetaMesh::IMetaMesh(const string& _modelpath) : modelpath(_modelpath) tmpIMesh = new IMesh(scene->mMeshes[i], tmpModelMat); models.push_back(tmpIMesh); updateBB(tmpIMesh->getBBox()); + + tmp_shape->addChildShape(btTransform(), *tmpIMesh); //tmpIMesh->getBBmm(tmpMin, tmpMax); //for (auto j = 0; j < 3; ++j) //{ @@ -60,6 +67,8 @@ IMetaMesh::IMetaMesh(const string& _modelpath) : modelpath(_modelpath) } //setBB(BBmin, BBmax); + + bt_collision_shape = tmp_shape; } else { diff --git a/Weave/Graphix/Model/Model.cpp b/Weave/Graphix/Model/Model.cpp index 3252885..201c185 100644 --- a/Weave/Graphix/Model/Model.cpp +++ b/Weave/Graphix/Model/Model.cpp @@ -28,12 +28,15 @@ numvertices(0), vertexBuffer(-1), normalBuffer(-1), uvBuffer(-1), -indexBuffer(-1) +indexBuffer(-1), +bt_collision_shape(nullptr) { } Model::~Model() { + if (bt_collision_shape!=nullptr) + delete bt_collision_shape; for (auto i = shader_map.begin(); i != shader_map.end(); ++i){ glDeleteVertexArrays(1, &(i->second)); }