# Coordinate Transformation

This post is about coordinate transformations which I was confused with so much!

Geometrically, coordinate system (or frame) consists of an origin and basis - a set of three vectors. Bases are not necessarily orthonormal, but it is assumed that bases are orthonormal because it is convenient. Let the origin, bases, and (a,b,c) the coordinates, then we can describe point like this:

In canonical coordinates, the origin is and bases are , , . We can use another origin and basis - . The point can be described in different coordinates.

As are described in canonical coordinates too, we can express this relationship using matrix.

This 4x4 matrix is a coordinate transformation matrix **from an arbitrary frame to the canonical coordinate system.**

Then we can obtain transformation matrix in the other direction. The transformation matrix is the inverse of the matrix above - translation and then rotation. When basis vectors are orthonormal, it is simply transposed matrix.

Now we know how to transform coordinate system! Next we can derive ’gluLookAt’ function using matrices described above. The function changes the world coordinate from the camera coordinate.

When we use gluLookAt, three points are given, *eye* - the position of the camera, *center* - the viewing direction, and *up* - the view-up vector. Using three points, we can create the camera frame (coordinate system). The camera is located at *eye*, viewing at - (OpenGL coordinate), with upward-orientation .

So we now have a transformation matrix from the world coordinates the camera coordinates. Remember it is from canonical coordinates to a new coordinate.

Yay! Now we can write our own gluLookAt function.