[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 4.9.6 Camera Movement

This section describes how to move the camera.

#### The Camera is a Transform

Internally in the engine the ``csCamera'` class inherits directly from ``csOrthoTransform'` which inherits from ``csReversibleTransform'`. If you work with ``iCamera'` then you can get the reference to this transform with `camera->GetTransform()`. In addition to the transformation a camera also holds a pointer to the current sector.

This means that all operations you have in ``csOrthoTransform'` can be used on the camera. One of the most useful functions there is `LookAt()` with which you can make the camera point to some spot. Using `LookAt()` it is very easy to make a 3rd person view.

In addition to the standard functions from ``csOrthoTransform'` there are a number of other functions that you can use. The most interesting are `MoveWorld()` and `Move()`. These functions will move the camera and make sure that it cannot walk through a wall and also make sure that walking through portals will work. Both functions move the camera a relative amount. The difference between `MoveWorld()` and `Move()` is that the latter will move the camera in camera space. For example, take the following code:

    iCamera* camera;
    camera->GetTransform ().Move (csVector3 (0, 0, 1));

This will move the camera forward in camera space. This means that the camera will walk 'forward' :-) On the other hand:

    iCamera* camera;
    camera->GetTransform ().MoveWorld (csVector3 (0, 0, 1));

This will move the camera in the world so that it goes one unit in the positive Z direction. This will happen independently of the orientation of the camera.

Here is another example which demonstrates how to use the `LookAt()` function. The following example will set a camera at location ``3,5,1'` and let it look at ``3,5,10'`. The up vector of the camera will be ``0,1,0'` (which is default):

    csVector3 camera_pos (3, 5, 1);
    csVector3 look_at_pos (3, 5, 10);
    csVector3 up (0, 1, 0);
    camera->GetTransform ().Move (camera_pos);
    camera->GetTransform ().LookAt (camera_pos - look_at_pos, up);

#### Include Files

The include files useful for this section are:

    #include <iengine/camera.h>
    #include <csgeom/transfrm.h>

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ]

This document was generated using texi2html 1.76.