]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
removed Triangle,Box,Splitmat BBoxsizes
authorPeter Schaefer <schaeferpm@gmail.com>
Tue, 16 Jun 2015 13:27:09 +0000 (15:27 +0200)
committerPeter Schaefer <schaeferpm@gmail.com>
Tue, 16 Jun 2015 13:27:09 +0000 (15:27 +0200)
Weave/Graphix/Model/BBox.cpp
Weave/Graphix/Model/IMesh.cpp
Weave/Graphix/Model/IMetaMesh.cpp
Weave/Graphix/Model/Model.cpp
Weave/Graphix/Model/Model.h

index 5c65628c723fb43607a4a993231959ef6696fa4d..5f84d7d493c070e586fcce49cdb521b006a9ebe6 100644 (file)
@@ -10,8 +10,6 @@ BBox::BBox()
 
        float vertex[] { -.5f, -.5f, -.5f, .5f, -.5f, -.5f, .5f, .5f, -.5f, -.5f, .5f, -.5f, -.5f, -.5f, .5f, .5f, -.5f, .5f, .5f, .5f, .5f, -.5f, .5f, .5f };
 
-       setBB(vec3(-.5f), vec3(.5f));
-
        //import("skybox.dae", numvertices, numfaces, vertex, uvs, normals, index, 0);
 
        genBuffer(vertexBuffer, numvertices * 3 * sizeof(float), (void*)vertex);
index 2058da7a7da30075d9de16379ba1f6f925d0c4ab..c512cde4d7038da1b5033c0fbc3669e8a10b231c 100644 (file)
 using std::string;
 using std::list;
 using std::array;
-typedef Model::Triangle Triangle;
-typedef Model::Box Box;
-typedef IMesh::Node Node;
-
 
 //IMesh::IMesh(const string& _modelpath, uint _mindex) : modelpath(_modelpath), root(nullptr)
 //{
@@ -34,14 +30,7 @@ typedef IMesh::Node Node;
 //
 //     bt_collision_shape = tmp_shape;
 //
-//#ifdef COMPARE_MTREE
-//     root = buildMeshTree(mat4(1.f), numvertices, numfaces, vertex, normals, index);
-//
-//     vec3 min, max;
-//     setBB(*root);
-//#else
 //     setBB(numvertices, vertex);
-//#endif
 //
 //     genBuffer(vertexBuffer, numvertices * 3 * sizeof(float), (void*)vertex);
 //     genBuffer(normalBuffer, numvertices * 3 * sizeof(float), (void*)normals);
@@ -77,9 +66,6 @@ IMesh::IMesh(const aiMesh* _mesh, const vec3& _scale) : modelpath("IMesh")
        bt_collision_shape = new btConvexTriangleMeshShape(tmp_mesh,true);
        //bt_collision_shape = tmp_shape;
 
-       setBB(numvertices, vertex);
-
-
        genBuffer(vertexBuffer, numvertices * 3 * sizeof(float), (void*)vertex);
        genBuffer(normalBuffer, numvertices * 3 * sizeof(float), (void*)normals);
        genBuffer(uvBuffer, numvertices * 2 * sizeof(float), (void*)uvs);
index a21fd54a4799b100c1882e027b6bef4b14079878..8c7c9de873d58024dace924f992559ea8b409a49 100644 (file)
@@ -43,7 +43,6 @@ IMetaMesh::IMetaMesh(const string& _modelpath, const vec3& _scale) : modelpath(_
                tmpModelMatBT.setFromOpenGLMatrix(value_ptr(tmpModelMatClean));
                tmpIMesh = new IMesh(scene->mMeshes[0], _scale* getScale(tmpModelMat));
                models.push_back(std::pair<IMesh*,mat4>(tmpIMesh,tmpModelMatClean));
-               setBB(tmpIMesh->getBBox());
                tmp_shape->addChildShape(tmpModelMatBT,*tmpIMesh);
 
                for (uint i = 1; i < scene->mNumMeshes; i++)
@@ -55,21 +54,10 @@ IMetaMesh::IMetaMesh(const string& _modelpath, const vec3& _scale) : modelpath(_
                        tmpModelMatBT.setFromOpenGLMatrix(value_ptr(tmpModelMatClean));
                        tmpIMesh = new IMesh(scene->mMeshes[i], _scale* getScale(tmpModelMat));
                        models.push_back(std::pair<IMesh*, mat4>(tmpIMesh, tmpModelMatClean));
-                       updateBB(tmpIMesh->getBBox());
 
                        tmp_shape->addChildShape(tmpModelMatBT, *tmpIMesh);
-                       //tmpIMesh->getBBmm(tmpMin, tmpMax);
-                       //for (auto j = 0; j < 3; ++j)
-                       //{
-                       //      if (tmpMin[j] < BBmin[j])
-                       //              BBmin[j] = tmpMin[j];
-                       //      if (tmpMax[j] > BBmax[j])
-                       //              BBmax[j] = tmpMax[j];
-                       //}
                }
 
-               //setBB(BBmin, BBmax);
-
                bt_collision_shape = tmp_shape;
        }
        else
