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