]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
fixed BBox size and position
authorPeter Schaefer <schaeferpm@gmail.com>
Sun, 26 Apr 2015 14:24:42 +0000 (16:24 +0200)
committerPeter Schaefer <schaeferpm@gmail.com>
Sun, 26 Apr 2015 14:24:42 +0000 (16:24 +0200)
Weave/Graphix/Model/BBox.cpp
Weave/Graphix/Model/IMesh.cpp
Weave/Graphix/Model/Model.cpp
Weave/Graphix/Model/Model.h
winrar.bat

index 27ca798137611dae847749c01660029ace9e3624..2f04e36ca2337dbb4b8eed244a549fb7838a29c4 100644 (file)
@@ -1,9 +1,6 @@
 #include "BBox.h"
 #include "GL\glew.h"
 
-uint indexL1[4]{ 0, 1, 2, 3 },
-indexL2[4]{ 4, 5, 6, 7},
-indexS1[8]{0, 4, 1, 5, 2, 6, 3, 7};
 
 BBox::BBox()
 {
@@ -25,6 +22,10 @@ BBox::~BBox()
 
 void BBox::drawModel() const
 {
+       uint indexL1[4]{ 0, 1, 2, 3 },
+               indexL2[4]{ 4, 5, 6, 7},
+               indexS1[8]{0, 4, 1, 5, 2, 6, 3, 7};
+
        //glDrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_INT, 0);
        glDrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_INT, indexL1);
        glDrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_INT, indexL2);
index e7fabee8212dbc24da981a46c72ce4991bbfadc7..37264f501a98ff917289fa606d4999267959f601 100644 (file)
@@ -21,7 +21,7 @@ IMesh::IMesh(const string& _modelpath, uint _mindex)
 
        import(_modelpath, numvertices, numfaces, vertex, uvs, normals, index, _mindex);
 
-       updateBB(vertex);
+       updateBB(numvertices,vertex);
 
        genBuffer(vertexBuffer, numvertices * 3 * sizeof(float), (void*)vertex);
        genBuffer(normalBuffer, numvertices * 3 * sizeof(float), (void*)normals);
@@ -40,7 +40,7 @@ IMesh::IMesh(const aiMesh* _mesh, const mat4& _transformation) : modelMat(_trans
 
        import(_mesh, numvertices, numfaces, vertex, uvs, normals, index);
 
-       updateBB(vertex);
+       updateBB(numvertices,vertex,modelMat);
 
        genBuffer(vertexBuffer, numvertices * 3 * sizeof(float), (void*)vertex);
        genBuffer(normalBuffer, numvertices * 3 * sizeof(float), (void*)normals);
index 6219431cc0cd50edba96d1e2187ce6e4cd159939..6031d9246ff3b2c0089f01377d96122908a539ab 100644 (file)
@@ -123,11 +123,11 @@ void Model::updateBB(const vec3& _min, const vec3& _max)
        BBposition = (_min + _max) / 2.f;
 }
 
-void Model::updateBB(const float* _vertices)
+void Model::updateBB(const uint _numvertices, const float* _vertices)
 {
        BBmin = vec3(_vertices[0], _vertices[1], _vertices[2]);
        BBmax = BBmin;
-       for (auto i = 3; i < numvertices * 3; ++i)
+       for (auto i = 3; i < _numvertices * 3; ++i)
        {
                if (_vertices[i] < BBmin[i % 3])
                        BBmin[i % 3] = _vertices[i];
@@ -139,6 +139,27 @@ void Model::updateBB(const float* _vertices)
        BBposition = (BBmin + BBmax) / 2.f;
 }
 
+void Model::updateBB(const uint _numvertices, const float* _vertices, const mat4& _modelMat)
+{
+       BBmin = (vec3)(_modelMat * vec4(_vertices[0], _vertices[1], _vertices[2],1.f));
+       BBmax = BBmin;
+       vec3 tmpVert;
+       for (auto j = 3; j < _numvertices * 3; j += 3)
+       {
+               tmpVert = (vec3)(_modelMat * vec4(_vertices[j], _vertices[j + 1], _vertices[j + 2], 1));
+               for (auto i = 0; i < 3; ++i)
+               {
+                       if (tmpVert[i] < BBmin[i])
+                               BBmin[i] = tmpVert[i];
+                       if (tmpVert[i] > BBmax[i])
+                               BBmax[i] = tmpVert[i];
+               }
+       }
+
+       BBsize = BBmax - BBmin;
+       BBposition = (BBmin + BBmax) / 2.f;
+}
+
 
 void Model::getBBmm(vec3& _min, vec3& _max) const
 {
index ea5645e47a82dda31fd627eb787faa16bdf53a4a..af8a43e157522cf4ff06c59c9ab077f80381f8f9 100644 (file)
@@ -33,7 +33,8 @@ protected:
        std::unordered_map<uint, uint> shader_map;
 
        void updateBB(const vec3& min, const vec3& max);
-       void updateBB(const float* vertices);
+       void updateBB(const uint numvertices, const float* vertices);
+       void updateBB(const uint numvertices, const float* vertices, const mat4& modelMat);
 
        void genBuffer(uint &buffer, uint size, void* value);
        void bindBuffer(const uint &buffer, const uint index, const uint dim = 3);
index 9ae18d0bad00a7727afe8585eb33e120c6b7929e..419a207a05cfdb3fc65608f640a661489c8636fe 100644 (file)
@@ -1,5 +1,5 @@
 @echo off
 
-C:\Programme\WinRar\rar a -r -x*.blend -x*.blend* -x*.pdb -x*.psb -x*.psd CGUE.zip textures models shader bin
+C:\Programme\WinRar\rar a -r -x*.blend -x*.blend* -x*.pdb -x*.psb -x*.psd CGUE.rar textures models shader bin
 
 #pause
\ No newline at end of file