index e010a4a8c489ca0acdd3244a30c8cf5c4be1de62..dae550ca71b4bde0ba58582223dfd191bdc69133 100644 (file)
 
 #include "../../Events.h"
 
-typedef Model::Triangle Triangle;
-typedef Model::Box Box;
-typedef Model::SplitMat SplitMat;
-
 Model::Model() :
 numfaces(0),
 numvertices(0),
@@ -136,71 +132,18 @@ void Model::drawBBox(const mat4& _modelMat, const vec4& _color) const
        getBBoxModel()->drawModel(Graphix::shader_BBox, NULL, _modelMat*translate(center)*glm::scale(size)); //
 }
 
-void Model::setBB(const Box& _box)
-{
-       box = _box;
-}
-
-void Model::setBB(const vec3& _min, const vec3& _max)
-{
-       box = Box((_min + _max) * .5f, (_max - _min) * .5f);
-}
-
-void Model::setBB(const uint _numvertices, const float* _vertices)
-{
-       vec3 BBmin = vec3(_vertices[0], _vertices[1], _vertices[2]);
-       vec3 BBmax = BBmin;
-       for (uint i = 3; i < _numvertices * 3; ++i)
-       {
-               if (_vertices[i] < BBmin[i % 3])
-                       BBmin[i % 3] = _vertices[i];
-               if (_vertices[i] > BBmax[i % 3])
-                       BBmax[i % 3] = _vertices[i];
-       }
-
-       box = Box((BBmin + BBmax) * .5f, (BBmax - BBmin) * .5f);
-}
-
-void Model::setBB(const uint _numvertices, const float* _vertices, const mat4& _modelMat)
-{
-       vec3 BBmin = (vec3)(_modelMat * vec4(_vertices[0], _vertices[1], _vertices[2], 1.f));
-       vec3 BBmax = BBmin;
-       vec3 tmpVert;
-       for (uint j = 3; j < _numvertices * 3; j += 3)
-       {
-               tmpVert = (vec3)(_modelMat * vec4(_vertices[j], _vertices[j + 1], _vertices[j + 2], 1));
-               for (uint i = 0; i < 3; ++i)
-               {
-                       if (tmpVert[i] < BBmin[i])
-                               BBmin[i] = tmpVert[i];
-                       if (tmpVert[i] > BBmax[i])
-                               BBmax[i] = tmpVert[i];
-               }
-       }
-
-       box = Box((BBmin + BBmax) * .5f, (BBmax - BBmin) * .5f);
-}
-
-void Model::updateBB(const Box& _box)
-{
-       box = Box::merge(box, _box);
-}
-
-//void Model::getBBmm(vec3& _min, vec3& _max) const
-//{
-//     _min = BBmin;
-//     _max = BBmax;
-//}
-
 void Model::getBBcs(vec3& _center, vec3& _size) const
 {
-       _size = box.size();
-       _center = box.center();
-}
+       btVector3 minB, maxB;
+       btTransform trans;
+       trans.setIdentity();
+       bt_collision_shape->getAabb(trans, minB, maxB);
 
-Box Model::getBBox() const
-{
-       return box;
+       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)
@@ -441,207 +384,3 @@ Model* Model::BoundingBox = nullptr;
 Model* Model::SkyBoxModel = nullptr;
 std::unordered_map<string, Model*> Model::IMetaModel;
 std::unordered_map<string, uint> Model::IMetaModel_count;
