messageman3
messageman3

Reputation: 21

Problems understanding gluLookAt xyz rotation in FPS scenario

I'm having trouble with gluLookAt.

My camera can rotate along the X and Y axis by piping in relative mouse motion events. The problem is the Z axis - I don't know how to calculate it.

So, my camera can look up, down, left and right. But I can't work out how to completely rotate through 360 degrees!

Could anyone help?

EDIT:

So, here's a trivial example of my code so far:

Point3 test(0,0,0);

Matrix4 camera = Camera::getInstance().getCameraM();
if ((event.motion.xrel > 200) || (event.motion.yrel > 200))
{
    break;
}

float mx = (event.motion.xrel);
float my = -(event.motion.yrel);
mx /= 20;
my /= 20;
test.setX(test.getX()+mx);
test.setY(test.getY()+my);
Camera::getInstance().lookAt(Point3(0,0,15),test,Vector3(0,-1,0));

Camera::lookAt simply wraps up the glu lookAt function.

Upvotes: 0

Views: 398

Answers (1)

Andon M. Coleman
Andon M. Coleman

Reputation: 43319

gluLookAt (...) produces an orthogonal view-space. You already know one of the two axes when you call it (Y-axis is given as up), the Z-axis is computed given the direction from eye to center and then finally the X-axis is the cross product between Y and Z.

By the way, you cannot completely rotate through 360 degrees. At +/- 90 degrees off of horizontal you run into a singularity, where there are two possible ways to represent the same angle. If you interpolate rotation through that Euler angle, then you can wind up flipping your orientation. Effectively if two of your three axes become parallel (which happens when you look straight up or straight down) then things get really messy with Euler angles.

Upvotes: 1

Related Questions