API reference

Cameras and input

A camera is a projection, a controller and a transform. You create it with createCamera and refer to it by a CameraHandle. Every frame the engine reads the mouse and keyboard, moves the camera of the frame with its controller, and eases the rendered pose toward the new one. The matrices come from the rendered pose. The controllers are also helpers you can run yourself, on your own cameras and input (section 6).

CPU work GPU buffer
InputEvents SDL or addInputEvent pollEvents once per frame CameraInput drag · wheel · keys updateCamera moves the target Easing pose follows target writes transform rendered pose projection CameraProjection getViewMatrix inverse of the pose getProjectionMatrix fitted to the target aspect scene cull pass every frame, per view SceneData view, projection, planes The camera itself never changes when a target has another shape: the scene passes fit a copy of the projection.
One frame of camera work. Input moves the target; the matrices use the eased rendered pose.

In short

  • A new camera gets a TRACK_BALL controller that orbits a point 1 unit in front of it. Change it with setCameraController.
  • Pass the camera to render, beginFrame or RenderGraph::execute. That camera receives the mouse and keyboard input of the frame, unless its controller is NONE.
  • To move cameras yourself, give them the NONE controller, keep a CameraRig each and set the pose with setCameraTransform (section 6).
  • The projection is reversed-Z: near is depth 1, far is depth 0. A perspective farZ of 0 (the default when you leave it out) means an infinite far plane.
  • fovY is in degrees. Free-fly yaw and pitch are in radians.
  • The camera also holds the exposure the tone-map pass uses: 1 by default, 2 is one stop brighter.
  • An invalid handle logs Invalid camera handle. and the call does nothing (setters) or returns a default value (getters).

1Create a camera

ProjectionFieldsValid values (checked by createCamera and setCameraProjection)
PERSPECTIVEfovY (degrees), aspect, nearZ, farZnearZ finite and > 0. farZ > nearZ, or 0 or infinity for an infinite far plane.
ORTHOGRAPHICleft, right, bottom, top, nearZ, farZnearZ and farZ finite, farZ > nearZ. There is no infinite form.
CameraHandle createCamera(CameraProjection projection, Transform transform);

Creates a camera at transform with the given projection. The camera looks down its local −Z axis, with +Y up. It can be used in the same frame.

projection
Perspective or orthographic, see CameraProjection. Its aspect is replaced by the swapchain aspect when the swapchain is created again (window resize), see updateCameraAspectRatio.
transform
The start pose. Only position and rotation matter for the view. Both the rendered and the target transform start here.

The camera starts with a TRACK_BALL controller: radius 1, center 1 unit in front of the camera, orbitSensitivity 1, easingSpeed 12. So the first drag does not move the camera away from its pose.

errors An invalid projection logs an error and returns an invalid handle. Past MAX_CAMERAS it logs an error and returns an invalid handle. Handle indices start at 1, so 31 cameras fit, and a refused call still uses up an index (B13).

// examples/01_render_graph: farZ is left out (0), so the far plane is infinite
rasm::CameraHandle camera = engine.createCamera(
    rasm::CameraProjection{.type = rasm::CameraProjection::Type::PERSPECTIVE,
                           .perspective{.fovY = 45.0f,
                                        .aspect = 1920.0f / 1080.0f,
                                        .nearZ = 0.1f}},
    rasm::Transform{glm::vec3(0.0f, 0.0f, -1.0f),      // position
                    glm::quat(1.0f, 0.0f, 0.0f, 0.0f), // rotation
                    glm::vec3(1.0f)});                 // scale
engine.addCameraToScene(scene, camera);
struct CameraProjection
{
    enum class Type { PERSPECTIVE, ORTHOGRAPHIC };

    struct Perspective
    {
        float fovY;
        float aspect;
        float nearZ;
        float farZ;
    };

    struct Orthographic
    {
        float left;
        float right;
        float bottom;
        float top;
        float nearZ;
        float farZ;
    };

    Type type;
    union
    {
        Perspective     perspective;
        Orthographic    orthographic;
    };
};

The projection. type says which member of the union is used.

fovY
Vertical field of view in degrees.
aspect
Width / height. The engine sets it for every camera when the swapchain is created; the scene passes use a copy fitted to their target.
nearZ, farZ
Distances in front of the camera, in world units. Perspective: farZ 0 or infinity gives an infinite far plane.
left … top
Orthographic view box in world units, in camera space. A new aspect keeps the width and the center, and changes the height.

