mathmatrix3d

World space to camera space


I am confused on how to convert world space coordinates to camera coordinates.

My current understanding is that I would need to calculate the camera space vector where

n = eyepoint - lookat

u = up(0,1,0) X n(normalized)

v = n X u

Then once I have < U, V, N > would I simply multiply each point by ?


Solution

  • Lets assume:

    Now first construct an orthonormal frame:

    In order to transform the global coord frame into the cam-coord frame you can apply the following matrix M_R:

    • | R_x, R_y, R_z, 0 |
    • | U_x, U_y, U_z, 0 |
    • | -D_x, -D_y, -D_z, 0|
    • | 0.0, 0.0, 0.0, 1.0|

    If your cam is not positioned at global origin you also have to apply a translation M_T:

    • | 1, 0, 0, -e_x |
    • | 0, 1, 0, -e_y |
    • | 0, 0, 1, -e_z|
    • | 0, 0, 0, 1|

    In the end your complete transformation matrix from global to cam-coords is:

    • | R_x, R_y, R_z, (R dot -E) |
    • | U_x, U_y, U_z, (U dot -E) |
    • | -D_x, -D_y, -D_z, (D dot E)|
    • | 0.0, 0.0, 0.0, 1.0|