-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.h
209 lines (169 loc) · 3.26 KB
/
model.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#ifndef MODEL_H
#define MODEL_H
#include <QGLWidget>
#include <QOffscreenSurface>
#include <QMap>
#include <QVector>
#include <QDebug>
#include <QImage>
#include <QFile>
#include <QTextStream>
#include <QTimer>
#include <QObject>
#include <GL/gl.h>
#include <GL/glu.h>
#define WARNING false
struct ModelSize
{
bool calculed;
unsigned int width;
unsigned int height;
unsigned int depth;
ModelSize()
{
}
ModelSize (unsigned int w, unsigned int h, unsigned int d)
{
this->width = w;
this->height = h;
this->depth = d;
this->calculed = true;
}
};
struct Vertex
{
float x;
float y;
float z;
float w;
Vertex ()
{
}
Vertex (float x, float y, float z, float w = 0)
{
this->x = x;
this->y = y;
this->z = z;
this->w = w;
}
};
struct Texture
{
float u;
float v;
float w;
Texture ()
{
u = 0;
v = 0;
w = 0;
}
Texture (float u, float v = 0, float w = 0)
{
this->u = u;
this->v = v;
this->w = w;
}
};
struct Normal
{
float i;
float j;
float k;
Normal ()
{
this->i = 0;
this->j = 0;
this->k = 0;
}
Normal (float i, float j, float k)
{
this->i = i;
this->j = j;
this->k = k;
}
};
struct Face
{
int vIndex;
int vtIndex;
int vnIndex;
QString mIndex; // Material
Face ()
{
this->vIndex = -1;
this->vnIndex = -1;
this->vtIndex = -1;
}
Face (int vIndex, int vtIndex, int vnIndex)
{
this->vIndex = vIndex;
this->vtIndex = vtIndex;
this->vnIndex = vnIndex;
}
Face (int vIndex, int vtIndex, int vnIndex, QString mIndex)
{
this->vIndex = vIndex;
this->vtIndex = vtIndex;
this->vnIndex = vnIndex;
this->mIndex = mIndex;
}
};
struct Material
{
float Ka[4]; //Ambient colour
float Kd[4]; //Diffuse colour
float Ks[4]; //Specular colour
float Ns; // Specular (coeff)
GLuint textureID;
unsigned int illum;
Material ()
{
this->Ka[0] = 0;
this->Ka[1] = 0;
this->Ka[2] = 0;
this->Ka[3] = 1;
this->Kd[0] = 0;
this->Kd[1] = 0;
this->Kd[2] = 0;
this->Kd[3] = 1;
this->Ks[0] = 0;
this->Ks[1] = 0;
this->Ks[2] = 0;
this->Ks[3] = 1;
this->Ns = 0;
this->textureID = 0;
this->illum = 0;
}
};
class Model : public QOffscreenSurface
{
Q_OBJECT
public:
Model();
void loadModel(QString filePath);
void makeVBO();
void drawModel();
void calcDim();
ModelSize getDim();
void scaleModel (float scale);
GLuint getGlList(bool useTexture=true);
QString getModelInfo();
protected:
private:
ModelSize ms;
GLuint loadTexture(QString imgPath);
void loadmtl (QString mtlPath);
void renderModel(bool useTexture=true);
QVector<Vertex> vertices;
QVector< QVector<Face> > faces;
QVector<Texture> textures;
QVector<Normal> normals;
QMap <QString, Material> materials;
/*GLuint VertexVBO;
GLuint NormalVBO;
GLuint TextureVBO;*/
signals:
public slots:
};
#endif // MODEL_H