PDA

View Full Version : using own camera matrix vs gluLookAt



paul_kelly2000
02-04-2002, 09:25 AM
I create a camera matrix with the following code segment and multiply the matrix for all objects but it doesn't seem to work correctly. Any ideas?

void myLookAt (
float *m,
float eyex, float eyey, float eyez,
float centerx, float centery, float centerz,
float upx, float upy, float upz)
{
vector3 x;
vector3 y (upx, upy, upz);
vector3 f (centerx - eyex, centery - eyey, centerz - eyez);
vector3 uprime (upx, upy, upz);
vector3 s, u;

uprime.normalize();

f.normalize();

s = CrossProduct (f, uprime);

s.normalize();

u = CrossProduct (s, f);


m[0] = s.x;
m[1] = s.y;
m[2] = s.z;
m[3] = 0.0;
m[4] = u.x;
m[5] = u.y;
m[6] = u.z;
m[7] = 0.0;
m[8] = -f.x;
m[9] = -f.y;
m[10] = -f.z;
m[11] = 0.0;
m[12] = 0.0;
m[13] = 0.0;
m[14] = 0.0;
m[15] = 1.0;
}

Then in the drawing code I do the following after setting the viewing frustum

/**/ myLookAt (
cameraMat,
eye.x,eye.y, eye.z,
center.x, center.y, center.z,
up.x, up.y, up.z); // Up vector

glMultMatrixf(cameraMat);
glTranslated (-eye.x, -eye.y, -eye.z);

then I draw the objects. However, there seems to a problem. Any help would be appreciated.

Bob
02-04-2002, 11:59 PM
OK, a problem... Is it a bluescreen (assuming Windows), a crach, any objects appear at all, wrong colors, wierd movements, or anything else?

paul_kelly2000
02-05-2002, 07:57 AM
This is what's happening...

Whenever I move the camera around, it doesn't keep the center point given to the myLookAt function in the center of the screen. The center point is also the center of a cube. So, the cube doesn't stay centered on the screen.
Whenever I use the gluLookAt, the cube stays centered and the camera always points towards the cube.

Bob
02-05-2002, 08:24 AM
Maybe you forgot to reset the modelview matrix before you muliply your look at matrix by the modelview stack.