PDA

View Full Version : Math is correct, but camera moves away!



hmb104
03-30-2011, 10:11 PM
Hello,

I'm having a problem in moving my camera in a 3d world I created.

This is the init side of my moving function:


xCamera = 0; yCamera = 0; zCamera = Z_POS; // camera posn
viewAngle = -90.0; // along -z axis
xStep = cosf(0.0174532925*(viewAngle)); // step distances
zStep = sinf(0.0174532925*(viewAngle));
xEye = xCamera + (LOOK_AT_DIST * xStep); // look-at posn
yEye = 0;
zEye = zCamera + (LOOK_AT_DIST * zStep);


Then in my special function I call it move:


if(key == GLUT_KEY_UP) {
xCamera += xStep * SPEED;
zCamera += zStep * SPEED;
}
if(key == GLUT_KEY_DOWN) {
xCamera -= xStep * SPEED;
zCamera -= zStep * SPEED;
}
if(key == GLUT_KEY_LEFT) {
viewAngle -= ANGLE_INCR;
xStep = cosf(0.0174532925*(viewAngle));
zStep = sinf(0.0174532925*(viewAngle));
}
if(key == GLUT_KEY_RIGHT) {
viewAngle += ANGLE_INCR;
xStep = cosf(0.0174532925*(viewAngle));
zStep = sinf(0.0174532925*(viewAngle));
}

// new look at position
xEye = xCamera + (xStep * LOOK_AT_DIST) ;
zEye = zCamera + (zStep * LOOK_AT_DIST);
glutPostRedisplay();


Everything works on JOGL, but now I moved all the code to openGL 2.0 on Windows 7 and the movement is in accurate at all.

I'm positive the math is correct.

This is my gluLookAt():
gluLookAt(xCamera, yCamera, zCamera,
xEye, yEye, zEye, 0,1,0);

I'm using a
Any help/comment will be appreciate it.

Thank you

McLeary
03-31-2011, 09:22 AM
void gluLookAt( GLdouble eyeX,
GLdouble eyeY,
GLdouble eyeZ,
GLdouble centerX,
GLdouble centerY,
GLdouble centerZ,
GLdouble upX,
GLdouble upY,
GLdouble upZ);


You inverted the order of gluLookAt parameters. It is center, eye and up, not eye, center and up.