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