Skip to content
Boutter Loïc edited this page Jan 26, 2021 · 1 revision

Overview

Fluffy has a Camera available for both 2D (orthographic) and 3D rendering. The role of the Camera is to provide a projection matrix to use in the shader. But don't worry, out of the box everything is taken care of by the Painter.

Camera position, size and viewport

The position of the camera refers to its center for 2D and to the point you're looking at for 3D. The position does not refer to the top-left coordinates!

The size is used by orthographic cameras (in 3D we use the FOV instead). The size is the portion of the world you wish to display on screen. Your render target might be for example 1280x720px but still you want to display your game at a 800x600px resolution, this is the size. Note that if the aspect ratio of the target and the size does not match, the size can be increased a bit horizontally or vertically to still fill the screen/texture.

The viewport of the camera corresponds to the area of the target you want to render within. A camera viewport is a FloatRect with relative coordinates (between 0 and 1) describing the area of the target you want to render in. This notion is important if you want to split your screen or to display a mini map.

Default camera

You can render your graphics without worrying about the camera (but you probably want to use a specific one), a default camera will be provided to you.

The default camera is an orthographic (2D) one and is intended to be used for your UI (or as a static camera). This camera position will change depending on the window size so that the top-left corner will always be at (0, 0). It allows you to position your UI element (for example) from that corner.

To use the default camera, juste don't provide one to the RenderContext:

void MyLayer::render(RenderContext& context)
{
    // Draw the scene with a camera that is, for example, centered on the player
	context.with(mySceneCamera).bind([&](Painter& painter) {
        painter.draw(myScene);
    });

    // We don't use .with(...) so the default camera will me used
    context.bind([&](Painter& painter) {
        painter.draw(myUI);
    });
}

Orthographic camera

API

Perspective camera

API

Clone this wiki locally