Skip to content

Class Engine::CameraSystem

ClassList > Engine > CameraSystem

Moves cameras (follow, shake) and converts them into raylib cameras for rendering.

  • #include <CameraSystem.hpp>

Inherits the following classes: Engine::System

Public Attributes inherited from Engine::System

See Engine::System

Type Name
std::set< Entity > m_Entities

Public Functions

Type Name
virtual void Update (Registry & registry, float dt) override
Moves every camera towards its follow target and decays its shake.

Public Functions inherited from Engine::System

See Engine::System

Type Name
virtual void OnSceneUnloaded (Registry & registry)
Called right before the current scene's entities are destroyed.
virtual void Render (Registry & registry)
World pass: drawn inside the active camera.
virtual void RenderScreen (Registry & registry)
Screen pass: drawn after the world, in window pixels.
virtual void Update (Registry & registry, float dt)
virtual ~System () = default

Public Static Functions

Type Name
Camera2D GetActiveCamera (Registry & registry, float viewportWidth, float viewportHeight)
Builds the raylib camera of the active camera for a given viewport.
Vector2 ScreenToWorld (Registry & registry, Vector2 screen)
Converts a canvas position into a world position.
Vector2 WorldToScreen (Registry & registry, Vector2 world)
Converts a world position into a canvas position.

Public Functions Documentation

function Update

Moves every camera towards its follow target and decays its shake.

virtual void Engine::CameraSystem::Update (
    Registry & registry,
    float dt
) override

Parameters:

  • registry The ECS registry containing the cameras.
  • dt Delta time in seconds.

Implements Engine::System::Update


Public Static Functions Documentation

function GetActiveCamera

Builds the raylib camera of the active camera for a given viewport.

static Camera2D Engine::CameraSystem::GetActiveCamera (
    Registry & registry,
    float viewportWidth,
    float viewportHeight
) 

Returns an identity camera (world == screen) when there is no primary camera, so games without a camera render exactly as before.

Parameters:

  • registry The ECS registry.
  • viewportWidth Width in pixels of the surface being drawn to.
  • viewportHeight Height in pixels of the surface being drawn to.

function ScreenToWorld

Converts a canvas position into a world position.

static Vector2 Engine::CameraSystem::ScreenToWorld (
    Registry & registry,
    Vector2 screen
) 

Parameters:

  • registry The ECS registry.
  • screen Position in virtual-canvas pixels.

function WorldToScreen

Converts a world position into a canvas position.

static Vector2 Engine::CameraSystem::WorldToScreen (
    Registry & registry,
    Vector2 world
) 

Parameters:

  • registry The ECS registry.
  • world Position in world units.


The documentation for this class was generated from the following file /home/runner/work/r-type/r-type/Engine/include/Systems/CameraSystem.hpp