[osg-users] How to add a camera

Robert Osfield robert.osfield at gmail.com
Tue Feb 21 00:45:12 PST 2017


Hi Nico,

On 21 February 2017 at 08:19, Nico Kruithof <nicokruithof at gmail.com> wrote:
> There are two ways to add a camera to a view. First, there is the addSlave
> (osgcamera example) and second, you can add the camera to a group node in
> the scene (osgprerendercubemap example). What is the difference between the
> two and when would you use one or the other?

You can implement the same effects with both approaches so it's mainly
down to conceptual and practical considerations.

Conceptually a Camera assigned to a View(er) as a master Camera or
slave Camera provides guidance on how the viewer views the scene.  So
if you had a HMD you would naturally use two slave Camera, one for
each eye.  Also if you want to do distortion correction again this
would likely be conceptually something associated with how you view
the scene so again would naturally fit as a slave Camera.  Practically
in both these cases configuring the viewer with different combinations
of slave Camera enables you to vary how the scene is viewed on
different physical devices, completely decoupled from the scene graph.

With effects like shadows or reflections conceptually these are
related to the scene that you are viewing rather than how you are
viewing it, so naturally you would put such a Camrea into the scene
graph itself.  Again practically this is a good fit as you can
serialize out the scene graph and then load into a application that
has a completely different viewer setup and it'll work, i.e. you can
move from a desktop to HMD or a powerwall and have the scene still
look as intended without having to hardware the application to it.

The design of osg::Camera and osgViewer is based on these
concepts/practical consideration, the class relationships and naming
all fall naturally from this desire to be able to conceptually and
practically decouple the needs of the viewer from the needs of the
scene.

Robert.



More information about the osg-users mailing list