00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef CAJUN_MODEL_H
00016 #define CAJUN_MODEL_H
00017
00018 #include<GL/glut.h>
00019 #include<iostream>
00020
00021 #ifdef VR_JUGGLER
00022 #include <vrj/Draw/OGL/GlContextData.h>
00023 #endif
00024
00025 class Model
00026 {
00027 public:
00028 struct texture_t
00029 {
00030 texture_t () : image_data (NULL), width (0), height (0) {}
00031 unsigned char *image_data;
00032 unsigned width;
00033 unsigned height;
00034 };
00035
00036
00037 struct Mesh
00038 {
00039 int m_materialIndex;
00040 int m_numTriangles;
00041 int *m_pTriangleIndices;
00042 };
00043
00044
00045 struct Material
00046 {
00047 float m_ambient[4], m_diffuse[4], m_specular[4], m_emissive[4];
00048 float m_shininess;
00049 #ifdef VR_JUGGLER
00050 vrj::GlContextData<GLuint> m_texture;
00051 #else
00052 GLuint m_texture;
00053 #endif
00054 char *m_pTextureFilename;
00055 texture_t texture;
00056 };
00057
00058
00059 struct Triangle
00060 {
00061 float m_vertexNormals[3][3];
00062 float m_s[3], m_t[3];
00063 int m_vertexIndices[3];
00064 };
00065
00066
00067 struct Vertex
00068 {
00069 char m_boneID;
00070 float m_location[3];
00071 };
00072
00073 public:
00074
00075 Model();
00076
00077
00078 virtual ~Model();
00079
00080
00081
00082
00083
00084 virtual bool loadModelData( const char *filename ) = 0;
00085
00086
00087 void draw();
00088 void draw_mesh();
00089
00090
00091
00092
00093
00094 void reloadTextures();
00095 void Init ();
00096
00097 void load_ppm_p6 (char *fname, unsigned int *w, unsigned int *h,
00098 unsigned char **data, int mallocflag);
00099 void load_ppm_p3 (char *fname, unsigned int *w, unsigned int *h,
00100 unsigned char **data, int mallocflag);
00101
00102 GLuint LoadGLTexture (const unsigned char *image_data_,
00103 unsigned int tex_width_,
00104 unsigned int tex_height_);
00105
00106 protected:
00107
00108 #ifdef VR_JUGGLER
00109 vrj::GlContextData<GLuint> list_num;
00110 #else
00111 GLuint list_num;
00112 #endif
00113 int m_numMeshes;
00114 Mesh *m_pMeshes;
00115
00116
00117 int m_numMaterials;
00118 Material *m_pMaterials;
00119
00120
00121 int m_numTriangles;
00122 Triangle *m_pTriangles;
00123
00124
00125 int m_numVertices;
00126 Vertex *m_pVertices;
00127
00128 char const *progname;
00129 };
00130
00131 #endif // ndef MODEL_H