added axis-aligned bounding box computation and retrieval function

git-svn-id: svn://anubis/misc/wfobj@40 bd8a9e45-a331-0410-811e-c64571078777
This commit is contained in:
josh 2008-02-20 02:46:32 +00:00
parent 85c451e8c2
commit 9c3944c98e
2 changed files with 33 additions and 2 deletions

View File

@ -72,6 +72,7 @@ static string basePath(const string & str)
void WFObj::clear()
{
m_data = std::vector< std::vector<std::string> >();
m_loadedVertex = false;
}
int WFObj::filesize(const char * filename)
@ -304,6 +305,32 @@ GLuint WFObj::render()
return list;
}
void WFObj::updateAABB(const float * const vertex)
{
if (m_loadedVertex)
{
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];
}
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;
}
}
WFObj::Vertex WFObj::readVertex(const vector<string> & parts)
{
int partslen = parts.size();

View File

@ -10,8 +10,9 @@ public:
typedef GLuint (*loadTextureFunc_t)(const char * texture);
bool load(const std::string & filename, loadTextureFunc_t loadTexture);
GLuint render();
const float * const getAABB() { return m_aabb; }
private:
protected:
/* types */
class Vertex
{
@ -29,11 +30,14 @@ private:
void processInputLine(const std::string & input);
Vertex readVertex(const std::vector<std::string> & parts);
void parseVertexIndices(const std::string & vtxref, int * ret);
void updateAABB(const float * const vertex);
/* variables */
std::vector< std::vector<std::string> > m_data;
loadTextureFunc_t m_loadTexture;
std::string m_fileName;
float m_aabb[6];
bool m_loadedVertex;
};
@ -44,7 +48,7 @@ public:
void renderBegin(const std::string & mtlname);
void renderEnd(const std::string & mtlname);
private:
protected:
/* methods */
void clear();
int filesize(const char * filename);