2Controllers

TRACK_BALL center radius camera, looks at center drag: orbit wheel: radius − wheel steps position = center + radius × (rotation × +Z) FREE_FLY W: forward (−Z) S: back A: left D: right drag: yaw around world +Y, pitch (±89°)
The two controllers. Both write the target transform; the rendered transform eases toward it with easingSpeed.
struct CameraController
{
    enum class Type { TRACK_BALL, FREE_FLY, NONE };
    enum class OrbitStyle : uint32_t { TURNTABLE, ARCBALL };

    struct TrackBall
    {
        float       radius;
        glm::dvec3  center;
        float       orbitSensitivity;
        OrbitStyle  style;
        glm::vec3   up;
    };

    struct FreeFly
    {
        float yaw;
        float pitch;
        float speed;
        float lookSensitivity;
        glm::vec3 up;
    };

    Type type;
    union
    {
        TrackBall   trackBall;
        FreeFly     freeFly;
    };

    float easingSpeed = 12.0f;
};

How input moves the camera. type says which member of the union is used. In rasm/cameraController.h, which rasm/camera.h includes.

type
TRACK_BALL or FREE_FLY, or NONE: no controller. beginFrame then leaves the camera alone, and it keeps the pose you set with setCameraTransform. A CameraRig with NONE only eases toward its target.
radius
Orbit distance from center. Each wheel step multiplies it by CAMERA_WHEEL_ZOOM (0.9 forward, 1 / 0.9 backward), never below MIN_TRACK_BALL_RADIUS. The rendered distance eases toward it. With an orthographic projection the wheel scales the box instead (updateCameraRig). A pan drag moves center across the view, at once. orbitSensitivity 0 makes a plan view that only pans and zooms.
center
The point the camera orbits and looks at, in world space, in doubles.
orbitSensitivity
Multiplies the drag rotation: at 1 a turntable turns 90° per NDC unit of drag (half the view's smaller side), and an arcball's scene follows the cursor. 0: a plan view that only pans and zooms.
style
TURNTABLE (the default, 0): the drag's motion turns around up and tilts, short of the poles, with no roll, the same anywhere in the view. ARCBALL: free rotation from the drag's points on Holroyd's ball (a sphere near the centre, a hyperbola outside), rolls included, smooth past the view's edge. How they differ: At the edge of the view.
up (trackball)
The turntable's axis, a globe's local up for example. Zero: +Y.
yaw, pitch
Radians. setCameraController overwrites them from the current view direction, so the view does not jump. Pitch stays within ±89°.
speed
World units per second for W, A, S, D.
lookSensitivity
Radians per NDC unit of mouse drag.
up
The axis the free-fly camera yaws around, and its pitch is measured from: its horizon stays level with the plane across up. Zero, or +Y, is the world's +Y, exactly as without it. On a globe, the local up (the ellipsoid's normal at the place); it may change every frame, as the normal does along a flight. With its own up, yaw counts the turns since the rig started and pitch is the angle above the plane.
easingSpeed
How fast the rendered pose follows the target: each frame it moves 1 − exp(−easingSpeed × dt) of the way. Higher is snappier. 0 or less snaps at once. Once the pose is within one millionth of a unit of the target, and turned by less than about one millionth, it snaps to it, so a camera at rest does not move. The position is a double, so this holds far from the origin too.
void setCameraController(CameraHandle camera, CameraController controller);

Replaces the controller. The camera's rig is made again with createCameraRig from the current rendered pose, so the camera does not jump. Takes effect at the next updateCamera (the next frame).

controller
For FREE_FLY, yaw and pitch are computed from the current view direction (roll is lost); the values you pass are ignored. For TRACK_BALL, choose center and radius so that the camera already sits on the orbit (see the example). Otherwise the camera moves onto the orbit sphere at the next frame.
// examples/01_render_graph: orbit the bunny at (0, 0, -10)
const glm::vec3 orbitCenter(0.0f, 0.0f, -10.0f);
const glm::vec3 position = glm::vec3(engine.getCameraTransform(camera).position);
engine.setCameraController(camera, rasm::CameraController{
                                       .type = rasm::CameraController::Type::TRACK_BALL,
                                       .trackBall = {.radius = glm::length(orbitCenter - position),
                                                     .center = orbitCenter,
                                                     .orbitSensitivity = 1.0f},
                                       .easingSpeed = 6.0f});
