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 | |
---|
90 | bool initialize (void); |
---|
91 | bool initGroup(Group* group); |
---|
92 | bool initFace (Face* face); |
---|
93 | bool cleanup(void); |
---|
94 | bool cleanupGroup(Group* group); |
---|
95 | bool cleanupFace(Face* face); |
---|
96 | bool cleanupFaceElement(FaceElement* faceElem); |
---|
97 | |
---|
98 | ///// readin /// |
---|
99 | bool importFile (char* fileName); |
---|
100 | bool readFromObjFile (void); |
---|
101 | |
---|
102 | bool readGroup (char* groupString); |
---|
103 | bool readVertex (char* vertexString); |
---|
104 | bool readFace (char* faceString); |
---|
105 | bool readVertexNormal (char* normalString); |
---|
106 | bool readVertexTexture (char* vTextureString); |
---|
107 | bool readMtlLib (char* matFile); |
---|
108 | bool readUseMtl (char* mtlString); |
---|
109 | |
---|
110 | bool importToGL (void); |
---|
111 | bool addGLElement (FaceElement* elem); |
---|
112 | |
---|
113 | bool buildVertexNormals (); |
---|
114 | |
---|
115 | void BoxObject (void); |
---|
116 | }; |
---|
117 | |
---|
118 | #endif |
---|