[2823] | 1 | /*! |
---|
[3360] | 2 | \file model.h |
---|
| 3 | \brief Contains the Model Class that handles 3D-Models |
---|
[2823] | 4 | */ |
---|
| 5 | |
---|
[3360] | 6 | #ifndef _MODEL_H |
---|
| 7 | #define _MODEL_H |
---|
[2773] | 8 | |
---|
[4577] | 9 | #include "base_object.h" |
---|
[2776] | 10 | #include "material.h" |
---|
[3917] | 11 | #include "glincl.h" |
---|
[4577] | 12 | #include "array.h" |
---|
[2748] | 13 | |
---|
[4577] | 14 | |
---|
[3427] | 15 | // FORWARD DEFINITION // |
---|
| 16 | class Vector; |
---|
[4579] | 17 | template<class T> class Array; |
---|
[3910] | 18 | template<class T> class tList; |
---|
[3427] | 19 | |
---|
[3916] | 20 | //! an enumerator fot the different Model Types. |
---|
| 21 | /** |
---|
| 22 | MODEL_DISPLAY_LIST means, that a DisplayList will be built out of the model. This model will be STATIC, meaning it cannot be changed after initialisation. |
---|
| 23 | MODEL_VERTEX_ARRAY means, that a VertexArray will be built out of the model. This moel will be DYNAMIX, meaning that one can change the properties from outside of the model. |
---|
[4577] | 24 | * \todo implement this stuff |
---|
[3916] | 25 | */ |
---|
| 26 | typedef enum MODEL_TYPE {MODEL_DISPLAY_LIST, |
---|
[4577] | 27 | MODEL_VERTEX_ARRAY}; |
---|
[3910] | 28 | |
---|
| 29 | |
---|
[3657] | 30 | // definition of different modes for setting up Faces |
---|
| 31 | #define VERTEX 0 //!< If Faces are created WITH Vertex-Coordinate |
---|
| 32 | #define NORMAL 1 //!< If Faces are created WITH Normals (otherwise autocalculate) |
---|
| 33 | #define TEXCOORD 2 //!< If Faces are created WITH TextureCoordinate |
---|
[4468] | 34 | |
---|
[3894] | 35 | //! an enumerator for VERTEX_FORMAT |
---|
[4577] | 36 | typedef enum VERTEX_FORMAT { VERTEX_ONLY = VERTEX, |
---|
| 37 | VERTEX_NORMAL = NORMAL, |
---|
| 38 | VERTEX_TEXCOORD = TEXCOORD, |
---|
| 39 | VERTEX_TEXCOORD_NORMAL = NORMAL | TEXCOORD }; |
---|
[2842] | 40 | |
---|
[4022] | 41 | //////////////////// |
---|
| 42 | /// SUB-ELEMENTS /// |
---|
| 43 | //////////////////// |
---|
| 44 | //! This is the placeholder of one Vertex beloning to a Face. |
---|
| 45 | class ModelFaceElement |
---|
[2748] | 46 | { |
---|
[4022] | 47 | public: |
---|
| 48 | ModelFaceElement(); |
---|
| 49 | ~ModelFaceElement(); |
---|
[3063] | 50 | |
---|
[4577] | 51 | int vertexNumber; //!< The number of the Vertex out of the Array* vertices, this vertex points to. |
---|
| 52 | int normalNumber; //!< The number of the Normal out of the Array* normals, this vertex points to. |
---|
| 53 | int texCoordNumber; //!< The number of the textureCoordinate out of the Array* vTexture, this vertex points to. |
---|
[4468] | 54 | |
---|
[4577] | 55 | ModelFaceElement* next; //!< Point to the next FaceElement in this List. |
---|
[4022] | 56 | }; |
---|
[3063] | 57 | |
---|
[4022] | 58 | //! This is the placeholder of a Face belonging to a Group of Faces. |
---|
| 59 | class ModelFace |
---|
| 60 | { |
---|
| 61 | public: |
---|
| 62 | ModelFace(); |
---|
| 63 | ~ModelFace(); |
---|
[4577] | 64 | |
---|
| 65 | unsigned int vertexCount; //!< The Count of vertices this Face has. |
---|
[4468] | 66 | ModelFaceElement* firstElem; //!< Points to the first Vertex (FaceElement) of this Face. |
---|
| 67 | Material* material; //!< The Material to use. |
---|
[4577] | 68 | |
---|
[4468] | 69 | ModelFace* next; //!< Pointer to the next Face. |
---|
[4577] | 70 | }; |
---|
[3063] | 71 | |
---|
[4022] | 72 | //! Group to handle multiple Models per obj-file. |
---|
| 73 | class ModelGroup |
---|
| 74 | { |
---|
| 75 | public: |
---|
| 76 | ModelGroup(); |
---|
| 77 | ~ModelGroup(); |
---|
[2850] | 78 | |
---|
[4022] | 79 | void cleanup(); |
---|
[2850] | 80 | |
---|
[4468] | 81 | char* name; //!< the Name of the Group. this is an identifier, that can be accessed via the draw (char* name) function. |
---|
| 82 | GLubyte* indices; //!< The indices of the Groups. Needed for vertex-arrays |
---|
| 83 | GLuint listNumber; //!< The number of the GL-List this Group gets. |
---|
| 84 | ModelFace* firstFace; //!< The first Face in this group. |
---|
| 85 | ModelFace* currentFace; //!< The current Face in this Group (the one we are currently working with.) |
---|
| 86 | int faceMode; //!< The Mode the Face is in: initially -1, 0 for FaceList opened, 1 for Material, 3 for triangle, 4 for Quad, 5+ for Poly \todo ENUM... |
---|
| 87 | int faceCount; //!< The Number of Faces this Group holds. |
---|
[4577] | 88 | |
---|
[4468] | 89 | ModelGroup* next; //!< Pointer to the next Group. |
---|
[4022] | 90 | }; |
---|
[2850] | 91 | |
---|
[4022] | 92 | ///////////// |
---|
| 93 | /// MODEL /// |
---|
| 94 | ///////////// |
---|
| 95 | |
---|
| 96 | //! Class that handles 3D-Models. it can also read them in and display them. |
---|
[4577] | 97 | class Model : public BaseObject |
---|
[4022] | 98 | { |
---|
[3398] | 99 | public: |
---|
[3916] | 100 | Model(const char* modelName = NULL, MODEL_TYPE type = MODEL_DISPLAY_LIST); |
---|
[3910] | 101 | virtual ~Model(void); |
---|
| 102 | |
---|
| 103 | void draw(void) const; |
---|
| 104 | void draw(int groupNumber) const; |
---|
| 105 | void draw(char* groupName) const; |
---|
| 106 | |
---|
[4038] | 107 | /** \returns Count of the Models (Groups) in this File */ |
---|
[4577] | 108 | inline int getGroupCount(void) const { return this->groupCount; }; |
---|
[4038] | 109 | |
---|
[4577] | 110 | /** \returns a Pointer to the Vertex-Array, if it was deleted it returns NULL */ |
---|
| 111 | inline const GLfloat* getVertexArray(void) const { return this->vertices->getArray(); }; |
---|
| 112 | /** \returns the VertexCount of this Model */ |
---|
| 113 | inline unsigned int getVertexArrayCount(void) const { return this->vertexCount; }; |
---|
| 114 | |
---|
| 115 | /** \returns a Pointer to the Normals-Array, if it was deleted it returns NULL */ |
---|
| 116 | inline const GLfloat* getNormalsArray(void) const { return this->normals->getArray(); }; |
---|
| 117 | /** \returns the NormalsCount of this Model */ |
---|
| 118 | inline unsigned int getNormalsArrayCount(void) const { return this->normalCount; }; |
---|
| 119 | |
---|
| 120 | /** \returns a Pointer to the TexCoord-Array, if it was deleted it returns NULL */ |
---|
| 121 | inline const GLfloat* getTexCoordArray(void) const { return this->vTexture->getArray(); }; |
---|
| 122 | /** \returns the TexCoord-Count of this Model */ |
---|
| 123 | inline unsigned int getTexCoordArrayCount(void) const { return this->texCoordCount; }; |
---|
| 124 | |
---|
| 125 | |
---|
[3913] | 126 | Material* addMaterial(Material* material); |
---|
| 127 | Material* addMaterial(const char* materialName); |
---|
| 128 | |
---|
[3894] | 129 | bool addGroup(const char* groupString); |
---|
[3909] | 130 | bool addVertex(const char* vertexString); |
---|
[3894] | 131 | bool addVertex(float x, float y, float z); |
---|
[3909] | 132 | bool addFace(const char* faceString); |
---|
[3895] | 133 | bool addFace(int faceElemCount, VERTEX_FORMAT type, ...); |
---|
[3909] | 134 | bool addVertexNormal(const char* normalString); |
---|
[3894] | 135 | bool addVertexNormal(float x, float y, float z); |
---|
[3909] | 136 | bool addVertexTexture(const char* vTextureString); |
---|
[3894] | 137 | bool addVertexTexture(float u, float v); |
---|
[3913] | 138 | bool setMaterial(const char* mtlString); |
---|
| 139 | bool setMaterial(Material* mtl); |
---|
[3398] | 140 | void finalize(void); |
---|
[4106] | 141 | |
---|
| 142 | /** \returns The number of Vertices of the Model */ |
---|
| 143 | inline int getVertexCount(void) const {return this->vertexCount;} |
---|
| 144 | /** \returns The number of Normals of the Model */ |
---|
| 145 | inline int getNormalCount(void) const {return this->normalCount;} |
---|
| 146 | /** \returns The number of Texture Coordinates of the Model*/ |
---|
| 147 | inline int getTexCoordCount(void) const {return this->texCoordCount;} |
---|
[4468] | 148 | |
---|
| 149 | protected: |
---|
| 150 | void cubeModel(void); |
---|
| 151 | |
---|
| 152 | Material* findMaterialByName(const char* materialName); |
---|
| 153 | |
---|
[4529] | 154 | |
---|
| 155 | protected: |
---|
| 156 | float scaleFactor; //!< The Factor with which the Model should be scaled. \todo maybe one wants to scale the Model after Initialisation |
---|
| 157 | |
---|
[4468] | 158 | private: |
---|
| 159 | bool buildVertexNormals(void); |
---|
| 160 | |
---|
| 161 | bool importToDisplayList(void); |
---|
| 162 | bool addGLElement(ModelFaceElement* elem); |
---|
| 163 | |
---|
| 164 | bool importToVertexArray(void); |
---|
| 165 | |
---|
| 166 | bool deleteArrays(void); |
---|
| 167 | bool cleanup(void); |
---|
| 168 | |
---|
| 169 | private: |
---|
| 170 | MODEL_TYPE type; //!< A type for the Model |
---|
| 171 | bool finalized; //!< Sets the Object to be finalized. |
---|
| 172 | |
---|
[4577] | 173 | unsigned int vertexCount; //!< A modelwide Counter for vertices. |
---|
| 174 | unsigned int normalCount; //!< A modelwide Counter for the normals. |
---|
| 175 | unsigned int texCoordCount; //!< A modelwide Counter for the texCoord. |
---|
[4579] | 176 | Array<GLfloat>* vertices; //!< The Array that handles the Vertices. |
---|
| 177 | Array<GLfloat>* normals; //!< The Array that handles the Normals. |
---|
| 178 | Array<GLfloat>* vTexture; //!< The Array that handles the VertexTextureCoordinates. |
---|
[4468] | 179 | |
---|
| 180 | ModelGroup* firstGroup; //!< The first of all groups. |
---|
| 181 | ModelGroup* currentGroup; //!< The currentGroup. this is the one we will work with. |
---|
[4529] | 182 | int groupCount; //!< The Count of Groups. |
---|
[4468] | 183 | |
---|
| 184 | tList<Material>* materialList; //!< A list for all the Materials in this Model |
---|
[2748] | 185 | }; |
---|
[2773] | 186 | |
---|
| 187 | #endif |
---|