CameraController getCameraController(CameraHandle camera);

Returns a copy of the controller, including the current radius, yaw and pitch after input. An invalid handle logs an error and returns CameraController{}.

3Set and read the pose, projection and exposure

Callrendered transformtargetTransformprojection
setCameraTransformsetset–
setCameraProjection––set, if valid
setCameraController–= rendered transform–
updateCamera (every frame, for the camera of beginFrame, unless NONE)eased toward the targetmoved by the controller–
updateCameraAspectRatio––aspect, for every camera
void setCameraTransform(CameraHandle camera, Transform transform);

Moves the camera at once, with no easing: both the rendered and the target transform become transform. The next frame uses it. A camera you drive yourself gets its pose this way each frame (section 6).

With a TRACK_BALL controller the orbit center stays where it was, and the next updateCamera puts the camera back on the orbit sphere around it. To move a trackball camera, call setCameraController after this with a new center and radius.

void destroyCamera(CameraHandle camera);

Destroys the camera and takes it out of every scene's camera list. Its index goes to the next createCamera, so at most MAX_CAMERAS − 1 cameras are alive at once.

errors Refused while a render graph draws a view with this camera, with an error that names the view: destroy that graph first, or let it go out of scope. The graph of render lets go by itself.

Transform getCameraTransform(CameraHandle camera);

Returns the rendered (eased) transform, the one the view matrix uses. An invalid handle logs an error and returns Transform{}. See Transform.

void setCameraProjection(CameraHandle camera, CameraProjection projection);

Replaces the projection. The next frame uses it. An invalid projection (see the table in section 1) logs an error and keeps the old one.

CameraProjection getCameraProjection(CameraHandle camera);

Returns a copy of the stored projection. Its aspect is the one of the last swapchain creation, unless you set another one after it. An invalid handle logs an error and returns CameraProjection{}.

void setCameraExposure(CameraHandle camera, float exposure);

How bright the camera sees the scene: the tone-map pass multiplies the scene's light by it before the tone curve, like a camera's exposure. 1 is the default; 2 is one stop brighter, 0.5 one stop darker. The pass reads it every time it runs, so the next frame shows it. How it works: Tone mapping.

exposure
A linear factor. 0, a negative value or NaN logs an error and keeps the old one.
engine.setCameraExposure(camera, 2.0f); // one stop brighter
float getCameraExposure(CameraHandle camera);

Returns the camera's exposure. An invalid handle logs an error and returns 1.

void setCameraBloomStrength(CameraHandle camera, float strength);

How much the camera's image glows around bright light: the tone-map pass draws lerp(scene, bloom, strength) with the bloom of addBloomPasses, like the haze of a real lens. 0.04 is the default. The passes read it every time they run, and at 0 they dispatch nothing. It has an effect only in a graph with the bloom passes (EngineConfig::bloom for Renderer::render). How it works: Bloom.

strength
The bloom's share of the image, from 0 to 1. A value outside, or NaN, logs an error and keeps the old one.
engine.setCameraBloomStrength(camera, 0.1f); // more glow
void resetCameraHistory(CameraHandle camera);

Drops the TAA history of the camera's views in the next frame (addTaaPass): that frame shows only itself, and TAA builds up again over the next frames. Call it on a camera cut, when the view jumps to another shot, so the old shot does not show through for a moment. A turn of more than 30° or a move of more than 100 near planes in one frame does it by itself. An invalid handle logs an error.

engine.setCameraTransform(camera, nextShot);
engine.resetCameraHistory(camera);
float getCameraBloomStrength(CameraHandle camera);

Returns the camera's bloom strength. An invalid handle logs an error and returns 0.

4Matrices and depth

camera distance along −Z nearZ 1.0 2 × nearZ 0.5 4 × nearZ 0.25 far away → 0 depth depth = nearZ / distance. The depth buffer is cleared to 0 and the test keeps a pixel when depth ≥ the stored one.
Reversed-Z with a float depth buffer keeps good precision far away. With a finite farZ, depth goes from 1 at nearZ to 0 at farZ.
glm::dmat4 getViewMatrix(CameraHandle camera);

