-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserInterface.cpp
437 lines (375 loc) · 13.1 KB
/
UserInterface.cpp
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
#include "UserInterface.h"
#include "Model.h"
extern int gWidth, gHeight;
extern enumModo modoActual;
extern typeShading shadeactual;
extern typeProjection projectionActual;
extern deploymentModes deploymentActual;
extern int picked;
// Global static pointer used to ensure a single instance of the class.
CUserInterface * CUserInterface::mInterface = NULL;
/**
* Creates an instance of the class
*
* @return the instance of this class
*/
CUserInterface * CUserInterface::Instance()
{
if (!mInterface) // Only allow one instance of class to be generated.
mInterface = new CUserInterface();
return mInterface;
}
CUserInterface::CUserInterface()
{
mUserInterface = TwNewBar("Model");
TwDefine("Model refresh = '0.0001f'");
TwDefine("Model resizable = true");
TwDefine("Model fontresizable = false");
TwDefine("Model movable = true");
TwDefine("Model position = '20 20'");
TwDefine("Model size = '350 750'");
TwEnumVal enumModo[] = {
{ PUNTOS , "Points" },
{ LINEAS , "Wire-frame" },
{TRIANGULOS , "Triangles" }
};
TwType twEnumModo = TwDefineEnum("Modo", enumModo, 3);
TwEnumVal enumShade[] = {
{ FLAT , "Flat Shading" },
{ GOURAUD, "Gouraud Shading" }
};
TwType twEnumShading = TwDefineEnum("Shading", enumShade, 2);
TwEnumVal enumProjection[] = {
{ PERSPECTIVE , "Perspective" },
{ ORTHOGONAL, "Orthogonal" }
};
TwType twEnumProjection = TwDefineEnum("Projection", enumProjection, 2);
TwEnumVal enumDeployment[] = {
{ IMMEDIATE , "Immediate" },
{ DISPLAYL, "Display list" },
{ VERTEXP, "Vertex pointer" },
{ VBO, "VBO" }
};
TwType twEnumDeployment = TwDefineEnum("Deployment", enumDeployment, 4);
mModelTranslation[0] = 0.0f;
mModelTranslation[1] = 0.0f;
mModelTranslation[2] = 0.0f;
mModelScale[0] = 1.0f;
mModelScale[1] = 1.0f;
mModelScale[2] = 1.0f;
mModelScale[3] = 1.0f;
mBoundingColor[0] = mBoundingColor[1] = mBoundingColor[2] = 1.0f;
mNFaceColor[0] = mNFaceColor[1] = mNFaceColor[2] = 1.0f;
mNVertexColor[0] = mNVertexColor[1] = mNVertexColor[2] = 1.0f;
mModelColor[0] = mModelColor[1] = mModelColor[2] = 0.0f;
mModelColor[3] = mModelColor2[0] = mModelColor2[1] = mModelColor2[2] = mModelColor2[3] = mModelColor3[0] = mModelColor3[1] = mModelColor3[2] = mModelColor3[3] = 1.0f;
mLightColor[0] = mLightColor[1] = mLightColor[2] = mLightColor[3] = mLightColor2[0] = mLightColor2[1] = mLightColor2[2] = mLightColor2[3]= mLightColor3[0] = mLightColor3[1] = mLightColor3[2] = mLightColor3[3] = 1.0f;
mLight1Translation[0] = 2.0f;
mLight1Translation[1] = -0.5f;
mLight1Translation[2] = 2.0f;
mLight2Translation[0] = -2.0f;
mLight2Translation[1] = 2.0f;
mLight2Translation[2] = -2.0f;
mMshininess = 20.0f;
backFace = false;
zBuffer = false;
TwAddButton(mUserInterface, "LoadFile", loadFile, NULL, " label='Load File' ");
TwAddSeparator(mUserInterface, "", NULL);
TwAddVarRW(mUserInterface, "Picked Figure", TW_TYPE_INT32, &picked, " min=-1 label='Picked' ");
TwAddSeparator(mUserInterface, "", NULL);
TwAddVarRW(mUserInterface, "Deployment", twEnumDeployment, &deploymentActual, "group = 'Screen Options'");
TwAddVarRW(mUserInterface, "Projection", twEnumProjection, &projectionActual, "group = 'Screen Options'");
TwAddVarRW(mUserInterface, "BackFace", TW_TYPE_BOOLCPP, &backFace, "label='BackFace Culling' group = 'Screen Options'");
TwAddVarRW(mUserInterface, "zBuffer", TW_TYPE_BOOLCPP, &zBuffer, "label='Z-Buffer' group = 'Screen Options'");
TwAddSeparator(mUserInterface, "", NULL);
TwAddVarRW(mUserInterface, "Mode", twEnumModo, &modoActual, NULL);
TwAddVarRW(mUserInterface, "Shading", twEnumShading, &shadeactual, NULL);
TwAddVarRW(mUserInterface, "ModelColor1", TW_TYPE_COLOR4F, &mModelColor, "label = 'Ambient Color' group='Model Colors'");
TwAddVarRW(mUserInterface, "ModelColor2", TW_TYPE_COLOR4F, &mModelColor2, "label = 'Diffuse Color' group='Model Colors'");
TwAddVarRW(mUserInterface, "ModelColor3", TW_TYPE_COLOR4F, &mModelColor3, "label = 'Specular Color' group='Model Colors'");
TwAddVarRW(mUserInterface, "ModelShininess", TW_TYPE_FLOAT, &mMshininess, " min=0 max=100 step=0.5 label='Model Shininess' group='Model Colors'");
TwAddSeparator(mUserInterface, "", NULL);
TwAddButton(mUserInterface, "BoundingBox", changebbox, NULL, " label='On / Off' group='Bounding Box' ");
TwAddVarRW(mUserInterface, "BoundingColor", TW_TYPE_COLOR3F, &mBoundingColor[0], "label = 'BoundingBox Color' group='Bounding Box' visible = false");
TwAddSeparator(mUserInterface, "", NULL);
TwAddButton(mUserInterface, "NormalFace", changenormalsF, NULL, " group='Normal Vector' label='Normal Faces' ");
TwAddVarRW(mUserInterface, "NFaceColor", TW_TYPE_COLOR3F, &mNFaceColor[0], " group='Normal Vector' label = 'Normal Faces Color' visible = false");
TwAddButton(mUserInterface, "NormalVetex", changenormalsV, NULL, " group='Normal Vector' label='Normal Vertex' ");
TwAddVarRW(mUserInterface, "NVertexColor", TW_TYPE_COLOR3F, &mNVertexColor[0], " group='Normal Vector' label = 'Normal Vertex Color' visible = false");
TwAddSeparator(mUserInterface, "", NULL);
TwAddVarRW(mUserInterface, "traslateX", TW_TYPE_FLOAT, &mModelTranslation[0], "label='Translate X' group='Translation' step=0.01 ");
TwAddVarRW(mUserInterface, "traslateY", TW_TYPE_FLOAT, &mModelTranslation[1], "label='Translate Y' group='Translation' step=0.01 ");
TwAddVarRW(mUserInterface, "traslateZ", TW_TYPE_FLOAT, &mModelTranslation[2], "label='Translate Z' group='Translation' step=0.01 ");
TwAddSeparator(mUserInterface, "", NULL);
TwAddVarRW(mUserInterface, "scaleX", TW_TYPE_FLOAT, &mModelScale[0], "label='Scale X' group='Scale' min = 0.01 step=0.01 ");
TwAddVarRW(mUserInterface, "scaleY", TW_TYPE_FLOAT, &mModelScale[1], "label='Scale Y' group='Scale' min = 0.01 step=0.01 ");
TwAddVarRW(mUserInterface, "scaleZ", TW_TYPE_FLOAT, &mModelScale[2], "label='Scale Z' group='Scale' min = 0.01 step=0.01 ");
TwAddVarRW(mUserInterface, "scaleAll", TW_TYPE_FLOAT, &mModelScale[3], "label='Scale' group='Scale' min = 0.01 step=0.01 ");
TwAddSeparator(mUserInterface, "", NULL);
TwAddVarRW(mUserInterface, "rotate", TW_TYPE_QUAT4F, &mModelRotate," label='Rotate' opened='true' ");
TwAddSeparator(mUserInterface, "", NULL);
TwAddButton(mUserInterface, "LightsOn", changelights, NULL, " label='On / Off' group='Lights' ");
TwAddVarRW(mUserInterface, "LightsColor1", TW_TYPE_COLOR4F, &mLightColor, "label = 'Ambient Color' group='Lights' visible = false");
TwAddVarRW(mUserInterface, "LightsColor2", TW_TYPE_COLOR4F, &mLightColor2, "label = 'Difuse Color' group='Lights' visible = false");
TwAddVarRW(mUserInterface, "LightsColor3", TW_TYPE_COLOR4F, &mLightColor3, "label = 'Specular Color' group='Lights' visible = false");
TwAddVarRW(mUserInterface, "traslateL1X", TW_TYPE_FLOAT, &mLight1Translation[0], "label='TranslateL1 X' group='Lights' visible = false step=0.01 ");
TwAddVarRW(mUserInterface, "traslateL1Y", TW_TYPE_FLOAT, &mLight1Translation[1], "label='TranslateL1 Y' group='Lights' visible = false step=0.01 ");
TwAddVarRW(mUserInterface, "traslateL1Z", TW_TYPE_FLOAT, &mLight1Translation[2], "label='TranslateL1 Z' group='Lights' visible = false step=0.01 ");
TwAddVarRW(mUserInterface, "traslateL2X", TW_TYPE_FLOAT, &mLight2Translation[0], "label='TranslateL2 X' group='Lights' visible = false step=0.01 ");
TwAddVarRW(mUserInterface, "traslateL2Y", TW_TYPE_FLOAT, &mLight2Translation[1], "label='TranslateL2 Y' group='Lights' visible = false step=0.01 ");
TwAddVarRW(mUserInterface, "traslateL2Z", TW_TYPE_FLOAT, &mLight2Translation[2], "label='TranslateL2 Z' group='Lights' visible = false step=0.01 ");
}
CUserInterface::~CUserInterface()
{
}
void CUserInterface::reshape()
{
TwWindowSize(gWidth, gHeight);
}
void CUserInterface::show()
{
TwDefine("Figure visible = true");
}
void CUserInterface::hide()
{
TwDefine("Figure visible = false");
}
void CUserInterface::setmBColor(float *color)
{
mBoundingColor[0] = color[0];
mBoundingColor[1] = color[1];
mBoundingColor[2] = color[2];
}
void CUserInterface::setmMColor(float *color)
{
mModelColor[0] = color[0];
mModelColor[1] = color[1];
mModelColor[2] = color[2];
mModelColor[3] = color[3];
}
void CUserInterface::setmMColor2(float *color)
{
mModelColor2[0] = color[0];
mModelColor2[1] = color[1];
mModelColor2[2] = color[2];
mModelColor2[3] = color[3];
}
void CUserInterface::setmMColor3(float *color)
{
mModelColor3[0] = color[0];
mModelColor3[1] = color[1];
mModelColor3[2] = color[2];
mModelColor3[3] = color[3];
}
void CUserInterface::setmNFColor(float *color)
{
mNFaceColor[0] = color[0];
mNFaceColor[1] = color[1];
mNFaceColor[2] = color[2];
}
void CUserInterface::setmNVColor(float *color)
{
mNVertexColor[0] = color[0];
mNVertexColor[1] = color[1];
mNVertexColor[2] = color[2];
}
void CUserInterface::setshininess(float shini)
{
mMshininess = shini;
}
void CUserInterface::setmLightColor(float *color)
{
mLightColor[0] = color[0];
mLightColor[1] = color[1];
mLightColor[2] = color[2];
mLightColor[3] = color[3];
}
void CUserInterface::setmLightColor2(float *color)
{
mLightColor2[0] = color[0];
mLightColor2[1] = color[1];
mLightColor2[2] = color[2];
mLightColor2[3] = color[3];
}
void CUserInterface::setmLightColor3(float *color)
{
mLightColor3[0] = color[0];
mLightColor3[1] = color[1];
mLightColor3[2] = color[2];
mLightColor3[3] = color[3];
}
float* CUserInterface::getmBColor()
{
return mBoundingColor;
}
float* CUserInterface::getmMColor()
{
return mModelColor;
}
float* CUserInterface::getmMColor2()
{
return mModelColor2;
}
float* CUserInterface::getmMColor3()
{
return mModelColor3;
}
float* CUserInterface::getmNFColor()
{
return mNFaceColor;
}
float* CUserInterface::getmNVColor()
{
return mNVertexColor;
}
float CUserInterface::getshininess()
{
return mMshininess;
}
float* CUserInterface::getmLightColor()
{
return mLightColor;
}
float* CUserInterface::getmLightColor2()
{
return mLightColor2;
}
float* CUserInterface::getmLightColor3()
{
return mLightColor3;
}
void CUserInterface::setModelTranslation(float *modelTranslation)
{
mModelTranslation[0] = modelTranslation[0];
mModelTranslation[1] = modelTranslation[1];
mModelTranslation[2] = modelTranslation[2];
}
glm::vec3 CUserInterface::getLight1Translation()
{
return mLight1Translation;
}
void CUserInterface::setLight1Translation(float *lightTranslation)
{
mLight1Translation[0] = lightTranslation[0];
mLight1Translation[1] = lightTranslation[1];
mLight1Translation[2] = lightTranslation[2];
}
glm::vec3 CUserInterface::getLight2Translation()
{
return mLight2Translation;
}
void CUserInterface::setLight2Translation(float *lightTranslation)
{
mLight2Translation[0] = lightTranslation[0];
mLight2Translation[1] = lightTranslation[1];
mLight2Translation[2] = lightTranslation[2];
}
glm::vec3 CUserInterface::getModelTranslation()
{
return mModelTranslation;
}
void CUserInterface::setModelScale(float *modelScale)
{
mModelScale[0] = modelScale[0];
mModelScale[1] = modelScale[1];
mModelScale[2] = modelScale[2];
mModelScale[3] = modelScale[3];
}
glm::vec4 CUserInterface::getModelScale()
{
return mModelScale;
}
void CUserInterface::setModelRotate(glm::quat quaternion)
{
mModelRotate[0] = quaternion.x;
mModelRotate[1] = quaternion.y;
mModelRotate[2] = quaternion.z;
mModelRotate[3] = quaternion.w;
}
glm::vec4 CUserInterface::getModelRotate()
{
return mModelRotate;
}
void CUserInterface::setModo(string type)
{
mModo = type;
}
void CUserInterface::setShading(string type)
{
mShading = type;
}
void CUserInterface::boundingColorVisible(bool v)
{
if (v) {
TwDefine("Model/BoundingColor visible = true");
}
else {
TwDefine("Model/BoundingColor visible = false");
}
}
void CUserInterface::lightsOptionsVisible(bool v)
{
if (v) {
TwDefine("Model/LightsColor1 visible = true");
TwDefine("Model/LightsColor2 visible = true");
TwDefine("Model/LightsColor3 visible = true");
TwDefine("Model/traslateL1X visible = true");
TwDefine("Model/traslateL1Y visible = true");
TwDefine("Model/traslateL1Z visible = true");
TwDefine("Model/traslateL2X visible = true");
TwDefine("Model/traslateL2Y visible = true");
TwDefine("Model/traslateL2Z visible = true");
}
else {
TwDefine("Model/LightsColor1 visible = false");
TwDefine("Model/LightsColor2 visible = false");
TwDefine("Model/LightsColor3 visible = false");
TwDefine("Model/traslateL1X visible = false");
TwDefine("Model/traslateL1Y visible = false");
TwDefine("Model/traslateL1Z visible = false");
TwDefine("Model/traslateL2X visible = false");
TwDefine("Model/traslateL2Y visible = false");
TwDefine("Model/traslateL2Z visible = false");
}
}
void CUserInterface::nfaceColorVisible(bool v)
{
if (v) {
TwDefine("Model/NFaceColor visible = true");
}
else {
TwDefine("Model/NFaceColor visible = false");
}
}
void CUserInterface::nvertexColorVisible(bool v)
{
if (v) {
TwDefine("Model/NVertexColor visible = true");
}
else {
TwDefine("Model/NVertexColor visible = false");
}
}
typeProjection CUserInterface::getProjection()
{
return projectionActual;
}
bool CUserInterface::getBackFace()
{
return backFace;
}
bool CUserInterface::getZBuffer()
{
return zBuffer;
}
deploymentModes CUserInterface::getDeployment()
{
return deploymentActual;
}
void CUserInterface::setModelTotals(int total)
{
}
int CUserInterface::getmPicked()
{
return mPicked;
}