Skip to content

Adding Camera

sppmacd edited this page Aug 28, 2021 · 3 revisions

In this tutorial I will show you how to setup a custom camera for the scene.

You can customize view using Camera object. That object is also a SceneObject; it must be added to SceneWidget to be used as camera. The basic 2D camera is EGE::Plain2DCamera. Example code:

auto sceneWidget = guiScreen->addNewWidget<EGE::SceneWidget>(scene);
auto camera = scene->addNewObject<EGE::Plain2DCamera>();
camera->setScalingMode(EGE::ScalingMode::Fit);
camera->setSize({100.0, 100.0});
sceneWidget->setCamera(camera);

That code sets camera that is centered on (10, 10) and is zoomed 10x, what means that all objects are 10x bigger. The important thing is scaling mode. It determines in which way the camera will setup its view. There are following scaling modes:

  • None - the camera is positioned using left top corner of window, the 1px on scene is equivalent to 1px on screen (until you add zoom)
  • Centered - the camera is positioned using center of window, the 1px on scene is equivalent to 1px on screen (until you add zoom)
  • Fit - the camera is scaled so that the camera view covers the maximum area of screen. You must set the size of camera, using CameraObject::setDisplaySize(). The proportions are kept.
  • XLocked - the camera is scaled to cover some specific amount of X area, defined by CameraObject::setFOV(). It's like Fit, but only in X coordinate. The proportions are kept.
  • YLocked - the camera is scaled to cover some specific amount of Y area, defined by CameraObject::setFOV(). It's like Fit, but only in Y coordinate. The proportions are kept.
  • Scaled - the camera view area is manually specified by CameraObject::setDisplaySize(). The proportions aren't kept.

Comparison horizontal Comparison vertical

In our example, the camera view covers the 100x100 scene area, that will be displayed in the biggest size that will fit on the screen.
Note that the zoom is applied AFTER applying scaling modes, so the zoom will change camera view dimensions even if explicitly set, e.g if you set ScalingMode::Scaled, size to (100, 100) and zoom to (10), the actual view size will be (10, 10) in scene coordinates.

Clone this wiki locally