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