[2823] | 1 | /*! |
---|
[2842] | 2 | \file object.h |
---|
| 3 | \brief Contains the Object Class that handles 3D-Objects |
---|
[2823] | 4 | */ |
---|
| 5 | |
---|
[2776] | 6 | #ifndef _OBJECT_H |
---|
| 7 | #define _OBJECT_H |
---|
[2773] | 8 | |
---|
[3184] | 9 | #include "stdincl.h" |
---|
[2773] | 10 | |
---|
[2754] | 11 | #include "array.h" |
---|
[2776] | 12 | #include "material.h" |
---|
[3075] | 13 | #include "vector.h" |
---|
[2823] | 14 | #include <fstream> |
---|
[2748] | 15 | |
---|
[2823] | 16 | using namespace std; |
---|
[2804] | 17 | |
---|
[3063] | 18 | extern int verbose; //!< Will be removed and added again as a verbose-class. |
---|
[2842] | 19 | |
---|
| 20 | |
---|
[2934] | 21 | |
---|
[2823] | 22 | //! Class that handles 3D-Objects. it can also read them in and display them. |
---|
[2748] | 23 | class Object |
---|
| 24 | { |
---|
| 25 | public: |
---|
| 26 | Object (); |
---|
[2767] | 27 | Object (char* fileName); |
---|
[2833] | 28 | Object(char* fileName, float scaling); |
---|
[2748] | 29 | ~Object (); |
---|
| 30 | |
---|
[3063] | 31 | void draw (void) const; |
---|
| 32 | void draw (int groupNumber) const; |
---|
| 33 | void draw (char* groupName) const; |
---|
| 34 | int getGroupCount() const; |
---|
[2767] | 35 | |
---|
[2748] | 36 | private: |
---|
[3186] | 37 | //! This is the placeholder of one Vertex beloning to a Face. |
---|
| 38 | struct FaceElement |
---|
[3063] | 39 | { |
---|
[3186] | 40 | int vertexNumber; //!< The number of the Vertex out of the Array* vertices, this vertex points to. |
---|
| 41 | int normalNumber; //!< The number of the Normal out of the Array* normals, this vertex points to. |
---|
| 42 | int texCoordNumber; //!< The number of the textureCoordinate out of the Array* vTexture, this vertex points to. |
---|
| 43 | FaceElement* next; //!< Point to the next FaceElement in this List. |
---|
[3063] | 44 | }; |
---|
| 45 | |
---|
[3186] | 46 | //! This is the placeholder of a Face belonging to a Group of Faces. |
---|
| 47 | /** |
---|
| 48 | \todo take Material to a call for itself. |
---|
| 49 | |
---|
| 50 | This can also be a Material-Change switch. |
---|
| 51 | That means if you want to change a Material inside of a group, |
---|
| 52 | you can create an empty face and apply a material to it, and the Importer will cahnge Colors |
---|
| 53 | */ |
---|
| 54 | struct Face |
---|
[3063] | 55 | { |
---|
[3186] | 56 | int vertexCount; //!< The Count of vertices this Face has. |
---|
| 57 | FaceElement* firstElem; //!< Points to the first Vertex (FaceElement) of this Face. |
---|
[3063] | 58 | |
---|
[3186] | 59 | char* materialString; //!< The Name of the Material to which to Change. |
---|
[3063] | 60 | |
---|
[3186] | 61 | Face* next; //!< Pointer to the next Face. |
---|
| 62 | }; |
---|
[3063] | 63 | |
---|
[3186] | 64 | //! Group to handle multiple Objects per obj-file. |
---|
[2850] | 65 | struct Group |
---|
| 66 | { |
---|
[3186] | 67 | char* name; //!< the Name of the Group. this is an identifier, that can be accessed via the draw (char* name) function. |
---|
[2850] | 68 | |
---|
[3186] | 69 | GLuint listNumber; //!< The number of the GL-List this Group gets. |
---|
| 70 | Face* firstFace; //!< The first Face in this group. |
---|
| 71 | Face* currentFace; //!< The current Face in this Group (the one we are currently working with.) |
---|
| 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... |
---|
| 73 | int faceCount; //!< The Number of Faces this Group holds. |
---|
[2850] | 74 | |
---|
[3186] | 75 | Group* next; //!< Pointer to the next Group. |
---|
[3063] | 76 | }; |
---|
[2850] | 77 | |
---|
[3063] | 78 | |
---|
[3186] | 79 | Array* vertices; //!< The Array that handles the Vertices. |
---|
| 80 | int verticesCount; //!< A global Counter for vertices. |
---|
| 81 | Array* normals; //!< The Array that handles the Normals. |
---|
| 82 | Array* vTexture; //!< The Array that handles the VertexTextureCoordinates. |
---|
[3063] | 83 | |
---|
[2850] | 84 | |
---|
[3186] | 85 | Group* firstGroup; //!< The first of all groups. |
---|
| 86 | Group* currentGroup; //!< The currentGroup. this is the one we will work with. |
---|
| 87 | int groupCount; //!< The Count of Groups. |
---|
[2850] | 88 | |
---|
[3186] | 89 | Material* material; //!< Initial pointer to the Material. This can hold many materials, because Material can be added with Material::addMaterial(..) |
---|
| 90 | float scaleFactor; //!< The Factor with which the Object hould be scaled. \todo maybe one wants to scale the Object after Initialisation |
---|
[2760] | 91 | |
---|
[3186] | 92 | char* objPath; //!< The Path wher the obj and mtl-file are located. |
---|
| 93 | char* objFileName; //!< The Name of the obj-file. |
---|
| 94 | char* mtlFileName; //!< The Name of the mtl-file (parsed out of the obj-file) |
---|
[2850] | 95 | |
---|
[3066] | 96 | bool initialize (void); |
---|
[2850] | 97 | bool initGroup(Group* group); |
---|
[3066] | 98 | bool initFace (Face* face); |
---|
| 99 | bool cleanup(void); |
---|
| 100 | bool cleanupGroup(Group* group); |
---|
| 101 | bool cleanupFace(Face* face); |
---|
[3068] | 102 | bool cleanupFaceElement(FaceElement* faceElem); |
---|
[2850] | 103 | |
---|
| 104 | ///// readin /// |
---|
[3066] | 105 | bool importFile (char* fileName); |
---|
[3140] | 106 | bool readFromObjFile (void); |
---|
[2748] | 107 | |
---|
[3066] | 108 | bool readGroup (char* groupString); |
---|
[2767] | 109 | bool readVertex (char* vertexString); |
---|
| 110 | bool readFace (char* faceString); |
---|
[2794] | 111 | bool readVertexNormal (char* normalString); |
---|
[2820] | 112 | bool readVertexTexture (char* vTextureString); |
---|
[2776] | 113 | bool readMtlLib (char* matFile); |
---|
| 114 | bool readUseMtl (char* mtlString); |
---|
[2754] | 115 | |
---|
[3063] | 116 | bool importToGL (void); |
---|
[3072] | 117 | bool addGLElement (FaceElement* elem); |
---|
[2821] | 118 | |
---|
[3075] | 119 | bool buildVertexNormals (); |
---|
| 120 | |
---|
[2821] | 121 | void BoxObject (void); |
---|
[2748] | 122 | }; |
---|
[2773] | 123 | |
---|
| 124 | #endif |
---|