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