-
-// CLASS SPLITMAT
-
-SplitMat::SplitMat(const mat4& _model) : scale(getScale(_model)), model(removeScale(_model)), modelInv(inverse(model)), modelOrig(_model)
-{
-}
-
-SplitMat::~SplitMat()
-{
-}
-
-// CLASS TRIANGLE
-
-Triangle::Triangle(const mat3& _vertex, const vec3& _normal) : vertex(_vertex), normal(normalize(_normal))
-{
-}
-
-Triangle::~Triangle()
-{
-}
-
-void Triangle::getBBcs(vec3& center, vec3& size) const
-{
-       vec3 BBmin = vertex[0];
-       vec3 BBmax = BBmin;
-       getUBBmm(BBmin, BBmax);
-
-       size = (BBmax - BBmin) / 2.f;
-       center = (BBmin + BBmax) / 2.f;
-}
-
-void Triangle::getBBmm(vec3& min, vec3& max) const
-{
-       min = vertex[0];
-       max = min;
-       getUBBmm(min, max);
-}
-
-void Triangle::getUBBmm(vec3& min, vec3& max) const
-{
-       for (uint i = 0; i < 3; ++i)
-       {
-               for (uint j = 0; j < 3; ++j)
-               {
-                       if (vertex[i][j] < min[j])
-                               min[j] = vertex[i][j];
-                       if (vertex[i][j] > max[j])
-                               max[j] = vertex[i][j];
-               }
-       }
-}
-
-vec3 Triangle::getMean() const
-{
-       return (vertex[0] + vertex[1] + vertex[2]) / 3.f;
-}
-
-Triangle::operator Model::Box() const
-{
-       vec3 min = vertex[0];
-       vec3 max = min;
-       for (uint i = 0; i < 3; ++i)
-       {
-               for (uint j = 0; j < 3; ++j)
-               {
-                       if (vertex[i][j] < min[j])
-                               min[j] = vertex[i][j];
-                       if (vertex[i][j] > max[j])
-                               max[j] = vertex[i][j];
-               }
-       }
-       return Box((max + min)*.5f, (max - min)*.5f);
-}
-
-
-//CLASS BOX
-
-Box::Box() : cen(0.f), siz(0.f)
-{}
-
-Box::Box(const vec3& _center, const vec3& _size) : cen(_center), siz(_size)
-{
-}
-
-Box::~Box()
-{
-}
-
-void Box::update(const Box& _box)
-{
-       vec3 diff = _box.cen - cen;
-       float size;
-
-       for (int i = 0; i<3; ++i)
-       {
-               if (abs(siz[i] - _box.siz[i]) - abs(diff[i]) >= 0)
-               {
-                       if (siz[i] < _box.siz[i])
-                       {
-                               siz[i] = _box.siz[i];
-                               cen[i] = _box.cen[i];
-                       }
-               }
-               else
-               {
-                       size = (siz[i] + _box.siz[i] + abs(diff[i])) * .5f;
-                       cen[i] = cen[i] - sign(diff[i]) * (siz[i] - size);
-                       siz[i] = size;
-               }
-
-       }
-}
-
-
-void Box::getBBcs(vec3& _center, vec3& _size) const
-{
-       _center = cen;
-       _size = siz;
-}
-
-vec3 Box::center() const
-{
-       return cen;
-}
-
-vec3 Box::size() const
-{
-       return siz;
-}
-
-void Box::rotate(const mat4& _modelMat)
-{
-       //Rotate Center
-       cen = (vec3)(_modelMat*vec4(cen, 1.f));
-
-       //Rotate Size
-       vec3 newSize(0.f);
-       mat3 tmpModelMat(_modelMat);
-       for (auto i = 0; i < 3; ++i)
-               newSize += abs(tmpModelMat[i]) * siz[i];
-       siz = newSize;
-}
-
-void Box::scale(const vec3& _scale)
-{
-       for (uint i = 0; i < 3; ++i)
-       {
-               cen[i] *= _scale[i];
-               siz[i] *= _scale[i];
-       }
-}
-
-float Box::getDist(const vec3& _pos) const
-{
-       vec3 diff = _pos - cen;
-       vec3 direc = normalize(diff);
-
-       float size(0.f);
-       for (auto i = 0; i < 3; ++i)
-               size += abs(siz[i] * direc[i]);
-       return diff.length()-size;
-}
-
-float Box::getDist(const vec3& _pos, const vec3& _direc) const
-{
-       vec3 diff = _pos - cen;
-
-       float size(0.f);
-       for (auto i = 0; i < 3; ++i)
-               size += abs(siz[i] * _direc[i]);
-       return dot(diff,_direc) - size;
-}
-
-
-Box Box::merge(const Box& _boxA, const Box& _boxB)
-{
-       vec3 diff = _boxB.cen - _boxA.cen;
-       vec3 size;
-       vec3 center;
-
-       for (int i = 0; i<3; ++i)
-       {
-               if (abs(_boxA.siz[i] - _boxB.siz[i]) - abs(diff[i]) >= 0)
-               {
-                       if (_boxA.siz[i] > _boxB.siz[i])
-                       {
-                               size[i] = _boxA.siz[i];
-                               center[i] = _boxA.cen[i];
-                       }
-                       else
-                       {
-                               size[i] = _boxB.siz[i];
-                               center[i] = _boxB.cen[i];
-                       }
-               } 
-               else
-               {
-                       size[i] = (_boxA.siz[i] + _boxB.siz[i] + abs(diff[i])) * .5f;
-                       center[i] = _boxA.cen[i] - sign(diff[i]) * (_boxA.siz[i] - size[i]);
-               }
-
-       }
-       return Box(center,size);
-}
index d1851d1b1099201b5511d7dc69d4086c9c4795f5..356c478efbcb69c97392b795acdc6f204ac33333 100644 (file)
@@ -18,9 +18,6 @@ typedef unsigned int uint;
 class Model
 {
 public:
-       class Triangle;
-       class Box;
-       class SplitMat;
 
        /* Binds Model to the Model*/
        virtual void bindShader(Shader* shader);
@@ -36,9 +33,6 @@ public:
        /* Get size&position from BBox */
        void getBBcs(vec3& center, vec3& size) const;
 
-       /* Get center&size (BOX) */
-       Box getBBox() const;
-
        class Triangle;
 
        static Model* getBBoxModel();
@@ -55,71 +49,6 @@ public:
 
        virtual operator btCollisionShape*() const;
 
-       class SplitMat
-       {
-       public:
-               SplitMat(const mat4& model);
-               ~SplitMat();
-
-               mat4& getModelMat();
-
-       //protected:
-               const vec3 scale;
-               const mat4 model;
-               const mat4 modelInv;
-               const mat4 modelOrig;
-       };
-
-       class Triangle
-       {
-       public:
-               Triangle(const mat3& vertex, const vec3& normal);
-               Triangle(const Triangle& tri) = default;
-               ~Triangle();
-
-               /* sets center & size */
-               void getBBcs(vec3& center, vec3& size) const;
-               /* sets min & max */
-               void getBBmm(vec3& min, vec3& max) const;
-               /* updates min & max */
-               void getUBBmm(vec3& min, vec3& max) const;
-               /* get mean*/
-               vec3 getMean() const;
-
-               operator Box() const;
-
-               const mat3 vertex;
-               const vec3 normal;
-
-       };
-
-       class Box
-       {
-       public:
-               Box();
-               Box(const vec3& center, const vec3& size);
-               ~Box();
-
-               void update(const Box& box);
-
-               void getBBcs(vec3& center, vec3& size) const;
-
-               vec3 center() const;
-               vec3 size() const;
-
-               void rotate(const mat4& modelMat);
-               void scale(const vec3& scale);
-
-               float getDist(const vec3& pos) const;
-               float getDist(const vec3& pos, const vec3& direc) const;
-
-               static Box merge(const Box& boxA, const Box& boxB);
-
-       protected:
-               vec3 cen;
-               vec3 siz;
-       };
-
        // Mesh Speichern?
        static bool import(const std::string& modelpath, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, uint mindex = 0);
        static bool import(const aiMesh* mesh, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, const vec3& scale = vec3(1.f));
@@ -133,13 +62,6 @@ protected:
 
        std::unordered_map<uint, uint> shader_map;
 
-       void setBB(const Box& box);
-       void setBB(const vec3& min, const vec3& max);
-       void setBB(const uint numvertices, const float* vertices);
-       void setBB(const uint numvertices, const float* vertices, const mat4& modelMat);
-
-       void updateBB(const Box& box);
-
        void genBuffer(uint &buffer, uint size, void* value);
        void bindBuffer(const uint &buffer, const uint index, const uint dim = 3);
 
@@ -160,9 +82,5 @@ protected:
        btCollisionShape* bt_collision_shape;
 
 private:
-//     vec3 BBmin, BBmax;
-//     vec3 BBsize, BBposition;
-
-       Box box;
 
 };
\ No newline at end of file