World-to-camera matrix of the rendered pose, in doubles: conjugate(rotation) × translate(−position). Scale is ignored. An invalid handle logs an error and returns the identity. Far from the origin its translation needs the doubles; the scene passes do not use it as it is, but move it into the view's render space, where it is the rotation alone.

Render space

Each view draws in the render space of its camera: the world moved so that the camera's position (getCameraTransform(camera).position in the frame the view drew) is the origin. Positions there are small near the camera, so floats keep them precise anywhere in a large world (large worlds). A position read back from the GPU, from a depth buffer or a picking pass, is in render space.

glm::vec3 toRenderPosition(const glm::dvec3& worldPosition, const glm::dvec3& origin);

A world position in the render space of origin, a view's camera position: the difference, taken in doubles, as floats. Free function in rasm/renderSpace.h.

glm::dvec3 toWorldPosition(const glm::vec3& renderPosition, const glm::dvec3& origin);

The world position of a render-space position of origin, in doubles.

// A point a picking pass read back, in the view's render space.
const glm::dvec3 world = rasm::toWorldPosition(picked, cameraPosition);
glm::mat4 getProjectionMatrix(CameraHandle camera);

The projection matrix of the stored projection, with Vulkan depth range [0, 1] and reversed-Z (near = 1, far = 0). An infinite perspective far plane gives a matrix with depth = nearZ / distance. An invalid handle logs an error and returns the identity.

glm::mat4 getProjectionMatrix(CameraHandle camera, float aspect);

The same, fitted to another aspect ratio. The camera itself does not change. A perspective camera keeps its vertical field of view; an orthographic one keeps its width and center. The scene passes call this every frame with the size of their target, so a render target of any shape renders without stretching.

aspect
Width / height of the image you render into.
void updateCameraAspectRatio(float aspect);

Sets the aspect of every camera. The engine calls it with the swapchain's width / height at start-up and after each swapchain re-creation (window resize). You rarely need it: the scene passes fit the aspect to their target anyway.

5Input

InputTRACK_BALLFREE_FLY
Drag with any mouse buttonorbit around center (the scene follows the cursor)look: yaw and pitch
Mouse wheelradius − wheel steps (zoom)–
W S–forward / back, speed units per second
A D–left / right
Esc, closing the windowrunning returns false from now on
F1shows or hides the stats (EngineConfig::showStats): the RASM window with EngineConfig::ui, else the stats overlay
F2cycles the forced LOD: by distance, LOD 0, 1, … 7, by distance (EngineConfig::forcedLod)
F3logs the dump of the next render graph that runs, Renderer::render's or yours (RenderGraph::dump)
A UI window under the mouse, or with the keyboardwith EngineConfig::ui: the camera gets no drag, wheel or WASD, and while a text field takes typing Esc and F1–F3 do nothing (UI with Dear ImGui)

Everything above happens in pollEvents, which runs once per frame: beginFrame calls it unless you did. Call it yourself before render or beginFrame to read this frame's input first, for cameras you move yourself.

void pollEvents();

Starts the frame's input. It measures the frame's step (getDeltaTime), takes the events queued with addInputEvent and then the platform's window events (SDL; none for NATIVE and headless), and applies them all in order to the UI, the built-in keys, the window state (size, minimized, quit) and the engine's CameraInputState for the main window, which gives the frame's getCameraInput.

Only the first call after a beginFrame does this. A second call in the same frame, and the one inside beginFrame, leave this frame's input as it is: they only take the window's new events into the next frame's queue, and stop running() when the window was closed, so a loop that renders no frame can still end. An event you add after it goes into the next frame. beginFrame then runs updateCamera on the camera given to it with that input, unless the camera's controller is NONE or the handle is invalid (no camera to move).

main thread The frame time it measures is capped at 0.1 s, and the first frame has 0. While an SDL window is minimized it waits up to 100 ms for an event.

// examples/05_city: the camera follows the user's input in the same frame.
engine.pollEvents();
rasm::updateCameraRig(rig, engine.getCameraInput());
engine.setCameraTransform(camera, rig.transform);
engine.render(city.scene, camera);
CameraInput getCameraInput() const;

The main window's CameraInput from the last pollEvents, without what the UI took: what the built-in controller of beginFrame's camera gets this frame.

void setCameraButtons(const CameraButtons& buttons);

