1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef _OBJFILE_H
#define _OBJFILE_H
#include "vector.h"
#include <string>
#include <vector>
#include "SDL_opengl.h"
using namespace std;
class ObjFile
{
public:
ObjFile();
ObjFile( string filename );
bool load( string filename );
void build();
void unbuild();
void draw();
void findNorms();
void enableTexture();
void disableTexture();
Vector scale();
void setScale( Vector newscale );
void setRecenter( bool newcentx, bool newcenty, bool newcentz );
protected:
bool loaded;
bool usetexture;
bool centx, centy, centz;
bool built;
GLuint displist;
unsigned int numvertices, numfaces, numnormals, numtextcoords;
Vector scl;
// Storage for all vertices that are used to make faces
struct Point {
double x, y, z;
void glVertex() { glVertex3d( x, y, z ); }
void glTexCoord() { glTexCoord3d( x, 1-y, z ); }
};
vector< Point > vertices;
vector< Point > textcoords;
vector< vector< Point > > facevertextextcoords;
// Storage for different types of normals
vector< Vector > facenormals;
vector< vector< Vector > > facevertexnormals;
vector< Vector > vertexnormals;
vector< Vector > normals;
// List of faces that use a specific vertex
vector< vector< int > > vertexuse;
// List of vertices that a face uses
vector< vector< int > > faceuse;
};
#endif
|