[2823] | 1 | /*! |
---|
[3360] | 2 | \file model.h |
---|
| 3 | \brief Contains the Model Class that handles 3D-Models |
---|
[2823] | 4 | */ |
---|
| 5 | |
---|
[3360] | 6 | #ifndef _MODEL_H |
---|
| 7 | #define _MODEL_H |
---|
[2773] | 8 | |
---|
[2776] | 9 | #include "material.h" |
---|
[2748] | 10 | |
---|
[3427] | 11 | // FORWARD DEFINITION // |
---|
| 12 | class Array; |
---|
| 13 | class Vector; |
---|
| 14 | |
---|
[2823] | 15 | using namespace std; |
---|
[2804] | 16 | |
---|
[3657] | 17 | // definition of different modes for setting up Faces |
---|
| 18 | #define VERTEX 0 //!< If Faces are created WITH Vertex-Coordinate |
---|
| 19 | #define NORMAL 1 //!< If Faces are created WITH Normals (otherwise autocalculate) |
---|
| 20 | #define TEXCOORD 2 //!< If Faces are created WITH TextureCoordinate |
---|
[3894] | 21 | //! an enumerator for VERTEX_FORMAT |
---|
| 22 | enum VERTEX_FORMAT {VERTEX_ONLY = VERTEX, |
---|
| 23 | VERTEX_NORMAL = NORMAL, |
---|
| 24 | VERTEX_TEXCOORD = TEXCOORD, |
---|
| 25 | VERTEXT_TEXTURE_NORMAL = NORMAL | TEXCOORD}; |
---|
[2842] | 26 | |
---|
[3360] | 27 | //! Class that handles 3D-Models. it can also read them in and display them. |
---|
| 28 | class Model |
---|
[2748] | 29 | { |
---|
| 30 | public: |
---|
[3396] | 31 | Model(void); |
---|
[3398] | 32 | Model(char* modelName); |
---|
[3396] | 33 | virtual ~Model(void); |
---|
[3398] | 34 | |
---|
| 35 | void setName(const char* name); |
---|
[2748] | 36 | |
---|
[3396] | 37 | void draw(void) const; |
---|
| 38 | void draw(int groupNumber) const; |
---|
| 39 | void draw(char* groupName) const; |
---|
[3063] | 40 | int getGroupCount() const; |
---|
[2767] | 41 | |
---|
[3396] | 42 | protected: |
---|
[3398] | 43 | char* name; //!< This is the name of the Model. |
---|
| 44 | bool finalized; //!< Sets the Object to be finalized. |
---|
| 45 | |
---|
[3186] | 46 | //! This is the placeholder of one Vertex beloning to a Face. |
---|
[3396] | 47 | struct FaceElement |
---|
[3063] | 48 | { |
---|
[3186] | 49 | int vertexNumber; //!< The number of the Vertex out of the Array* vertices, this vertex points to. |
---|
| 50 | int normalNumber; //!< The number of the Normal out of the Array* normals, this vertex points to. |
---|
| 51 | int texCoordNumber; //!< The number of the textureCoordinate out of the Array* vTexture, this vertex points to. |
---|
| 52 | FaceElement* next; //!< Point to the next FaceElement in this List. |
---|
[3063] | 53 | }; |
---|
| 54 | |
---|
[3186] | 55 | //! This is the placeholder of a Face belonging to a Group of Faces. |
---|
[3418] | 56 | struct Face |
---|
[3063] | 57 | { |
---|
[3186] | 58 | int vertexCount; //!< The Count of vertices this Face has. |
---|
| 59 | FaceElement* firstElem; //!< Points to the first Vertex (FaceElement) of this Face. |
---|
[3063] | 60 | |
---|
[3801] | 61 | Material* material; //!< The Material to use. |
---|
[3063] | 62 | |
---|
[3186] | 63 | Face* next; //!< Pointer to the next Face. |
---|
| 64 | }; |
---|
[3063] | 65 | |
---|
[3360] | 66 | //! Group to handle multiple Models per obj-file. |
---|
[2850] | 67 | struct Group |
---|
| 68 | { |
---|
[3186] | 69 | char* name; //!< the Name of the Group. this is an identifier, that can be accessed via the draw (char* name) function. |
---|
[2850] | 70 | |
---|
[3427] | 71 | unsigned int listNumber;//!< The number of the GL-List this Group gets. |
---|
[3186] | 72 | Face* firstFace; //!< The first Face in this group. |
---|
| 73 | Face* currentFace; //!< The current Face in this Group (the one we are currently working with.) |
---|
| 74 | 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... |
---|
| 75 | int faceCount; //!< The Number of Faces this Group holds. |
---|
[2850] | 76 | |
---|
[3186] | 77 | Group* next; //!< Pointer to the next Group. |
---|
[3063] | 78 | }; |
---|
[2850] | 79 | |
---|
[3063] | 80 | |
---|
[3186] | 81 | Array* vertices; //!< The Array that handles the Vertices. |
---|
| 82 | int verticesCount; //!< A global Counter for vertices. |
---|
| 83 | Array* normals; //!< The Array that handles the Normals. |
---|
| 84 | Array* vTexture; //!< The Array that handles the VertexTextureCoordinates. |
---|
[3063] | 85 | |
---|
[2850] | 86 | |
---|
[3186] | 87 | Group* firstGroup; //!< The first of all groups. |
---|
| 88 | Group* currentGroup; //!< The currentGroup. this is the one we will work with. |
---|
| 89 | int groupCount; //!< The Count of Groups. |
---|
[2850] | 90 | |
---|
[3186] | 91 | Material* material; //!< Initial pointer to the Material. This can hold many materials, because Material can be added with Material::addMaterial(..) |
---|
[3360] | 92 | float scaleFactor; //!< The Factor with which the Model should be scaled. \todo maybe one wants to scale the Model after Initialisation |
---|
[2760] | 93 | |
---|
[3400] | 94 | bool initialize(void); |
---|
[2850] | 95 | bool initGroup(Group* group); |
---|
[3066] | 96 | bool initFace (Face* face); |
---|
| 97 | bool cleanup(void); |
---|
| 98 | bool cleanupGroup(Group* group); |
---|
| 99 | bool cleanupFace(Face* face); |
---|
[3068] | 100 | bool cleanupFaceElement(FaceElement* faceElem); |
---|
[2850] | 101 | |
---|
[3398] | 102 | public: |
---|
[3894] | 103 | bool addGroup(const char* groupString); |
---|
[3400] | 104 | bool addVertex(char* vertexString); |
---|
[3894] | 105 | bool addVertex(float x, float y, float z); |
---|
[3400] | 106 | bool addFace(char* faceString); |
---|
[3894] | 107 | bool addFace(int faceElemCount, int type, ...); |
---|
[3400] | 108 | bool addVertexNormal(char* normalString); |
---|
[3894] | 109 | bool addVertexNormal(float x, float y, float z); |
---|
[3400] | 110 | bool addVertexTexture(char* vTextureString); |
---|
[3894] | 111 | bool addVertexTexture(float u, float v); |
---|
| 112 | bool addUseMtl(const char* mtlString); |
---|
[3801] | 113 | bool addUseMtl(Material* mtl); |
---|
[3398] | 114 | void finalize(void); |
---|
[2754] | 115 | |
---|
[3398] | 116 | protected: |
---|
[3400] | 117 | bool importToGL(void); |
---|
| 118 | bool addGLElement(FaceElement* elem); |
---|
[2821] | 119 | |
---|
[3400] | 120 | bool buildVertexNormals(void); |
---|
[3075] | 121 | |
---|
[3400] | 122 | void cubeModel(void); |
---|
[2748] | 123 | }; |
---|
[2773] | 124 | |
---|
| 125 | #endif |
---|