Ignition Rendering

API Reference

Camera tracking

This example shows a camera tracking a moving target. You can use the keyboard to move the target being tracked, toggle between different tracking modes, and adjust the tracking offsets.

Compile and run the example

Clone the source code, create a build directory and use cmake and make to compile the code:

git clone https://github.com/ignitionrobotics/ign-rendering
cd ign-rendering/examples/camera_tracking
mkdir build
cd build
cmake ..

To run the example:


You'll see:

TAB - Switch render engines
ESC - Exit
W: Move box forward
S: Move box backward
A: Rotate box to the left
D: Rotate box to the right
1: Camera tracking only
2: Camera tracking and
3: Camera tracking and
following (world frame)
T: Toggle smooth tracking
F: Toggle smooth following
Track offset
u/U: +- 0.1 on X
i/I: +- 0.1 on Y
o/O: +- 0.1 on Z
Follow offset
j/J: +- 0.1 on X
k/K: +- 0.1 on Y
l/L: +- 0.1 on Z


There are two main functions in the Camera class that allow us to track and follow the object:

SetTrackTarget: Set a node for camera to track. The camera will automatically change its orientation to face the target being tracked. If a null node is specified, tracking is disabled. In contrast to SetFollowTarget the camera does not change its position when tracking is enabled.

cam->SetTrackTarget(node, g_trackOffset, false);

SetFollowTarget: Set a node for camera to follow. The camera will automatically update its position to keep itself at the specified offset distance from the target being followed. If a null node is specified, camera follow is disabled. In contrast to SetTrackTarget, the camera does not change its orientation when following is enabled.

cam->SetFollowTarget(node, g_followOffset, false);