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:
parent
85c451e8c2
commit
9c3944c98e
27
WFObj.cc
27
WFObj.cc
@ -72,6 +72,7 @@ static string basePath(const string & str)
|
|||||||
void WFObj::clear()
|
void WFObj::clear()
|
||||||
{
|
{
|
||||||
m_data = std::vector< std::vector<std::string> >();
|
m_data = std::vector< std::vector<std::string> >();
|
||||||
|
m_loadedVertex = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WFObj::filesize(const char * filename)
|
int WFObj::filesize(const char * filename)
|
||||||
@ -304,6 +305,32 @@ GLuint WFObj::render()
|
|||||||
return list;
|
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)
|
WFObj::Vertex WFObj::readVertex(const vector<string> & parts)
|
||||||
{
|
{
|
||||||
int partslen = parts.size();
|
int partslen = parts.size();
|
||||||
|
8
WFObj.hh
8
WFObj.hh
@ -10,8 +10,9 @@ public:
|
|||||||
typedef GLuint (*loadTextureFunc_t)(const char * texture);
|
typedef GLuint (*loadTextureFunc_t)(const char * texture);
|
||||||
bool load(const std::string & filename, loadTextureFunc_t loadTexture);
|
bool load(const std::string & filename, loadTextureFunc_t loadTexture);
|
||||||
GLuint render();
|
GLuint render();
|
||||||
|
const float * const getAABB() { return m_aabb; }
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
/* types */
|
/* types */
|
||||||
class Vertex
|
class Vertex
|
||||||
{
|
{
|
||||||
@ -29,11 +30,14 @@ private:
|
|||||||
void processInputLine(const std::string & input);
|
void processInputLine(const std::string & input);
|
||||||
Vertex readVertex(const std::vector<std::string> & parts);
|
Vertex readVertex(const std::vector<std::string> & parts);
|
||||||
void parseVertexIndices(const std::string & vtxref, int * ret);
|
void parseVertexIndices(const std::string & vtxref, int * ret);
|
||||||
|
void updateAABB(const float * const vertex);
|
||||||
|
|
||||||
/* variables */
|
/* variables */
|
||||||
std::vector< std::vector<std::string> > m_data;
|
std::vector< std::vector<std::string> > m_data;
|
||||||
loadTextureFunc_t m_loadTexture;
|
loadTextureFunc_t m_loadTexture;
|
||||||
std::string m_fileName;
|
std::string m_fileName;
|
||||||
|
float m_aabb[6];
|
||||||
|
bool m_loadedVertex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -44,7 +48,7 @@ public:
|
|||||||
void renderBegin(const std::string & mtlname);
|
void renderBegin(const std::string & mtlname);
|
||||||
void renderEnd(const std::string & mtlname);
|
void renderEnd(const std::string & mtlname);
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
/* methods */
|
/* methods */
|
||||||
void clear();
|
void clear();
|
||||||
int filesize(const char * filename);
|
int filesize(const char * filename);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user