int windowWidth, windowHeight, upY;
double scale = 1.0;
+#ifdef FLYING_CAMERA
+Camera eye;
+#endif //FLYING_CAMERA
/**
* @function Graphics_Run
look[2] = 0;
gluPerspective(VIEW_ANGLE, (double)WIDTH/(double)HEIGHT, WORLD_NEAR, WORLD_FAR);
+ #ifdef FLYING_CAMERA
+ eye.x[0] = 1; eye.x[1] = 0; eye.x[2] = 0;
+ eye.y[0] = 0; eye.y[1] = 1; eye.y[2] = 0;
+ eye.z[0] = 0; eye.z[1] = 0; eye.z[2] = 1;
+ #endif //FLYING_CAMERA
+
glutMainLoop();
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
+
+ #ifdef FLYING_CAMERA
+ gluLookAt(eye.p[0], eye.p[1], eye.p[2],
+ eye.p[0] + eye.x[0], eye.p[1] + eye.x[1], eye.p[2] + eye.x[2],
+ eye.z[0], eye.z[1], eye.z[2]);
+ #else
gluLookAt(eyeRho * sin(eyePhi) * sin(eyeTheta), eyeRho * cos(eyePhi),
eyeRho * sin(eyePhi) * cos(eyeTheta),look[0], look[1], look[2], 0, upY, 0);
+ #endif //FLYING_CAMERA
BeforeDraw(); // Stuff to do before graphics is allowed to draw
// Single-thread - perform a computation step, obviously! It's not done anywhere else
return;
}
+ #ifdef FLYING_CAMERA
+ switch (theKey)
+ {
+ case 'W':
+ case 'w':
+ for (unsigned i = 0; i < DIMENSIONS; ++i)
+ eye.p[i] += eye.x[i];
+ break;
+ case 'S':
+ case 's':
+ for (unsigned i = 0; i < DIMENSIONS; ++i)
+ eye.p[i] -= eye.x[i];
+ break;
+ case 'A':
+ case 'a':
+ for (unsigned i = 0; i < DIMENSIONS; ++i)
+ eye.p[i] += eye.y[i];
+ break;
+ case 'D':
+ case 'd':
+ for (unsigned i = 0; i < DIMENSIONS; ++i)
+ eye.p[i] -= eye.y[i];
+ break;
+ case 'Z':
+ case 'z':
+ for (unsigned i = 0; i < DIMENSIONS; ++i)
+ eye.p[i] += eye.z[i];
+ break;
+ case 'C':
+ case 'c':
+ for (unsigned i = 0; i < DIMENSIONS; ++i)
+ eye.p[i] -= eye.z[i];
+ break;
+
+ case 'I':
+ case 'i':
+ {
+ float theta = M_PI/80.0;
+ Camera old = eye;
+
+ for (unsigned i = 0; i < DIMENSIONS; ++i)
+ {
+ eye.z[i] = old.z[i] * cos(theta) + old.x[i] * sin(theta);
+ eye.x[i] = old.x[i] * cos(theta) - old.z[i] * sin(theta);
+ }
+ break;
+ }
+ case 'K':
+ case 'k':
+ {
+ float theta = -M_PI/80.0;
+ Camera old = eye;
+
+ for (unsigned i = 0; i < DIMENSIONS; ++i)
+ {
+ eye.z[i] = old.z[i] * cos(theta) + old.x[i] * sin(theta);
+ eye.x[i] = old.x[i] * cos(theta) - old.z[i] * sin(theta);
+ }
+ break;
+ }
+
+ case 'J':
+ case 'j':
+ {
+ float theta = -M_PI/80.0;
+ Camera old = eye;
+
+ for (unsigned i = 0; i < DIMENSIONS; ++i)
+ {
+ eye.y[i] = old.y[i] * cos(theta) + old.x[i] * sin(theta);
+ eye.x[i] = old.x[i] * cos(theta) - old.y[i] * sin(theta);
+ }
+ break;
+ }
+
+ case 'L':
+ case 'l':
+ {
+ float theta = M_PI/80.0;
+ Camera old = eye;
+
+ for (unsigned i = 0; i < DIMENSIONS; ++i)
+ {
+ eye.y[i] = old.y[i] * cos(theta) + old.x[i] * sin(theta);
+ eye.x[i] = old.x[i] * cos(theta) - old.y[i] * sin(theta);
+ }
+ break;
+ }
+
+ case 'Q':
+ case 'q':
+ {
+ float theta = M_PI/80.0;
+ Camera old = eye;
+
+ for (unsigned i = 0; i < DIMENSIONS; ++i)
+ {
+ eye.z[i] = old.z[i] * cos(theta) + old.y[i] * sin(theta);
+ eye.y[i] = old.y[i] * cos(theta) - old.z[i] * sin(theta);
+ }
+ break;
+ }
+ case 'E':
+ case 'e':
+ {
+ float theta = -M_PI/80.0;
+ Camera old = eye;
+
+ for (unsigned i = 0; i < DIMENSIONS; ++i)
+ {
+ eye.z[i] = old.z[i] * cos(theta) + old.y[i] * sin(theta);
+ eye.y[i] = old.y[i] * cos(theta) - old.z[i] * sin(theta);
+ }
+ break;
+ }
+ }
+
+ /*
+ float x = 0; float y = 0; float z = 0;
+ for (unsigned i = 0; i < DIMENSIONS; ++i)
+ {
+ x += eye.x[i] * eye.x[i];
+ y += eye.y[i] * eye.y[i];
+ z += eye.z[i] * eye.z[i];
+ }
+ for (unsigned i = 0; i < DIMENSIONS; ++i)
+ {
+ eye.x[i] /= sqrt(x);
+ eye.y[i] /= sqrt(y);
+ eye.z[i] /= sqrt(z);
+ }
+ */
+ system("clear");
+ printf("Camera status:\n");
+ printf("Position: %f %f %f\n", eye.p[0], eye.p[1], eye.p[2]);
+ printf("x: %f %f %f (%f)\n", eye.x[0], eye.x[1], eye.x[2], sqrt(eye.x[0]*eye.x[0] + eye.x[1]*eye.x[1] + eye.x[2]*eye.x[2]));
+ printf("y: %f %f %f (%f)\n", eye.y[0], eye.y[1], eye.y[2], sqrt(eye.y[0]*eye.y[0] + eye.y[1]*eye.y[1] + eye.y[2]*eye.y[2]));
+ printf("z: %f %f %f (%f)\n", eye.z[0], eye.z[1], eye.z[2], sqrt(eye.z[0]*eye.z[0] + eye.z[1]*eye.z[1] + eye.z[2]*eye.z[2]));
+
+ #else
+
+
+
if (theKey == 'i' || theKey == 'I') {
eyePhi -= M_PI / 20;
if (eyePhi == 0)
}
if (sin(eyePhi) > 0) upY = 1;
else upY = 1;
+ #endif //FLYING_CAMERA
}
/**