wfobj/WFObj.hh
josh 9c3944c98e added axis-aligned bounding box computation and retrieval function
git-svn-id: svn://anubis/misc/wfobj@40 bd8a9e45-a331-0410-811e-c64571078777
2008-02-20 02:46:32 +00:00

65 lines
1.5 KiB
C++

#include <GL/gl.h>
#include <vector>
#include <string>
#include <map>
class WFObj
{
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; }
protected:
/* types */
class Vertex
{
public:
float operator[](int idx) const { return data[idx]; }
const float & operator[](int idx) { return data[idx]; }
float * getData() { return data; }
private:
float data[4];
};
/* methods */
void clear();
int filesize(const char * filename);
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;
};
class WFMtl
{
public:
bool load(const std::string & filename, WFObj::loadTextureFunc_t loadTexture);
void renderBegin(const std::string & mtlname);
void renderEnd(const std::string & mtlname);
protected:
/* methods */
void clear();
int filesize(const char * filename);
void processInputLine(const std::string & input);
void pushAttributes();
/* variables */
std::map< std::string, std::vector< std::vector<std::string> > > m_data;
std::string m_currentMaterialName;
bool m_attributesPushed;
WFObj::loadTextureFunc_t m_loadTexture;
std::string m_fileName;
};