title: Camera rotation matrix
body: <p>I am trying to raytrace a video. For that matter, I need the camera roation matrix for every frame, in world coordinates. The camera is at the origin. There are no translation.</p>
  
  <p>I have the trajectory of the camera as changes in rotation for every frame.
  So for every frame, I have three values (roll, yaw, pitch) that describe how much the camera should rotate from this frame to the next. These rotations are to be understand in the camera coordinate system.</p>
  
  <p>How do I compute the world coordinate rotation matrices for the frames?</p>
  
  <p>What I tried:</p>
  
  <pre><code>def rot_x(angle):
      cosa = np.cos(angle)
      sina = np.sin(angle)
      return np.array([[1,0,0], [0, cosa, -sina], [0, sina, cosa]])
  
  def rot_y(angle):
      cosa = np.cos(angle)
      sina = np.sin(angle)
      return np.array([[cosa, 0, sina], [0,1,0], [-sina, 0, cosa]])
  
  def rot_z(angle):
      cosa = np.cos(angle)
      sina = np.sin(angle)
      return np.array([[cosa, -sina, 0], [sina, cosa, 0], [0,0,1]])
  
  matrices = [initial_rot]
  for pitch, yaw, roll in frames_data:
      rx = rot_x(pitch)
      ry = rot_y(yaw)
      rz = rot_z(roll)
      last_matrix = matrices[-1]
      matrices.append(last_matrix.T.dot(rx).dot(ry).dot(rz))
  </code></pre>
  
  <p>(Since last_matrix should be orthonormal, so the inverse of it should be the transpose).</p>
  
  <p>However, something is horribly wrong, the rendered video just flickers in the y dimension. I am sure there is something wrong with the math here..</p>