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