Which drag each mouse button starts for the engine's own camera input, the one getCameraInput gives (CameraButtons). By default the left button orbits, and the right and middle buttons and Shift + left pan. Set every button to CameraDrag::ORBIT to orbit with any button, as before pans existed.

void setMouseGrab(bool on, WindowHandle window = {});

Grabs the mouse for a camera drag: the SDL platform hides the pointer and sends motion only (InputEvent::dx, dy), so the drag goes on past the window's and the screen's edge, and on release puts the pointer back where the grab began. The engine's own camera input grabs during its drags by itself (in beginFrame, for a camera with a controller). An application with its own CameraInputState per view calls it each frame with the drag's state; one that owns its window (NATIVE) grabs the mouse itself and sends the motion in dx, dy. A headless renderer does nothing.

bool dragging = false;
for (ViewCamera &view : views)
    dragging = dragging || view.input.dragActive;
engine.setMouseGrab(dragging);
const InputEvent* getInputEvents(uint32_t& count) const;

The events the last pollEvents applied, in order: those you added with addInputEvent, then the platform's. With the SDL platform this is how you see its window's events. The pointer stays valid until the next frame's pollEvents.

count
Set to the number of events; 0 before the first poll.
UiInputCapture getUiInputCapture() const;

What the last UI frame took (UiInputCapture), for your own CameraInputState, so a click on a UI window does not turn your camera. All false without EngineConfig::ui.

float getDeltaTime() const;

The frame's step in seconds from the last pollEvents: EngineConfig::fixedDeltaTime when it is above 0, else the measured frame time (0 on the first frame, at most 0.1 s). Pass it to takeCameraInput.

struct CameraInput
{
    glm::vec2 mouseStart = glm::vec2(0.0f);
    glm::vec2 mouseEnd   = glm::vec2(0.0f);
    float     wheelDelta = 0.0f;
    float     deltaTime  = 0.0f;

    bool      forward  = false;
    bool      backward = false;
    bool      left     = false;
    bool      right    = false;

    glm::vec2 panStart = glm::vec2(0.0f);
    glm::vec2 panEnd   = glm::vec2(0.0f);
    glm::vec2 pointer  = glm::vec2(0.0f);
};

One frame of input for updateCamera and updateCameraRig, from takeCameraInput or your own code.

