]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
creating btShapes (not Tested)
authorPeter Schaefer <schaeferpm@gmail.com>
Mon, 1 Jun 2015 12:25:21 +0000 (14:25 +0200)
committerPeter Schaefer <schaeferpm@gmail.com>
Mon, 1 Jun 2015 12:25:21 +0000 (14:25 +0200)
Weave/Graphix/Model/BBox.cpp
Weave/Graphix/Model/IMesh.cpp
Weave/Graphix/Model/IMetaMesh.cpp
Weave/Graphix/Model/Model.cpp

index 25f9cf73b859c4d4af9014075ea3e0216ef3d718..5c65628c723fb43607a4a993231959ef6696fa4d 100644 (file)
@@ -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);
index 0873f56315e39453f1782ac2ade4b0020ee956b0..a3a621c59867c9a06f543e6c9bb4783d604f7f1f 100644 (file)
@@ -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);
 
index 9ede5acf0fda35be96871e1f85b97a6bda8c7740..407654eb27a389ffd25882c5c91dfc7896eda986 100644 (file)
@@ -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
        {
index 32528851f6235bf63f331c12f51162fc0bb159fb..201c1850d99de4a37d95da72eb20cccaf7890785 100644 (file)
@@ -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));
        }