simple camera issue...
I'm attempting to write some camera code, pretty simple overall, but I need an up (or right/left) vector to pan (I can get the other with a simple cross product). However, I'm stuck at the up vector.
Here's my code for rotation:
Also, feel free to comment on my sad excuse at coding.
Here's my code for rotation:
Code:
double theta, phi; // global variables, where theta is the vertical spherical angle, and phi is the horizontal.
...
double tempTheta, tempPhi;
tempTheta = ((double)mouseChangedy / HEIGHT) * HALF_PI * 5;
tempPhi = ((double)-mouseChangedx / WIDTH) * M_PI * 5;
phi += tempPhi;
theta += tempTheta;
if (theta > HALF_PI) theta = HALF_PI;
if (theta < -HALF_PI) theta = -HALF_PI;
scn->cam.eye.y = camDistance * sin(theta);
scn->cam.eye.z = camDistance * cos(theta) * cos(phi);
scn->cam.eye.x = camDistance * cos(theta) * sin(phi);
scn->cam.up.y = 1.0 - fabs(sin(theta)); // and here's the y part of the up vector.
scn->cam.up.x = FOO;
scn->cam.up.z = BAR;
// But WHAT is FOO and BAR?Also, feel free to comment on my sad excuse at coding.
It's not magic, it's Ruby.
The way I usually do this is as gluLookAt does -- given the "front" vector (treated as canonical) and the "up" vector (which is approximate only), calculate "right" from the cross product of front and up, then recalculate up from the cross product of right and front. Remember to normalize vectors at appropriate times. That gives you three orthonormal vectors, which can be used as the columns of a matrix to rotate the camera.
thanks, that's pretty much what I decided to do anyway.
It's not magic, it's Ruby.

