From: Peter Schaefer Date: Sun, 26 Apr 2015 14:24:42 +0000 (+0200) Subject: fixed BBox size and position X-Git-Url: https://git.leopard-lacewing.eu/?a=commitdiff_plain;h=fd2f3ceb73ed0616d1dffccc8cbfbabb353f4c8a;p=cgue_weave.git fixed BBox size and position --- diff --git a/Weave/Graphix/Model/BBox.cpp b/Weave/Graphix/Model/BBox.cpp index 27ca798..2f04e36 100644 --- a/Weave/Graphix/Model/BBox.cpp +++ b/Weave/Graphix/Model/BBox.cpp @@ -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); diff --git a/Weave/Graphix/Model/IMesh.cpp b/Weave/Graphix/Model/IMesh.cpp index e7fabee..37264f5 100644 --- a/Weave/Graphix/Model/IMesh.cpp +++ b/Weave/Graphix/Model/IMesh.cpp @@ -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); diff --git a/Weave/Graphix/Model/Model.cpp b/Weave/Graphix/Model/Model.cpp index 6219431..6031d92 100644 --- a/Weave/Graphix/Model/Model.cpp +++ b/Weave/Graphix/Model/Model.cpp @@ -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 { diff --git a/Weave/Graphix/Model/Model.h b/Weave/Graphix/Model/Model.h index ea5645e..af8a43e 100644 --- a/Weave/Graphix/Model/Model.h +++ b/Weave/Graphix/Model/Model.h @@ -33,7 +33,8 @@ protected: std::unordered_map 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); diff --git a/winrar.bat b/winrar.bat index 9ae18d0..419a207 100644 --- a/winrar.bat +++ b/winrar.bat @@ -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