-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
392 lines (342 loc) · 7.53 KB
/
main.cpp
File metadata and controls
392 lines (342 loc) · 7.53 KB
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
//
// main.cpp
// Base Skeleton framework for running our own C++ framework in the CAVE / Dev Lab / Oculus / etc.
// Adapted from Hyun Joon Shin and Ross Tredinnick's FionaUT project
#define WITH_FIONA
#ifdef WIN32
#include "gl/glew.h"
#else
#include "GL/glew.h"
#endif
#include "FionaUT.h"
#ifdef WIN32
#include "FionaUtil.h"
#endif
#include <Kit3D/glslUtils.h>
#include <Kit3D/glUtils.h>
#ifdef LINUX_BUILD
#define FALSE 0
#endif
class FionaScene;
FionaScene* scene = NULL;
extern bool cmp(const std::string& a, const std::string& b);
extern std::string getst(char* argv[], int& i, int argc);
/*static bool cmp(const char* a, const char* b)
{
if( strlen(a)!=strlen(b) ) return 0;
size_t len = MIN(strlen(a),strlen(b));
for(size_t i=0; i<len; i++)
if(toupper(a[i]) != toupper(b[i])) return 0;
return 1;
}
*/
static bool cmpExt(const std::string& fn, const std::string& ext)
{
std::string extt = fn.substr(fn.rfind('.')+1,100);
std::cout<<"The extension: "<<extt<<std::endl;
return cmp(ext.c_str(),extt.c_str());
}
jvec3 curJoy(0.f,0.f,0.f);
jvec3 secondCurJoy(0.f, 0.f, 0.f);
jvec3 pos(0.f,0.f,0.f);
jvec3 secondPos(0.f, 0.f, 0.f);
quat ori(1.f,0.f,0.f,0.f);
quat secondOri(1.f, 0.f, 0.f, 0.f);
//int calibMode = 0;
void draw5Teapot(void) {
static GLuint phongShader=0;
static GLuint teapotList =0;
if( FionaIsFirstOfCycle() )
{
if(!fionaConf.dualView || _FionaUTIsSingleViewMachine())
{
pos+=jvec3(0,0,curJoy.z*0.01f);
ori =exp(YAXIS*curJoy.x*0.01f)*ori;
}
else if(_FionaUTIsDualViewMachine())
{
secondPos+=jvec3(0,0,secondCurJoy.z*0.01f);
secondOri =exp(YAXIS*secondCurJoy.x*0.01f)*secondOri;
}
}
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
if(!fionaConf.dualView || _FionaUTIsSingleViewMachine())
{
glTranslate(-pos);
glRotate(ori);
}
else if(_FionaUTIsDualViewMachine())
{
glTranslate(-secondPos);
glRotate(secondOri);
}
glDisable(GL_CULL_FACE);
glDepthFunc(GL_LESS);
glLight(vec4(0,0,0,1),GL_LIGHT0,0xFF202020);
glBindTexture(GL_TEXTURE_2D,0);
jvec3 posSpheres[5]={jvec3(0,0,-1.5),jvec3(-1.5,0,0),jvec3(1.5,0,0),jvec3(0,-1.5,0), jvec3(0,1.5,0)};
if( teapotList <=0 )
{
teapotList = glGenLists(1);
glNewList(teapotList,GL_COMPILE);
//glutSolidTeapot(.65f);
glEndList();
}
if( phongShader<=0 )
{
glewInit();
std::string vshader = std::string(commonVShader());
std::string fshader = coinFShader(PLASTICY,PHONG,false);
phongShader = loadProgram(vshader,fshader,true);
}
glUseProgram(phongShader);
glEnable(GL_DEPTH_TEST); glMat(0xFFFF8000,0xFFFFFFFF,0xFF404040);
glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,10);
for(int i=0;i<3; i++)
{
glPushMatrix();
glTranslate(posSpheres[i]);
//glutSolidTeapot(.65f);
//glCallList(teapotList);
glSphere(V3ID,.65);
glPopMatrix();
}
glUseProgram(0);
}
void drawSkyTest(void)
{
if( FionaIsFirstOfCycle() )
{
if(!fionaConf.dualView || _FionaUTIsSingleViewMachine())
{
pos+=jvec3(0,0,curJoy.z*0.01f);
ori =exp(YAXIS*curJoy.x*0.01f)*ori;
}
else if(_FionaUTIsDualViewMachine())
{
secondPos+=jvec3(0,0,secondCurJoy.z*0.01f);
secondOri =exp(YAXIS*secondCurJoy.x*0.01f)*secondOri;
}
}
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
if(!fionaConf.dualView || _FionaUTIsSingleViewMachine())
{
glTranslate(-pos);
glRotate(ori);
}
else if(_FionaUTIsDualViewMachine())
{
glTranslate(-secondPos);
glRotate(secondOri);
}
glDisable(GL_CULL_FACE);
glDepthFunc(GL_LESS);
glLight(vec4(0,0,0,1),GL_LIGHT0,0xFF202020);
glBindTexture(GL_TEXTURE_2D,0);
jvec3 posSpheres[5]={jvec3(0,0,-1.5),jvec3(-1.5,0,0),jvec3(1.5,0,0),jvec3(0,-1.5,0), jvec3(0,1.5,0)};
static GLuint phongShader=0;
if( phongShader<=0 )
{
glewInit();
std::string vshader = std::string("../../shaders/simple.vert");
std::string fshader = std::string("../../shaders/red.frag");
phongShader = loadProgramFiles(vshader,fshader,true);
}
GLint projLoc = glGetUniformLocation(phongShader, "projection");
GLint viewLoc = glGetUniformLocation(phongShader, "modelview");
glUseProgram(phongShader);
glEnable(GL_DEPTH_TEST); glMat(0xFFFF8000,0xFFFFFFFF,0xFF404040);
glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,10);
for(int i=0;i<3; i++)
{
glPushMatrix();
glTranslate(posSpheres[i]);
GLfloat view[16];
glGetFloatv(GL_MODELVIEW_MATRIX, view);
glUniformMatrix4fv(viewLoc, 1, FALSE, view);
GLfloat proj[16];
glGetFloatv(GL_PROJECTION_MATRIX, proj);
glUniformMatrix4fv(projLoc, 1, FALSE, proj);
//glutSolidSphere(.25, 12, 12);
//glutSolidTeapot(.65f);
//glCallList(teapotList);
glSphere(V3ID,.65);
glPopMatrix();
}
glUseProgram(0);
}
enum APP_TYPE
{
APP_TAEPOT = 0
} type = APP_TAEPOT;
void wandBtns(int button, int state, int idx)
{
if(!fionaConf.dualView || _FionaUTIsSingleViewMachine())
{
if(scene)
{
scene->buttons(button, state);
}
}
else if(_FionaUTIsDualViewMachine())
{
if(idx == 1)
{
if(scene)
{
scene->buttons(button, state);
}
}
}
}
void keyboard(unsigned int key, int x, int y)
{
if(scene)
{
scene->keyboard(key, x, y);
}
}
void joystick(int w, const vec4& v)
{
if(!fionaConf.dualView || _FionaUTIsSingleViewMachine())
{
curJoy = jvec3(v.x, v.y, v.z);
if(scene)
{
scene->updateJoystick(v);
}
}
else if(_FionaUTIsDualViewMachine())
{
//need this sort of construct because we don't want to
//update the first viewer's scene if the second joystick is moved...
if(w == 1)
{
secondCurJoy = jvec3(v.x, v.y, v.z);
if(scene)
{
scene->updateJoystick(v);
}
}
}
}
void mouseBtns(int button, int state, int x, int y)
{
}
void mouseMove(int x, int y)
{
}
void tracker(int s,const jvec3& p, const quat& q)
{
if(s==1)
{
fionaConf.wandPos = p;
fionaConf.wandRot = q;
}
else if(s == 3)
{
fionaConf.secondWandPos = p;
fionaConf.secondWandRot = q;
}
if((s==1 || s==3) && scene)
{
scene->updateWand(p,q);
}
}
void preDisplay(float value)
{
if(scene != 0)
{
scene->preRender(value);
}
}
void postDisplay(void)
{
if(scene != 0)
{
scene->postRender();
}
}
void render(void)
{
if(scene!=NULL)
{
scene->render();
}
else
{
draw5Teapot();
}
}
void cleanup(int errorCode)
{
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
float measuredIPD=63.5;
int userID=0;
bool writeFull=false;
std::string fn;
/*for(int i=1; i<argc; i++)
{
if(cmp(argv[i],"--ogreScene"))
{
type=APP_OGRE_SCENE;
fn=getst(argv,i,argc);
printf("%s\n",fn.c_str());
}
else if(cmp(argv[i],"--ogreHead"))
{
type=APP_OGRE_HEAD;
}
else if(cmp(argv[i], "--gopro"))
{
type=APP_GO_PRO;
}
else if(cmp(argv[i], "--wordcake"))
{
type = APP_WORD_CAKE;
fn=getst(argv,i,argc);
printf("%s\n",fn.c_str());
}
else if(cmp(argv[i], "--latency"))
{
type = APP_LAT_TEST;
}
}*/
/*switch( type )
{
case APP_OGRE_HEAD:
scene = new FionaOgre();
scene->navMode=WAND_WORLD;
static_cast<FionaOgre*>(scene)->initOgre();
break;
case APP_OGRE_SCENE:
scene = new FionaOgre();
scene->navMode=WAND_WORLD;
static_cast<FionaOgre*>(scene)->initOgre(fn);
break;
case APP_GO_PRO:
scene = new FionaGoPro();
scene->navMode=WAND_WORLD;
break;
}*/
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow ("Window");
glutDisplayFunc (render);
glutJoystickFunc (joystick);
glutMouseFunc (mouseBtns);
glutMotionFunc (mouseMove);
glutWandButtonFunc (wandBtns);
glutTrackerFunc (tracker);
glutKeyboardFunc (keyboard);
glutCleanupFunc (cleanup);
glutFrameFunc (preDisplay);
glutPostRender (postDisplay);
glutMainLoop();
delete scene;
return 0;
}