I just got a new PC and now have to get my demo program running with SDL2/OpenGL. I used the program to try out various techniques and used gluLookAt (which, obviously, shouldn't be used any more or even never should have been used).
Now I'm looking for a way to replace the gluLookAt method by building a transformation matrix doing the same as gluLookAt did. I came across this claiming to be usable replacement for gluLookAt (the answer - not the question).
My implementation of it looks like this (I assume j ^ k
means the cross product of j and k - correct me if I'm wrong):
//Compat method: gluLookAt deprecated
void util_compat_gluLookAt(GLfloat eyeX, GLfloat eyeY, GLfloat eyeZ, GLfloat lookAtX, GLfloat lookAtY, GLfloat lookAtZ, GLfloat upX, GLfloat upY, GLfloat upZ) {
Vector3f up (upX, upY, upZ);
Vector3f lookAt (-lookAtX, -lookAtY, -lookAtZ);
Vector3f eye (eyeX, eyeY, eyeZ);
Vector3f i = up ^ lookAt;
Matrix4x4 mat (new GLfloat[16]
{i.getX(), upX, lookAt.getX(), 0,
i.getY(), upY, lookAt.getY(), 0,
i.getZ(), upZ, lookAt.getZ(), 0,
0, 0, 0, 1});
Vector3f translate = mat * (Vector3f()-eye); // Not yet correctly implemented: Negative of vector eye ([0,0,0]-[eyeX,eyeY,eyeZ])
mat.setItem(3,0,translate.getX());
mat.setItem(3,1,translate.getX());
mat.setItem(3,2,translate.getX());
glMultMatrixf(mat.transpose().getComponents());
}
Who did the wrong stuff - my source of information or me? And how can I fix this? NOTE: I won't use this in my actual project, but I still need it for my demo program which will also be reviewed for grading.