# 3D Camera Transformation

In graphics we usually use a camera analogy, i.e., the viewer, located at the View Reference Point (VRP), observes the scene through a camera and can move around the scene. This is accomplished by defining a viewing coordinate system (VCS) (left handed) which has the position and orientation of the camera. Then we align the VCS with the world coordinate system (WCS), creating a viewing transformation matrix. This matrix is then applied to all the objects in the scene which moves them into the proper position as seen from the VRP. We will assume the world coordinate system is right handed.

First step : Choosing the VCS origin (in world coordinates). This is the VRP, that is, the position of the camera (observer). Next, we define a projection plane (view plane or image plane). Choose a view plane normal vector, N which determines the positive Z axis direction. Next choose a view up vector, V which determines the positive y axis direction. We are through since the positive U (X) axis is orthogonal to the V (Y) and N (Z) axis.

Now that we have defined a VCS (left handed) we must perform a coordinate transformation to align the WCS with the VCS.

A problem with the previous method is that it is not easy for the user to choose N and an orthogonal vector, V. So we will look at an alternative method of determining the Viewing Coordinate System. We ask the viewer to choose the VRP (viewers position), a Focus Point (FP), i.e. center of focus or center of attention, and an up point (UP). Then we compute the Eye Vector (EV) which is the vector from the VRP to the Focus Point. We normalize EV and this becomes N, the normal to the view plane , which is the Z axis of the VCS. The length of EV can be used as the view plane distance, i.e., the distance between the VRP and the View Plane.

Now compute the vector from the VRP to the Up Point. This vector (UV) is not necessarily orthogonal to N so we must construct the up vector which is orthogonal to N. This is given by the following:

 V1 = UV - (N * UV)N Now, normalize V1 and get V.

The third axis U = N × V (since the VCS is left handed). The viewing transformation M transforms objects described in the WCS into the VCS. It is given as:

```     | R  |  0 |
M  = | ---|-----|
| T   |  1 |
```
 Where R = the rotational component, i.e., it rotates the VCS into alignment with the WCS, and T is the translation component, i.e. it translates the VRP into the origin. So we now have two R3 spaces with orthonormal bases X , Y, Z and U, V, N. So we want to find the rotational matrix R, which transforms from one vector space to the other. That is, to transform a point P from UVN space to XYZ space we multiply by R.``` R × Puvn => Pxyz Then : u × R = i v × R = j => L × R = I n × R = k ```

The rotation transformation aligns n with the -z axis, but then we invert the z axis since are converting from a left handed to a right handed system so the composition of these two transformations maps n into the + z axis ;

```	  |  u1  u2   u3  |
where L = |  v1   v2   v3  |
|  n1  n2   n3  |
```

Now L × L-1 = I => R = L-1

Since u, v, n are orthonormal and L is an orthogonal matrix L-1 = LT (transpose).

```		   |  u1  v1   n1  |
Therefore R = LT = |  u2  v2   n2  |
|  u3  v3   n3  |
```

Now M transforms the VRP into the origin of the WCS, so:

(VRP, 1) × M = (0, 0, 0, 1) = VRP × R + T
T = -VRP × R = - (VRP × u, -VRP × v, -VRP × n)

So the complete viewing transformation matrix is as follows:

```   | u1	v1	n1	0 |
M =| u2	v2	n2	0 |
| u3	v3	n3	0 |
|-VRP·u	-VRP·v	 -VRP·n	1 |
```

We can now apply this matrix, M, to all the objects in the scene and it will orient them in the way we want, i.e., as viewed from the VRP.

Last changed September 30, 1998, G. Scott Owen, owen@siggraph.org