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.