fix compilation errors; compiling!

This commit is contained in:
Josh Holtrop 2011-04-19 17:05:17 -04:00
parent 18c4be6a42
commit 51c0ded005
2 changed files with 29 additions and 13 deletions

View File

@ -3,8 +3,9 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <ctype.h> // isspace() #include <ctype.h> /* isspace() */
#include <string.h> // strlen() #include <string.h> /* strlen() */
#include <stdlib.h> /* atoi */
#include <GL/gl.h> #include <GL/gl.h>
#include <vector> #include <vector>
#include <string> #include <string>
@ -125,9 +126,9 @@ bool WFObj::load(const WFObj::Buffer &buff)
{ {
string buildup; string buildup;
size_t idx = 0; size_t idx = 0;
while (idx < buff.size) while (idx < buff.length)
{ {
string line = getLine(buff, idx, &idx) string line = getLine(buff, idx, &idx);
string input = trimString(line); string input = trimString(line);
int sz = input.size(); int sz = input.size();
if (sz == 0 || input[0] == '#') if (sz == 0 || input[0] == '#')
@ -148,7 +149,7 @@ bool WFObj::load(const WFObj::Buffer &buff)
return true; return true;
} }
string WFObj::getLine(const Buff & buff, size_t idx, size_t *update_idx) string WFObj::getLine(const Buffer & buff, size_t idx, size_t *update_idx)
{ {
size_t len = 0; size_t len = 0;
while (idx + len < buff.length) while (idx + len < buff.length)
@ -198,7 +199,9 @@ void WFObj::processInputLine(const std::string & input)
{ {
if (m_faces.find(m_current_material_name) == m_faces.end()) if (m_faces.find(m_current_material_name) == m_faces.end())
m_faces[m_current_material_name] = vector<Face>(); m_faces[m_current_material_name] = vector<Face>();
m_faces[m_current_material_name].push_back(readFace(tokens)); vector<Face> faces = readFaces(tokens);
for (vector<Face>::iterator it = faces.begin(); it != faces.end(); it++)
m_faces[m_current_material_name].push_back(*it);
} }
else if (type == "usemtl") else if (type == "usemtl")
{ {
@ -226,6 +229,7 @@ void WFObj::processInputLine(const std::string & input)
void WFObj::updateAABB(const float * const vertex) void WFObj::updateAABB(const float * const vertex)
{ {
#ifdef TODO
if (m_loadedVertex) if (m_loadedVertex)
{ {
if (vertex[0] < m_aabb[0]) if (vertex[0] < m_aabb[0])
@ -248,6 +252,7 @@ void WFObj::updateAABB(const float * const vertex)
m_aabb[2] = m_aabb[5] = vertex[2]; m_aabb[2] = m_aabb[5] = vertex[2];
m_loadedVertex = true; m_loadedVertex = true;
} }
#endif
} }
WFObj::Vertex WFObj::readVertex(const vector<string> & parts) WFObj::Vertex WFObj::readVertex(const vector<string> & parts)
@ -308,3 +313,13 @@ WFObj::VertexRef WFObj::readVertexRef(const std::string ref)
} }
return fr; return fr;
} }
void WFObj::loadMaterial(const std::string & name)
{
/* TODO */
}
bool WFObj::loadfile(const char *path, Buffer *buff)
{
/* TODO */
}

15
WFObj.h
View File

@ -11,9 +11,6 @@ class WFObj
{ {
public: public:
/* types */ /* types */
typedef bool (*loadfile_t)(const char *fname, Buffer *buff);
typedef GLuint (*loadtexture_t)(const char *fname);
class Buffer class Buffer
{ {
public: public:
@ -21,6 +18,9 @@ public:
size_t length; size_t length;
}; };
typedef bool (*loadfile_t)(const char *fname, Buffer *buff);
typedef GLuint (*loadtexture_t)(const char *fname);
enum { VERTEX, VERTEX_TEXTURE, VERTEX_NORMAL, VERTEX_TYPES }; enum { VERTEX, VERTEX_TEXTURE, VERTEX_NORMAL, VERTEX_TYPES };
/* constructors */ /* constructors */
@ -66,14 +66,15 @@ protected:
std::vector<Face> readFaces(const std::vector<std::string> & parts); std::vector<Face> readFaces(const std::vector<std::string> & parts);
VertexRef readVertexRef(const std::string ref); VertexRef readVertexRef(const std::string ref);
void updateAABB(const float * const vertex); void updateAABB(const float * const vertex);
static Buffer loadfile(const char *path); static bool loadfile(const char *path, Buffer *buff);
std::string getLine(const Buff & buff, size_t idx, size_t *update_idx); std::string getLine(const Buffer & buff, size_t idx, size_t *update_idx);
void loadMaterial(const std::string & name);
/* variables */ /* variables */
std::vector<Vector> m_vertices[VERTEX_TYPES]; std::vector<Vertex> m_vertices[VERTEX_TYPES];
std::map< std::string, std::vector< Face > > m_faces; std::map< std::string, std::vector< Face > > m_faces;
FileLoader::Path m_path;
float m_aabb[6]; float m_aabb[6];
std::string m_path;
loadfile_t m_loadfile; loadfile_t m_loadfile;
loadtexture_t m_loadtexture; loadtexture_t m_loadtexture;
std::string m_current_material_name; std::string m_current_material_name;