Gazebo Rendering

API Reference

6.6.3
Simple demo

This example shows how move the camera automatically.

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/simple_demo
mkdir build
cd build
cmake ..
make

Execute the example:

./simple_demo

You'll see:

[Msg] Loading plugin [ignition-rendering6-ogre]
Engine 'optix' is not supported
===============================
TAB - Switch render engines
ESC - Exit
===============================

Code

The function updateCameras() is called each time the DisplayCB function runs. Using the method SetLocalPosition from the Camera class we can move the camera in the world:

void updateCameras()
{
double angle = g_offset / 2 * M_PI;
double x = sin(angle) * 3.0 + 3.0;
double y = cos(angle) * 3.0;
for (ir::CameraPtr camera : g_cameras)
{
camera->SetLocalPosition(x, y, 0.0);
}
g_offset += 0.0005;
}
T cos(T... args)
T sin(T... args)
shared_ptr< Camera > CameraPtr
Shared pointer to Camera.
Definition: gz/rendering/RenderTypes.hh:107