# [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
X-direction.

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,
const double focalPoint,
const double viewUp)
{
double matrix;
vtkMatrix4x4::Identity(*matrix);

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

// set the view plane normal from the view vector
viewPlaneNormal = position - focalPoint;
viewPlaneNormal = position - focalPoint;
viewPlaneNormal = position - focalPoint;
vtkMath::Normalize(viewPlaneNormal);

// orthogonalize viewUp and compute viewSideways
vtkMath::Cross(viewUp,viewPlaneNormal,viewSideways);
vtkMath::Normalize(viewSideways);
vtkMath::Cross(viewPlaneNormal,viewSideways,orthoViewUp);

// translate by the vector from the position to the origin
double delta;
delta = -position;
delta = -position;
delta = -position;
delta = 0.0; // yes, this should be zero, not one

vtkMatrix4x4::MultiplyPoint(*matrix,delta,delta);

matrix = delta;
matrix = delta;
matrix = delta;

// apply the transformation
this->Concatenate(*matrix);
}

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