Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

World space to camera space

Tags:

math

matrix

3d

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 ?

like image 850
Freddy Avatar asked Dec 12 '12 03:12

Freddy


1 Answers

Lets assume:

  • Eye position is E=(e_x, e_y, e_z),
  • Viewing direction is D=(d_x, d_y, d_z)
  • Up-Vector is UP=(up_x, up_y, up_z)

Now first construct an orthonormal frame:

  • R = D X UP
  • U = R X D
  • Now normalize D,R,U and you have an orthonormal frame for the camera (D,R,U)

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:

  • M = M_R * M_T
  • | 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|
like image 83
D-rk Avatar answered Sep 28 '22 13:09

D-rk