[vtkusers] Correctly apply camera matrix

andyjk andrewkeeling at hotmail.com
Mon Apr 8 06:59:11 EDT 2019

Looking deeper - in PerspectiveTransform.cxx we have a function to create the
matrix from a set of view directions.

It looks like vtk does just take the cross-product of Y-Z to get the

However, my confusion is now that the code below stores the rotated X,Y,Z
axes along rows. I thought that it is the *columns* of a rotation matrix
that set its basis ? Can anyone help explain?

void vtkPerspectiveTransform::SetupCamera(const double position[3],
                                          const double focalPoint[3],
                                          const double viewUp[3])
  double matrix[4][4];

  // the view directions correspond to the rows of the rotation matrix,
  // so we'll make the connection explicit
  double *viewSideways =    matrix[0];
  double *orthoViewUp =     matrix[1];
  double *viewPlaneNormal = matrix[2];

  // set the view plane normal from the view vector
  viewPlaneNormal[0] = position[0] - focalPoint[0];
  viewPlaneNormal[1] = position[1] - focalPoint[1];
  viewPlaneNormal[2] = position[2] - focalPoint[2];

  // orthogonalize viewUp and compute viewSideways

  // translate by the vector from the position to the origin
  double delta[4];
  delta[0] = -position[0];
  delta[1] = -position[1];
  delta[2] = -position[2];
  delta[3] = 0.0; // yes, this should be zero, not one


  matrix[0][3] = delta[0];
  matrix[1][3] = delta[1];
  matrix[2][3] = delta[2];

  // apply the transformation

Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html

More information about the vtkusers mailing list