I came across a math problem that mystifies me and I can’t sleep very well since then. Taking the function below, wish seems to be a common practice to get a camera view in a 3d world using C++.
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat4x4<T> lookAt
(
detail::tvec3<T> const & eye,
detail::tvec3<T> const & center,
detail::tvec3<T> const & up
)
{
detail::tvec3<T> f = normalize(center - eye);
detail::tvec3<T> u = normalize(up);
detail::tvec3<T> s = normalize(cross(f, u));
u = cross(s, f);
detail::tmat4x4<T> Result(1);
Result[0][0] = s.x;
Result[1][0] = s.y;
Result[2][0] = s.z;
Result[0][1] = u.x;
Result[1][1] = u.y;
Result[2][1] = u.z;
Result[0][2] =-f.x;
Result[1][2] =-f.y;
Result[2][2] =-f.z;
Result[3][0] =-dot(s, eye);
Result[3][1] =-dot(y, eye);
Result[3][2] = dot(f, eye);
}
If my understanding is correct, m[3][0], m[3][1] and m[3][2] refers to the XYZ position in a Column-Major matrix. What’s making me nervous is, when passing the object position, for instance: eye(0, 5, 20) becomes (0, 0, 20.61) after being transformed. How is that possible that the Matrix transforms the actual position?
In my book, it should be :
Result[3][0] =- eye.x
Result[3][1] = -eye.y
Result[3][2] = -eye.z
What am I missing?