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