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