mouseStart, mouseEnd
The orbit drag of this frame (a free-fly camera's look), in NDC with +Y up (toInputNdc). Both axes are divided by the smaller side of the window or area, so the short axis spans [−1, 1] and the long one is wider. Equal values mean no drag.
panStart, panEnd
The pan drag of this frame, in the same NDC: a trackball moves its center by it; a free-fly camera looks with it too. Which button gives which drag: CameraButtons.
pointer
The pointer in the same NDC, where an orthographic view zooms. 0 (the center) when no event told where it is.
wheelDelta
Wheel steps this frame (positive = away from you).
deltaTime
Seconds since the last frame, or EngineConfig::fixedDeltaTime when it is set. Used for free-fly movement and easing.
forward … right
Held keys: W, S, A, D by position.
constexpr float     CAMERA_WHEEL_ZOOM       = 0.9f;
constexpr float     MIN_TRACK_BALL_RADIUS   = 1e-4f;

A wheel step scales a trackball's radius, or an orthographic view's box, by CAMERA_WHEEL_ZOOM: toward the target for a forward step, away for a backward one, so a zoom feels the same at a millimetre and at a kilometre. The radius never goes under MIN_TRACK_BALL_RADIUS, so a zoom out always works again, nor over 109; an orthographic box's smaller half side stays in the same range. In rasm/cameraController.h. How it works: Pan and zoom.

void updateCamera(CameraHandle camera, const CameraInput& input);

Moves the target transform with the camera's controller, then eases the rendered transform toward it. The trackball eases along the orbit sphere, so the camera does not cut inside the orbit. The next matrices use the result.

It runs updateCameraRig on the camera's rig and its projection, so a trackball pans by the camera's own field of view or box, and the wheel zooms an orthographic camera's box at the pointer. beginFrame calls it for its camera with getCameraInput(); you can call it with any input for any camera. A camera with the NONE controller only eases.

6Drive a camera yourself

The controllers are plain structs and free functions with no Engine. Keep a CameraRig per camera, move it each frame with a CameraInput, and give the engine its pose. Give the engine camera the NONE controller, so beginFrame leaves it alone. The input can be the engine's (getCameraInput), your own CameraInputState's (one per view), or made by your code. How it works: Camera controllers.

// examples/19_embedding: its own input state, orbit or fly
engine.setCameraController(camera, rasm::CameraController{.type = rasm::CameraController::Type::NONE});
rasm::CameraRig rig = rasm::createCameraRig(orbit, start);
rasm::CameraInputState cameraInput;

// each frame
engine.pollEvents();
const rasm::UiInputCapture capture = engine.getUiInputCapture();
const rasm::InputArea area = {.width = 1280.0f, .height = 720.0f};
uint32_t count = 0;
const rasm::InputEvent *events = engine.getInputEvents(count);
for (uint32_t i = 0; i < count; ++i)
    rasm::addCameraInputEvent(cameraInput, events[i], area, capture);
rasm::updateCameraRig(rig, rasm::takeCameraInput(cameraInput, capture, engine.getDeltaTime()));
engine.setCameraTransform(camera, rig.transform);
engine.render(scene, camera);
struct CameraRig
{
    CameraController    controller      = {.type = CameraController::Type::NONE};
    Transform           transform       = {};
    Transform           targetTransform = {};
};

What a controller keeps for one camera, in rasm/cameraController.h. Each engine camera holds one too (Camera::rig).

controller
The controller and its state: radius, yaw and pitch change with the input.
transform
The eased pose: the one to render, for setCameraTransform.
targetTransform
The pose the controller wants; transform eases toward it. Set it yourself with the NONE controller to get a smoothed move.
CameraRig createCameraRig(const CameraController& controller, const Transform& transform);

A rig at rest at transform: both poses are set to it. A FREE_FLY controller takes its yaw and pitch from the rotation (a roll is lost), so the view does not jump; a TRACK_BALL keeps its center and radius. Use it to switch controllers from where the camera is.

void updateCameraRig(CameraRig& rig, const CameraInput& input);
void updateCameraRig(CameraRig& rig, CameraProjection& projection, const CameraInput& input);

One frame: the controller moves targetTransform by the input, then transform eases toward it with easingSpeed. With NONE only the easing runs. The same function moves the engine's cameras, so a rig and an engine camera with the same controller and input end in the same pose.

With the camera's projection, a trackball pans by the projection's size at its center (r · tan(fovY / 2), or half the box's smaller side), and for an orthographic projection the wheel scales the box by CAMERA_WHEEL_ZOOM a step and moves the center by the pointer's offset times (1 − the scale), at once: the point under CameraInput::pointer stays put. Set the changed projection back with setCameraProjection. Keep the box's aspect the view's (D49): the engine fits the box's width to the view, so fit the height before each update, as examples/27_cad_views does. Without a projection, a trackball pans as a 45° perspective camera would, and the wheel scales the radius.

rasm::updateCameraRig(view.rig, view.projection, rasm::takeCameraInput(view.input, capture, engine.getDeltaTime()));
engine.setCameraTransform(view.camera, view.rig.transform);
engine.setCameraProjection(view.camera, view.projection);
struct CameraInputState
{
    bool        keysDown[static_cast<uint32_t>(Key::COUNT)] = {};
    float       pointerX        = 0.0f;
    float       pointerY        = 0.0f;
    bool        pointerInWindow = false;
    bool        pointerSeen     = false;
    bool        dragActive      = false;
    CameraDrag  drag            = CameraDrag::NONE;
    MouseButton dragButton      = MouseButton::LEFT;
    glm::vec2   dragStart       = glm::vec2(0.0f);
    glm::vec2   dragEnd         = glm::vec2(0.0f);
    glm::vec2   pointerNdc      = glm::vec2(0.0f);
    float       wheel           = 0.0f;
    CameraButtons buttons       = {};
};

What one camera's input keeps between events, in rasm/cameraInput.h. Feed it a frame's events with addCameraInputEvent, then take the frame's CameraInput with takeCameraInput. The engine keeps one for the main window; keep one per view of your own.

keysDown
Keys held, by position (InputEvent::physicalKey, else key).
pointerX, pointerY, pointerInWindow
The pointer in window points, from the last move or button event; MOUSE_LEAVE clears pointerInWindow.
pointerSeen
A move, button or leave event told where the pointer is. Until then a wheel event counts in every area, since it carries no position.
dragActive, dragStart, dragEnd
A drag that began with a press in the area, outside the UI, in NDC.
drag, dragButton
What the drag does, from buttons, and the button that started it: only that button's release ends it, and other presses during it do nothing.
pointerNdc
The pointer in the area's NDC, from the last move or button event: CameraInput::pointer.
wheel
This frame's wheel steps with the pointer in the area, or not seen yet.
buttons
Which drag each mouse button starts (CameraButtons). Set it before the events, for example a left-button pan in a flat view.
enum class CameraDrag : uint8_t
{
    NONE,
    ORBIT,
    PAN,
};

struct CameraButtons
{
    CameraDrag  left            = CameraDrag::ORBIT;
    CameraDrag  right           = CameraDrag::PAN;
    CameraDrag  middle          = CameraDrag::PAN;
    CameraDrag  back            = CameraDrag::NONE;
    CameraDrag  forward         = CameraDrag::NONE;
    CameraDrag  shiftLeft       = CameraDrag::PAN;
};

Which drag each mouse button starts, in rasm/cameraInput.h. A trackball orbits with an ORBIT drag and moves its center with a PAN drag; a free-fly camera looks with either. NONE: the button does not move the camera. shiftLeft is the left button with Shift held, for a pointer with no middle button. Every button ORBIT is how the camera moved before pans existed. The engine's own: setCameraButtons.

rasm::CameraInputState input;
input.buttons.left = rasm::CameraDrag::PAN; // a CAD convention for a flat view
struct InputArea
{
    float       x               = 0.0f;
    float       y               = 0.0f;
    float       width           = 0.0f;
    float       height          = 0.0f;
};

The rectangle a camera's input belongs to, in window points like InputEvent mouse positions, from the top-left corner: the whole window ({0, 0, width, height} of getMainWindow), or the part one view covers: getInputArea(window, rect) gives it from a view's ViewRect.

void addCameraInputEvent(CameraInputState& state, const InputEvent& event, const InputArea& area, const UiInputCapture& capture);

Applies one event. A press in the area starts the drag state.buttons maps its button to, which goes on outside the area until that button's release; a drag released since the last takeCameraInput keeps its motion for it, and a press before then starts nothing. A move adds its dx, dy to the drag (or its change of position, without them). The wheel counts while the pointer is in the area, or before any event told where it is. A lost FOCUS lets go of every key and ends the drag.

capture
What the UI took (getUiInputCapture): a press or the wheel over a UI window does not reach the camera. Pass {} without a UI.
CameraInput takeCameraInput(CameraInputState& state, const UiInputCapture& capture, float deltaTime);

The frame's CameraInput: the drag while its button is down (as mouseStart and mouseEnd for an orbit, panStart and panEnd for a pan), the pointer, the wheel steps, and W, S, A, D held by position unless the UI has the keyboard. The next frame's drag starts where this one ended, with no wheel steps yet. Call it once per frame.

glm::vec2 toInputNdc(float x, float y, const InputArea& area);

Window points to the camera's NDC: the area's center is 0, both axes are divided by its smaller side, and +Y is up. In an 800 × 600 area, the point (700, 0) is (1, 1).

struct UiInputCapture
{
    bool            mouse           = false;
    bool            keyboard        = false;
    bool            text            = false;
};

What Dear ImGui took from the last UI frame, in rasm/input.h.

mouse
The pointer is over a UI window, or drags one.
keyboard
A UI window has the keyboard focus.
text
A text field takes typing.

7A reference grid

A camera can draw a reference grid in each of its shaded views: an endless (or bounded) plane of lines that stays crisp at any zoom, with the axes in color. It goes over the opaque scene and under see-through draws, vectors and labels. How it works: Reference grids.

struct Grid
{
    bool        enabled         = false;
    glm::dvec3  origin          = glm::dvec3(0.0);
    glm::quat   orientation     = glm::quat(1.0f, 0.0f, 0.0f, 0.0f);
    double      cellSize        = 1.0;
    uint32_t    subdivisions    = 10;
    glm::vec2   extent          = glm::vec2(0.0f);
    glm::vec4   minorColor      = glm::vec4(0.5f, 0.5f, 0.5f, 0.35f);
    glm::vec4   majorColor      = glm::vec4(0.5f, 0.5f, 0.5f, 0.7f);
    float       lineWidth       = 1.0f;
    float       majorLineWidth  = 1.5f;
    bool        axes            = true;
    glm::vec4   xAxisColor      = glm::vec4(0.85f, 0.12f, 0.1f, 1.0f);
    glm::vec4   zAxisColor      = glm::vec4(0.1f, 0.28f, 0.9f, 1.0f);
    float       fadeDistance    = 0.0f;
};

In rasm/grid.h. The plane is the local XZ plane of origin and orientation, its normal the local +Y. The lines come in levels of cellSize × subdivisionsk; each pixel shows the levels whose cells are wide enough there, so a view at any zoom has minor and major lines a few dozen pixels apart.

origin
A point of the plane, in the world, where the axes cross. Lines sit on exact multiples of cellSize from it, also 6 000 km from the world's origin.
orientation
Turns the XZ plane: angleAxis(90°, +X) gives a wall facing +Z (a front view's grid), angleAxis(−90°, +Z) one facing +X.
cellSize
The finest level's cells, in world units, a double: 10−9 to 109. A camera farther from origin than 253 cells shows no grid.
subdivisions
Cells of one level per cell of the next, along a side: 10 for decimal, 2 for binary. 2 to 1000.
extent
Half the grid's size along its X and Z axes; 0 leaves that axis endless.
minorColor, majorColor
Linear color and alpha of the lines and of every subdivisions-th line. They go through exposure and tone mapping, like the scene.
lineWidth, majorLineWidth
In pixels. A line under a pixel wide is drawn a pixel wide and fainter.
axes, xAxisColor, zAxisColor
The lines through origin along the plane's X and Z axes, majorLineWidth + 0.5 pixels wide. Give a wall's vertical axis the Y color (green).
fadeDistance
In a perspective view, the lines fade out from half this distance to it; 0: no fade. Every view fades the grid where it is seen edge-on.
bool setCameraGrid(CameraHandle camera, const Grid& grid);
Grid getCameraGrid(CameraHandle camera);

Sets the grid every shaded view of the camera draws, from the next frame; Grid{} turns it off. An invalid camera, or a grid with a value out of range (a cellSize outside 10−9 to 109, subdivisions outside 2 to 1000, a negative width or extent, NaN), logs an error, keeps the old grid and returns false. Each camera has its own, so each view of a CAD layout can show the plane it looks at.

rasm::Grid grid;
grid.enabled = true;
grid.cellSize = 0.01; // 1 cm, then 10 cm, 1 m, 10 m ...
engine.setCameraGrid(camera, grid);

rasm::Grid wall = grid;
wall.origin = glm::dvec3(0.0, 0.0, -3.0);
wall.orientation = glm::angleAxis(glm::radians(90.0f), glm::vec3(1.0f, 0.0f, 0.0f));
wall.zAxisColor = glm::vec4(0.15f, 0.7f, 0.15f, 1.0f); // the plane's Z is the world's -Y here
engine.setCameraGrid(frontCamera, wall);

8The camera type and limits

struct Camera
{
    CameraProjection projection;
    CameraRig        rig;
    float            exposure = 1.0f;
    float            bloomStrength = 0.04f;
    uint32_t         historyResets = 0;
    Grid             grid          = {};
};

What the engine stores per camera. You never get a Camera directly; use the getters above.

rig
The controller, the rendered pose rig.transform that getViewMatrix uses, and the rig.targetTransform it eases toward (CameraRig).
exposure
The factor the tone-map pass multiplies the scene's light by (setCameraExposure).
historyResets
How many times resetCameraHistory was called; a TAA pass that sees it change drops its history.
bloomStrength
The bloom's share of the tone-mapped image, 0.04 by default (setCameraBloomStrength).
grid
The reference grid its shaded views draw (setCameraGrid).
ConstantValueWhat it limits
MAX_CAMERAS32 (31 usable)cameras in the whole engine, rasm/engine.h
MAX_CAMERAS_PER_SCENE32addCameraToScene per scene, rasm/scene.h
MAX_SCENE_VIEWS32scene views (scene, camera, target) held by render graphs at once (addScenePasses, render(views, count)), so at most 32 camera views at a time, shadow maps included, rasm/scene.h
Known limits

A camera that a render graph draws can't be destroyed until the graph goes (destroyCamera). The engine's own input covers the whole main window: for several views, keep a CameraInputState per view. For the math (coordinate system, viewport flip, depth) see the guide Coordinate spaces and Projection and reversed-Z depth.