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 "base_object.h" |
---|
10 | #include "material.h" |
---|
11 | #include "glincl.h" |
---|
12 | #include "array.h" |
---|
13 | |
---|
14 | |
---|
15 | // FORWARD DEFINITION // |
---|
16 | class Vector; |
---|
17 | template<class T> class Array; |
---|
18 | template<class T> class tList; |
---|
19 | |
---|
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. |
---|
24 | * \todo implement this stuff |
---|
25 | */ |
---|
26 | typedef enum MODEL_TYPE {MODEL_DISPLAY_LIST, |
---|
27 | MODEL_VERTEX_ARRAY}; |
---|
28 | |
---|
29 | |
---|
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 |
---|
34 | |
---|
35 | //! an enumerator for VERTEX_FORMAT |
---|
36 | typedef enum VERTEX_FORMAT { VERTEX_ONLY = VERTEX, |
---|
37 | VERTEX_NORMAL = NORMAL, |
---|
38 | VERTEX_TEXCOORD = TEXCOORD, |
---|
39 | VERTEX_TEXCOORD_NORMAL = NORMAL | TEXCOORD }; |
---|
40 | |
---|
41 | //////////////////// |
---|
42 | /// SUB-ELEMENTS /// |
---|
43 | //////////////////// |
---|
44 | //! This is the placeholder of one Vertex beloning to a Face. |
---|
45 | class ModelFaceElement |
---|
46 | { |
---|
47 | public: |
---|
48 | ModelFaceElement(); |
---|
49 | ~ModelFaceElement(); |
---|
50 | |
---|
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. |
---|
54 | |
---|
55 | ModelFaceElement* next; //!< Point to the next FaceElement in this List. |
---|
56 | }; |
---|
57 | |
---|
58 | //! This is the placeholder of a Face belonging to a Group of Faces. |
---|
59 | class ModelFace |
---|
60 | { |
---|
61 | public: |
---|
62 | ModelFace(); |
---|
63 | ~ModelFace(); |
---|
64 | |
---|
65 | unsigned int vertexCount; //!< The Count of vertices this Face has. |
---|
66 | ModelFaceElement* firstElem; //!< Points to the first Vertex (FaceElement) of this Face. |
---|
67 | Material* material; //!< The Material to use. |
---|
68 | |
---|
69 | ModelFace* next; //!< Pointer to the next Face. |
---|
70 | }; |
---|
71 | |
---|
72 | //! Group to handle multiple Models per obj-file. |
---|
73 | class ModelGroup |
---|
74 | { |
---|
75 | public: |
---|
76 | ModelGroup(); |
---|
77 | ~ModelGroup(); |
---|
78 | |
---|
79 | void cleanup(); |
---|
80 | |
---|
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. |
---|
88 | |
---|
89 | ModelGroup* next; //!< Pointer to the next Group. |
---|
90 | }; |
---|
91 | |
---|
92 | ///////////// |
---|
93 | /// MODEL /// |
---|
94 | ///////////// |
---|
95 | |
---|
96 | //! Class that handles 3D-Models. it can also read them in and display them. |
---|
97 | class Model : public BaseObject |
---|
98 | { |
---|
99 | public: |
---|
100 | Model(const char* modelName = NULL, MODEL_TYPE type = MODEL_DISPLAY_LIST); |
---|
101 | virtual ~Model(); |
---|
102 | |
---|
103 | void draw() const; |
---|
104 | void draw(int groupNumber) const; |
---|
105 | void draw(char* groupName) const; |
---|
106 | |
---|
107 | /** \returns Count of the Models (Groups) in this File */ |
---|
108 | inline int getGroupCount() const { return this->groupCount; }; |
---|
109 | |
---|
110 | /** \returns a Pointer to the Vertex-Array, if it was deleted it returns NULL */ |
---|
111 | inline const GLfloat* getVertexArray() const { return this->vertices->getArray(); }; |
---|
112 | /** \returns the VertexCount of this Model */ |
---|
113 | inline unsigned int getVertexCount() 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() const { return this->normals->getArray(); }; |
---|
117 | /** \returns the NormalsCount of this Model */ |
---|
118 | inline unsigned int getNormalsCount() 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() const { return this->vTexture->getArray(); }; |
---|
122 | /** \returns the TexCoord-Count of this Model */ |
---|
123 | inline unsigned int getTexCoordCount() const { return this->texCoordCount; }; |
---|
124 | |
---|
125 | /** \returns the Count of Faces of this Model */ |
---|
126 | inline unsigned int getFaceCount() const { return this->faceCount; }; |
---|
127 | |
---|
128 | |
---|
129 | Material* addMaterial(Material* material); |
---|
130 | Material* addMaterial(const char* materialName); |
---|
131 | |
---|
132 | bool addGroup(const char* groupString); |
---|
133 | bool addVertex(const char* vertexString); |
---|
134 | bool addVertex(float x, float y, float z); |
---|
135 | bool addFace(const char* faceString); |
---|
136 | bool addFace(int faceElemCount, VERTEX_FORMAT type, ...); |
---|
137 | bool addVertexNormal(const char* normalString); |
---|
138 | bool addVertexNormal(float x, float y, float z); |
---|
139 | bool addVertexTexture(const char* vTextureString); |
---|
140 | bool addVertexTexture(float u, float v); |
---|
141 | bool setMaterial(const char* mtlString); |
---|
142 | bool setMaterial(Material* mtl); |
---|
143 | void finalize(); |
---|
144 | |
---|
145 | |
---|
146 | protected: |
---|
147 | void cubeModel(); |
---|
148 | |
---|
149 | Material* findMaterialByName(const char* materialName); |
---|
150 | |
---|
151 | |
---|
152 | protected: |
---|
153 | float scaleFactor; //!< The Factor with which the Model should be scaled. \todo maybe one wants to scale the Model after Initialisation |
---|
154 | |
---|
155 | private: |
---|
156 | bool buildVertexNormals(); |
---|
157 | |
---|
158 | bool importToDisplayList(); |
---|
159 | bool addGLElement(ModelFaceElement* elem); |
---|
160 | |
---|
161 | bool importToVertexArray(); |
---|
162 | |
---|
163 | bool deleteArrays(); |
---|
164 | bool cleanup(); |
---|
165 | |
---|
166 | private: |
---|
167 | MODEL_TYPE type; //!< A type for the Model |
---|
168 | bool finalized; //!< Sets the Object to be finalized. |
---|
169 | |
---|
170 | unsigned int vertexCount; //!< A modelwide Counter for vertices. |
---|
171 | unsigned int normalCount; //!< A modelwide Counter for the normals. |
---|
172 | unsigned int texCoordCount; //!< A modelwide Counter for the texCoord. |
---|
173 | unsigned int faceCount; //!< A modelwide Counter for the faces |
---|
174 | Array<GLfloat>* vertices; //!< The Array that handles the Vertices. |
---|
175 | Array<GLfloat>* normals; //!< The Array that handles the Normals. |
---|
176 | Array<GLfloat>* vTexture; //!< The Array that handles the VertexTextureCoordinates. |
---|
177 | |
---|
178 | ModelGroup* firstGroup; //!< The first of all groups. |
---|
179 | ModelGroup* currentGroup; //!< The currentGroup. this is the one we will work with. |
---|
180 | int groupCount; //!< The Count of Groups. |
---|
181 | |
---|
182 | tList<Material>* materialList; //!< A list for all the Materials in this Model |
---|
183 | }; |
---|
184 | |
---|
185 | #endif |
---|