67
66
static bool nVidiaWindows; // very dirty but hey, it's for testing only
69
static void gearsTimerProc(GHOST_ITimerTask* task, GHOST_TUns64 time);
68
static void gearsTimerProc(GHOST_ITimerTask *task, GHOST_TUns64 time);
71
static class Application* fApp;
72
static GLfloat view_rotx=20.0, view_roty=30.0, view_rotz=0.0;
70
static class Application * fApp;
71
static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
73
72
static GLfloat fAngle = 0.0;
74
static GHOST_ISystem* fSystem = 0;
73
static GHOST_ISystem *fSystem = 0;
77
76
void StereoProjection(float left, float right, float bottom, float top, float nearplane, float farplane,
78
float zero_plane, float dist,
82
static void testTimerProc(GHOST_ITimerTask* /*task*/, GHOST_TUns64 time)
77
float zero_plane, float dist,
81
static void testTimerProc(GHOST_ITimerTask * /*task*/, GHOST_TUns64 time)
84
83
std::cout << "timer1, time=" << (int)time << "\n";
96
r1 = outer_radius - tooth_depth/2.0;
97
r2 = outer_radius + tooth_depth/2.0;
95
r1 = outer_radius - tooth_depth / 2.0;
96
r2 = outer_radius + tooth_depth / 2.0;
99
98
const double pi = 3.14159264;
100
da = 2.0*pi / teeth / 4.0;
99
da = 2.0 * pi / teeth / 4.0;
102
101
glShadeModel(GL_FLAT);
103
102
glNormal3f(0.0, 0.0, 1.0);
105
104
/* draw front face */
106
105
glBegin(GL_QUAD_STRIP);
107
for (i=0;i<=teeth;i++) {
108
angle = i * 2.0*pi / teeth;
109
glVertex3f(r0*cos(angle), r0*sin(angle), width*0.5);
110
glVertex3f(r1*cos(angle), r1*sin(angle), width*0.5);
111
glVertex3f(r0*cos(angle), r0*sin(angle), width*0.5);
112
glVertex3f(r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5);
106
for (i = 0; i <= teeth; i++) {
107
angle = i * 2.0 * pi / teeth;
108
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
109
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
110
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
111
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5);
116
115
/* draw front sides of teeth */
117
116
glBegin(GL_QUADS);
118
da = 2.0*pi / teeth / 4.0;
119
for (i=0;i<teeth;i++) {
120
angle = i * 2.0*pi / teeth;
121
glVertex3f(r1*cos(angle), r1*sin(angle), width*0.5);
122
glVertex3f(r2*cos(angle+da), r2*sin(angle+da), width*0.5);
123
glVertex3f(r2*cos(angle+2*da), r2*sin(angle+2*da), width*0.5);
124
glVertex3f(r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5);
117
da = 2.0 * pi / teeth / 4.0;
118
for (i = 0; i < teeth; i++) {
119
angle = i * 2.0 * pi / teeth;
120
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
121
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
122
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5);
123
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5);
130
129
/* draw back face */
131
130
glBegin(GL_QUAD_STRIP);
132
for (i=0;i<=teeth;i++) {
133
angle = i * 2.0*pi / teeth;
134
glVertex3f(r1*cos(angle), r1*sin(angle), -width*0.5);
135
glVertex3f(r0*cos(angle), r0*sin(angle), -width*0.5);
136
glVertex3f(r1*cos(angle+3*da), r1*sin(angle+3*da), -width*0.5);
137
glVertex3f(r0*cos(angle), r0*sin(angle), -width*0.5);
131
for (i = 0; i <= teeth; i++) {
132
angle = i * 2.0 * pi / teeth;
133
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
134
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
135
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5);
136
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
141
140
/* draw back sides of teeth */
142
141
glBegin(GL_QUADS);
143
da = 2.0*pi / teeth / 4.0;
144
for (i=0;i<teeth;i++) {
145
angle = i * 2.0*pi / teeth;
146
glVertex3f(r1*cos(angle+3*da), r1*sin(angle+3*da), -width*0.5);
147
glVertex3f(r2*cos(angle+2*da), r2*sin(angle+2*da), -width*0.5);
148
glVertex3f(r2*cos(angle+da), r2*sin(angle+da), -width*0.5);
149
glVertex3f(r1*cos(angle), r1*sin(angle), -width*0.5);
142
da = 2.0 * pi / teeth / 4.0;
143
for (i = 0; i < teeth; i++) {
144
angle = i * 2.0 * pi / teeth;
145
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5);
146
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5);
147
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
148
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
153
152
/* draw outward faces of teeth */
154
153
glBegin(GL_QUAD_STRIP);
155
for (i=0;i<teeth;i++) {
156
angle = i * 2.0*pi / teeth;
157
glVertex3f(r1*cos(angle), r1*sin(angle), width*0.5);
158
glVertex3f(r1*cos(angle), r1*sin(angle), -width*0.5);
159
u = r2*cos(angle+da) - r1*cos(angle);
160
v = r2*sin(angle+da) - r1*sin(angle);
161
len = sqrt(u*u + v*v);
154
for (i = 0; i < teeth; i++) {
155
angle = i * 2.0 * pi / teeth;
156
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
157
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
158
u = r2 * cos(angle + da) - r1 *cos(angle);
159
v = r2 * sin(angle + da) - r1 *sin(angle);
160
len = sqrt(u * u + v * v);
164
163
glNormal3f(v, -u, 0.0);
165
glVertex3f(r2*cos(angle+da), r2*sin(angle+da), width*0.5);
166
glVertex3f(r2*cos(angle+da), r2*sin(angle+da), -width*0.5);
164
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
165
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
167
166
glNormal3f(cos(angle), sin(angle), 0.0);
168
glVertex3f(r2*cos(angle+2*da), r2*sin(angle+2*da), width*0.5);
169
glVertex3f(r2*cos(angle+2*da), r2*sin(angle+2*da), -width*0.5);
170
u = r1*cos(angle+3*da) - r2*cos(angle+2*da);
171
v = r1*sin(angle+3*da) - r2*sin(angle+2*da);
167
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5);
168
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5);
169
u = r1 * cos(angle + 3 * da) - r2 *cos(angle + 2 * da);
170
v = r1 * sin(angle + 3 * da) - r2 *sin(angle + 2 * da);
172
171
glNormal3f(v, -u, 0.0);
173
glVertex3f(r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5);
174
glVertex3f(r1*cos(angle+3*da), r1*sin(angle+3*da), -width*0.5);
172
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5);
173
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5);
175
174
glNormal3f(cos(angle), sin(angle), 0.0);
177
glVertex3f(r1*cos(0.0), r1*sin(0.0), width*0.5);
178
glVertex3f(r1*cos(0.0), r1*sin(0.0), -width*0.5);
176
glVertex3f(r1 * cos(0.0), r1 * sin(0.0), width * 0.5);
177
glVertex3f(r1 * cos(0.0), r1 * sin(0.0), -width * 0.5);
181
180
glShadeModel(GL_SMOOTH);
183
182
/* draw inside radius cylinder */
184
183
glBegin(GL_QUAD_STRIP);
185
for (i=0;i<=teeth;i++) {
186
angle = i * 2.0*pi / teeth;
184
for (i = 0; i <= teeth; i++) {
185
angle = i * 2.0 * pi / teeth;
187
186
glNormal3f(-cos(angle), -sin(angle), 0.0);
188
glVertex3f(r0*cos(angle), r0*sin(angle), -width*0.5);
189
glVertex3f(r0*cos(angle), r0*sin(angle), width*0.5);
187
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
188
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
212
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ared);
213
gearGL(1.0f, 4.0f, 1.0f, 20, 0.7f);
216
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, agreen);
217
gearGL(0.5f, 2.0f, 2.0f, 10, 0.7f);
220
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ablue);
221
gearGL(1.3f, 2.0f, 0.5f, 10, 0.7f);
211
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ared);
212
gearGL(1.0f, 4.0f, 1.0f, 20, 0.7f);
215
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, agreen);
216
gearGL(0.5f, 2.0f, 2.0f, 10, 0.7f);
219
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ablue);
220
gearGL(1.3f, 2.0f, 0.5f, 10, 0.7f);
226
225
glEnable(GL_NORMALIZE);
347
343
float zero_plane, float dist,
349
345
/* Perform the perspective projection for one eye's subfield.
350
The projection is in the direction of the negative z axis.
352
-6.0, 6.0, -4.8, 4.8,
353
left, right, bottom, top = the coordinate range, in the plane of zero
354
parallax setting, which will be displayed on the screen. The
355
ratio between (right-left) and (top-bottom) should equal the aspect
356
ratio of the display.
359
near, far = the z-coordinate values of the clipping planes.
362
zero_plane = the z-coordinate of the plane of zero parallax setting.
365
dist = the distance from the center of projection to the plane
369
eye = half the eye separation; positive for the right eye subfield,
370
negative for the left eye subfield.
346
* The projection is in the direction of the negative z axis.
348
* -6.0, 6.0, -4.8, 4.8,
349
* left, right, bottom, top = the coordinate range, in the plane of zero
350
* parallax setting, which will be displayed on the screen. The
351
* ratio between (right-left) and (top-bottom) should equal the aspect
352
* ratio of the display.
355
* near, far = the z-coordinate values of the clipping planes.
358
* zero_plane = the z-coordinate of the plane of zero parallax setting.
361
* dist = the distance from the center of projection to the plane
365
* eye = half the eye separation; positive for the right eye subfield,
366
* negative for the left eye subfield.
373
369
float xmid, ymid, clip_near, clip_far, topw, bottomw, leftw, rightw,
376
372
dx = right - left;
377
373
dy = top - bottom;
419
Application::Application(GHOST_ISystem* system)
415
Application::Application(GHOST_ISystem *system)
420
416
: m_system(system), m_mainWindow(0), m_secondaryWindow(0), m_fullScreenWindow(0),
421
m_gearsTimer(0), m_testTimer(0), m_cursor(GHOST_kStandardCursorFirstCursor),
422
m_exitRequested(false), stereo(false)
417
m_gearsTimer(0), m_testTimer(0), m_cursor(GHOST_kStandardCursorFirstCursor),
418
m_exitRequested(false), stereo(false)
426
422
// Create the main window
427
STR_String title1 ("gears - main window");
423
STR_String title1("gears - main window");
428
424
m_mainWindow = system->createWindow(title1, 10, 64, 320, 200, GHOST_kWindowStateNormal,
429
GHOST_kDrawingContextTypeOpenGL, false, false);
425
GHOST_kDrawingContextTypeOpenGL, false, false);
432
428
std::cout << "could not create main window\n";
436
432
// Create a secondary window
437
STR_String title2 ("gears - secondary window");
433
STR_String title2("gears - secondary window");
438
434
m_secondaryWindow = system->createWindow(title2, 340, 64, 320, 200, GHOST_kWindowStateNormal,
439
GHOST_kDrawingContextTypeOpenGL, false, false);
435
GHOST_kDrawingContextTypeOpenGL, false, false);
440
436
if (!m_secondaryWindow) {
441
cout << "could not create secondary window\n";
437
std::cout << "could not create secondary window\n";
445
441
// Install a timer to have the gears running
446
m_gearsTimer = system->installTimer(0 /*delay*/, 20/*interval*/, gearsTimerProc, m_mainWindow);
442
m_gearsTimer = system->installTimer(0 /*delay*/, 20 /*interval*/, gearsTimerProc, m_mainWindow);
462
bool Application::processEvent(GHOST_IEvent* event)
458
bool Application::processEvent(GHOST_IEvent *event)
464
GHOST_IWindow* window = event->getWindow();
460
GHOST_IWindow *window = event->getWindow();
465
461
bool handled = true;
467
463
switch (event->getType()) {
468
/* case GHOST_kEventUnknown:
465
case GHOST_kEventUnknown:
470
467
case GHOST_kEventCursorButton:
471
468
std::cout << "GHOST_kEventCursorButton"; break;
472
469
case GHOST_kEventCursorMove:
473
470
std::cout << "GHOST_kEventCursorMove"; break;
475
case GHOST_kEventWheel:
477
GHOST_TEventWheelData* wheelData = (GHOST_TEventWheelData*) event->getData();
478
if (wheelData->z > 0)
489
case GHOST_kEventKeyUp:
492
case GHOST_kEventKeyDown:
494
GHOST_TEventKeyData* keyData = (GHOST_TEventKeyData*) event->getData();
495
switch (keyData->key) {
498
int cursor = m_cursor;
500
if (cursor >= GHOST_kStandardCursorNumCursors) {
501
cursor = GHOST_kStandardCursorFirstCursor;
503
m_cursor = (GHOST_TStandardCursor)cursor;
504
window->setCursorShape(m_cursor);
511
m_system->setCursorPosition(x,y);
516
if (!m_system->getFullScreen()) {
517
// Begin fullscreen mode
518
GHOST_DisplaySetting setting;
521
setting.frequency = 50;
522
setting.xPixels = 640;
523
setting.yPixels = 480;
524
m_system->beginFullScreen(setting, &m_fullScreenWindow, false /* stereo flag */);
527
m_system->endFullScreen();
528
m_fullScreenWindow = 0;
533
window->setCursorVisibility(!window->getCursorVisibility());
539
m_system->getModifierKeyState(GHOST_kModifierKeyLeftShift,down);
541
std::cout << "left shift down\n";
543
m_system->getModifierKeyState(GHOST_kModifierKeyRightShift,down);
545
std::cout << "right shift down\n"; }
546
m_system->getModifierKeyState(GHOST_kModifierKeyLeftAlt,down);
548
std::cout << "left Alt down\n";
550
m_system->getModifierKeyState(GHOST_kModifierKeyRightAlt,down);
552
std::cout << "right Alt down\n";
554
m_system->getModifierKeyState(GHOST_kModifierKeyLeftControl,down);
556
std::cout << "left control down\n";
558
m_system->getModifierKeyState(GHOST_kModifierKeyRightControl,down);
560
std::cout << "right control down\n";
566
if (m_system->getFullScreen())
568
m_system->endFullScreen();
569
m_fullScreenWindow = 0;
571
m_exitRequested = true;
574
case GHOST_kKeyS: // toggle mono and stereo
583
m_testTimer = m_system->installTimer(0, 1000, testTimerProc);
587
m_system->removeTimer(m_testTimer);
597
m_mainWindow->getTitle(title);
599
m_mainWindow->setTitle(title);
610
case GHOST_kEventWindowClose:
612
GHOST_IWindow* window2 = event->getWindow();
613
if (window2 == m_mainWindow) {
614
m_exitRequested = true;
617
m_system->disposeWindow(window2);
622
case GHOST_kEventWindowActivate:
626
case GHOST_kEventWindowDeactivate:
630
case GHOST_kEventWindowUpdate:
632
GHOST_IWindow* window2 = event->getWindow();
633
if(!m_system->validWindow(window2))
472
case GHOST_kEventWheel:
474
GHOST_TEventWheelData *wheelData = (GHOST_TEventWheelData *) event->getData();
475
if (wheelData->z > 0)
485
case GHOST_kEventKeyUp:
488
case GHOST_kEventKeyDown:
490
GHOST_TEventKeyData *keyData = (GHOST_TEventKeyData *) event->getData();
491
switch (keyData->key) {
494
int cursor = m_cursor;
496
if (cursor >= GHOST_kStandardCursorNumCursors) {
497
cursor = GHOST_kStandardCursorFirstCursor;
499
m_cursor = (GHOST_TStandardCursor)cursor;
500
window->setCursorShape(m_cursor);
506
int x = 200, y = 200;
507
m_system->setCursorPosition(x, y);
512
if (!m_system->getFullScreen()) {
513
// Begin fullscreen mode
514
GHOST_DisplaySetting setting;
517
setting.frequency = 50;
518
setting.xPixels = 640;
519
setting.yPixels = 480;
520
m_system->beginFullScreen(setting, &m_fullScreenWindow, false /* stereo flag */);
523
m_system->endFullScreen();
524
m_fullScreenWindow = 0;
529
window->setCursorVisibility(!window->getCursorVisibility());
535
m_system->getModifierKeyState(GHOST_kModifierKeyLeftShift, down);
537
std::cout << "left shift down\n";
539
m_system->getModifierKeyState(GHOST_kModifierKeyRightShift, down);
541
std::cout << "right shift down\n";
543
m_system->getModifierKeyState(GHOST_kModifierKeyLeftAlt, down);
545
std::cout << "left Alt down\n";
547
m_system->getModifierKeyState(GHOST_kModifierKeyRightAlt, down);
549
std::cout << "right Alt down\n";
551
m_system->getModifierKeyState(GHOST_kModifierKeyLeftControl, down);
553
std::cout << "left control down\n";
555
m_system->getModifierKeyState(GHOST_kModifierKeyRightControl, down);
557
std::cout << "right control down\n";
563
if (m_system->getFullScreen())
565
m_system->endFullScreen();
566
m_fullScreenWindow = 0;
568
m_exitRequested = true;
571
case GHOST_kKeyS: // toggle mono and stereo
580
m_testTimer = m_system->installTimer(0, 1000, testTimerProc);
584
m_system->removeTimer(m_testTimer);
594
m_mainWindow->getTitle(title);
596
m_mainWindow->setTitle(title);
607
case GHOST_kEventWindowClose:
609
GHOST_IWindow *window2 = event->getWindow();
610
if (window2 == m_mainWindow) {
611
m_exitRequested = true;
614
m_system->disposeWindow(window2);
619
case GHOST_kEventWindowActivate:
623
case GHOST_kEventWindowDeactivate:
627
case GHOST_kEventWindowUpdate:
629
GHOST_IWindow *window2 = event->getWindow();
630
if (!m_system->validWindow(window2))
636
633
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
640
637
View(window2, stereo, LEFT_EYE);