From 3506ad6b57642922cb049e718f9d55e63905aad0 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 20 Apr 2011 11:34:02 -0400 Subject: [PATCH] update updateAABB() --- WFObj.cc | 49 ++++++++++++++++++++++++++----------------------- WFObj.h | 2 +- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/WFObj.cc b/WFObj.cc index 9dd8c6b..690aa09 100644 --- a/WFObj.cc +++ b/WFObj.cc @@ -227,32 +227,35 @@ void WFObj::processInputLine(const std::string & input) } } -void WFObj::updateAABB(const float * const vertex) +void WFObj::updateAABB() { -#ifdef TODO - if (m_loadedVertex) + bool firstVertex = true; + for (int i = 0, sz = m_vertices[VERTEX].size(); i < sz; i++) { - if (vertex[0] < m_aabb[0]) - m_aabb[0] = vertex[0]; - else if (vertex[0] > m_aabb[3]) - m_aabb[3] = vertex[0]; - if (vertex[1] < m_aabb[1]) - m_aabb[1] = vertex[1]; - else if (vertex[1] > m_aabb[4]) - m_aabb[4] = vertex[1]; - if (vertex[2] < m_aabb[2]) - m_aabb[2] = vertex[2]; - else if (vertex[2] > m_aabb[5]) - m_aabb[5] = vertex[2]; + Vertex & v = m_vertices[VERTEX][i]; + if (firstVertex) + { + m_aabb[0] = m_aabb[3] = v[0]; + m_aabb[1] = m_aabb[4] = v[1]; + m_aabb[2] = m_aabb[5] = v[2]; + firstVertex = false; + } + else + { + if (v[0] < m_aabb[0]) + m_aabb[0] = v[0]; + else if (v[0] > m_aabb[3]) + m_aabb[3] = v[0]; + if (v[1] < m_aabb[1]) + m_aabb[1] = v[1]; + else if (v[1] > m_aabb[4]) + m_aabb[4] = v[1]; + if (v[2] < m_aabb[2]) + m_aabb[2] = v[2]; + else if (v[2] > m_aabb[5]) + m_aabb[5] = v[2]; + } } - else - { - m_aabb[0] = m_aabb[3] = vertex[0]; - m_aabb[1] = m_aabb[4] = vertex[1]; - m_aabb[2] = m_aabb[5] = vertex[2]; - m_loadedVertex = true; - } -#endif } WFObj::Vertex WFObj::readVertex(const vector & parts) diff --git a/WFObj.h b/WFObj.h index 9e5cae5..02375d5 100644 --- a/WFObj.h +++ b/WFObj.h @@ -65,7 +65,7 @@ protected: Vertex readVertex(const std::vector & parts); std::vector readFaces(const std::vector & parts); VertexRef readVertexRef(const std::string ref); - void updateAABB(const float * const vertex); + void updateAABB(); static bool loadfile(const char *path, Buffer *buff); std::string getLine(const Buffer & buff, size_t idx, size_t *update_idx); void loadMaterial(const std::string & name);