**Advanced Camera**

**What you can do with the camera:**

- Rotate around all axis
- Move in the direction of the upvector, rightvector and of the view direction

**What's the target of the camera?**

Some years ago I wrote my first camera tutorial. As I didn't want to make it too complex
I didn't add rotation around all axis.

I changed this with my advanced camera.

**How does the camera work?**

The orientation of the camera is described by three vectors: The *view direction* (like in the
first camera), the *right vector* and the *up vector*.

Initially the orientation points along the negative z-axis: View Direction (0|0|-1), Right Vector (1|0|0), UpVector (0|1|0).

Let's say, RotateY is called. This does no longer mean that the orientation is rotated around
the y-axis. Instead, it is rotated around the up vector.

But what does it mean to rotate the "orientation"? It means to rotate the *view direction*,
the *right vector* and the *up vector*. Rotation around a certain straight line is normally
done by multiplying the vector with a rotation matrix. I already had started to implement this kind of
rotation, but then I realized that we have a very special case here which can be handled more easily:

This makes our case special:

- only two vectors must be rotated at each RotateX/Y/Z
- all vectors are perpendicular, so one vector always can be computed by the cross product (i.e. we have to rotate only one vector!)
- the vector which must be rotated around the straight line is perpendicular to the line's direction
- we know the vector which is perpendicular to the vector which must be computed and the line's direction

Let's assume we want to rotate the camera's orientation around the

If you wonder what I need the last two points for, this image might help:

The

If you know want to rotate the

Now you have to add the vector from C to D which is parallel to the

Look at this image, where we have the same situation in 2d:

Here you can see clearly that the new vector (AD) is:

AD = cos(alpha)*AB+sin(alpha)*AE.

It is the same in 3d!

You now can turn a vector around another one (at least in our special case). After you have turned the

The rest is easy to understand:

The new orientation is computed each time a Rotate? method is called. As it is always only one rotation, it does not require too much calculation time.

The Move (or Strafe) methods are also very easy: Simplify stretch the

If you have problems to imagine how the three orientation vectors behave, you can have a look at the sample code Looking at the camera. Here you can use the same keys to control the camera. But the camera is not used for rendering - you can see the three vectors:

Here you can find the downloads to this document.

**************************************************************************

Any comments? Conact me!