1 | /*! |
---|
2 | \file object.h |
---|
3 | \brief Contains the Object Class that handles 3D-Objects |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef _OBJECT_H |
---|
7 | #define _OBJECT_H |
---|
8 | |
---|
9 | #include <GL/gl.h> |
---|
10 | #include <GL/glu.h> |
---|
11 | |
---|
12 | #include "array.h" |
---|
13 | #include "material.h" |
---|
14 | #include "vector.h" |
---|
15 | #include <fstream> |
---|
16 | |
---|
17 | using namespace std; |
---|
18 | |
---|
19 | extern int verbose; //!< Will be removed and added again as a verbose-class. |
---|
20 | |
---|
21 | |
---|
22 | |
---|
23 | //! Class that handles 3D-Objects. it can also read them in and display them. |
---|
24 | class Object |
---|
25 | { |
---|
26 | public: |
---|
27 | Object (); |
---|
28 | Object (char* fileName); |
---|
29 | Object(char* fileName, float scaling); |
---|
30 | ~Object (); |
---|
31 | |
---|
32 | void draw (void) const; |
---|
33 | void draw (int groupNumber) const; |
---|
34 | void draw (char* groupName) const; |
---|
35 | int getGroupCount() const; |
---|
36 | |
---|
37 | private: |
---|
38 | struct FaceElement |
---|
39 | { |
---|
40 | int vertexNumber; |
---|
41 | int normalNumber; |
---|
42 | int texCoordNumber; |
---|
43 | FaceElement* next; |
---|
44 | }; |
---|
45 | |
---|
46 | //! Face |
---|
47 | struct Face |
---|
48 | { |
---|
49 | int vertexCount; |
---|
50 | FaceElement* firstElem; |
---|
51 | |
---|
52 | char* materialString; |
---|
53 | |
---|
54 | Face* next; |
---|
55 | }; |
---|
56 | |
---|
57 | //! Group to handle multiple Objects per obj-file |
---|
58 | struct Group |
---|
59 | { |
---|
60 | char* name; |
---|
61 | |
---|
62 | GLuint listNumber; |
---|
63 | Face* firstFace; |
---|
64 | Face* currentFace; |
---|
65 | int faceMode; |
---|
66 | int faceCount; |
---|
67 | |
---|
68 | Group* next; |
---|
69 | }; |
---|
70 | |
---|
71 | |
---|
72 | Array* vertices; |
---|
73 | int verticesCount; |
---|
74 | Array* colors; |
---|
75 | Array* normals; |
---|
76 | Array* vTexture; |
---|
77 | |
---|
78 | |
---|
79 | Group* firstGroup; //!< the first of all groups. |
---|
80 | Group* currentGroup; //!< the currentGroup. this is the one we will work with. |
---|
81 | int groupCount; |
---|
82 | |
---|
83 | Material* material; |
---|
84 | float scaleFactor; |
---|
85 | |
---|
86 | char* objPath; |
---|
87 | char* objFileName; |
---|
88 | char* mtlFileName; |
---|
89 | ifstream* OBJ_FILE; |
---|
90 | ifstream* MTL_FILE; |
---|
91 | |
---|
92 | bool initialize (void); |
---|
93 | bool initGroup(Group* group); |
---|
94 | bool initFace (Face* face); |
---|
95 | bool cleanup(void); |
---|
96 | bool cleanupGroup(Group* group); |
---|
97 | bool cleanupFace(Face* face); |
---|
98 | bool cleanupFaceElement(FaceElement* faceElem); |
---|
99 | |
---|
100 | ///// readin /// |
---|
101 | bool importFile (char* fileName); |
---|
102 | bool readFromObjFile (char* fileName); |
---|
103 | |
---|
104 | bool readGroup (char* groupString); |
---|
105 | bool readVertex (char* vertexString); |
---|
106 | bool readFace (char* faceString); |
---|
107 | bool readVertexNormal (char* normalString); |
---|
108 | bool readVertexTexture (char* vTextureString); |
---|
109 | bool readMtlLib (char* matFile); |
---|
110 | bool readUseMtl (char* mtlString); |
---|
111 | |
---|
112 | bool importToGL (void); |
---|
113 | bool addGLElement (FaceElement* elem); |
---|
114 | |
---|
115 | bool buildVertexNormals (); |
---|
116 | |
---|
117 | void BoxObject (void); |
---|
118 | }; |
---|
119 | |
---|
120 | #endif |
---|