0

I have a transformation matrix of 3d object in world space with a fixed camera position. I would like to derive the camera matrix (position, look up vector, right vector) if the object wasn't transformed and the camera was transformed instead. How could I compute that? Hope my question makes sense

noOne
  • 60
  • 1
  • 9
  • Rotating and then translating the object is done by `M1= T*R`. Transforming the camera instead is done with `M2`. The point is that if the object is seen from the camera *same for both options* that means `M1=M2` – Ripi2 Sep 27 '17 at 16:00
  • This [lookAt link](https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluLookAt.xml) shows how to derive the matrix when the camera is transformed. – Ripi2 Sep 27 '17 at 16:02
  • see [Understanding 4x4 homogenous transform matrices](https://stackoverflow.com/a/28084380/2521214) so for example you just translate behind the object |(relative to it) and do an inverse to obtain the camera matrix with follow mode ... but of coarse you have to take your conventions ... – Spektre Sep 28 '17 at 08:35

1 Answers1

2

Premise. Let's represent coordinate transformations with 4x4 matrices. Specifically, the 4x4 matrix Qab representing the coordinate transform of frame a from frame b is such that:

  • Its 3x3 upper-left submatrix is the rotation matrix Rab, i.e. the 3x3 orthonormal matrix whose columns are the ordinately the components of the x_b, y_b, z_b unit vectors of frame b, decomposed in frame a.
  • Its 3x1 upper-right submatrix is the translation vector t_ab from the origin of frame a to the origin of frame b, decomposed in frame a.
  • Its 4th row is [0, 0, 0, 1].
  • If p is a point whose coordinates in frame b are p_b= [px_b, py_b, pz_b, 1], then the coordinates p_a= [px_a, py_a, pz_a, 1] of the same point in frame in frame a are given by p_a.T=Qab * p_b.T, where x.T means the transposed of vector x. Note that we append a 1 as a dummy fourth coordinate in order to be able to multiply 3D points by 4x4 matrices.

Now, to your question. Let Qcw be the 4x4 matrix representing the rotation and translation of the camera from the world reference frame, and Qow the analogous transformation of the object from the world.

Then your answer is the camera-from-object transform Qco. We can compute it by noting that we can go from frame o to frame c by first going from o to w, and then from w to c. Therefore it is Qco=Qcw * Qwo, where Qwo=inv(Qow) is the inverse of Qow, and represents the world frame as seen from the object.

Francesco Callari
  • 11,300
  • 2
  • 25
  • 40