Skip to content

Class ViewportController

ClassList > ViewportController

Controller for viewport interaction and object selection. More...

  • #include <ViewportController.h>

Inherits the following classes: Controllers

Public Functions

Type Name
virtual void bind (EventPool & pool) override
Bind to EventPool to subscribe to viewport interaction events.

Public Functions inherited from Controllers

See Controllers

Type Name
virtual void bind (EventPool & pool) = 0
Subscribe to relevant events in the EventPool .

Detailed Description

ViewportController manages user interactions within the 3D viewport, primarily object selection via GPU-based picking. It maintains references to framebuffers used for picking (ID buffer) and display (viewport render target).

Selection Mechanism: * GPU renders scene with object IDs encoded as colors to id_fb * Mouse click reads pixel from id_fb at cursor position * Color decoded back to ObjectID * SelectionEvent emitted with picked object

Viewport Management: * Handles ViewportResizeEvent to update framebuffer dimensions * Maintains aspect ratio for camera projection updates * Coordinates with Renderer for framebuffer recreation

Event Integration: * Subscribes to: MouseClickEvent, ViewportResizeEvent, ViewportFocusEvent * Emits: SelectionEvent (object picked), ViewportResizeEvent (size changed)

State Management: * Reads viewport dimensions from UI layer * Queries active camera from SceneContext for ray generation * Updates SelectionManager via emitted events

Note:

Framebuffer pointers are non-owning - managed by Renderer.

Note:

Picking requires id_fb to be rendered before interaction.

Public Functions Documentation

function bind

Bind to EventPool to subscribe to viewport interaction events.

virtual void ViewportController::bind (
    EventPool & pool
) override

Subscribes to events for viewport interactions: * MouseClickEvent: Perform object picking via id_fb read * MouseMoveEvent: Handle hover feedback (optional) * ViewportResizeEvent: Update framebuffer dimensions * ViewportFocusEvent: Handle viewport activation/deactivation

Picking Logic: * On click, query mouse position in viewport coordinates * Read pixel from id_fb at (x, y) * Decode RGB color to ObjectID * Emit SelectionEvent if valid object picked

Resize Logic: * Receive ViewportResizeEvent with new dimensions * Notify Renderer to recreate framebuffers * Update camera aspect ratio via CameraEvent

Parameters:

  • pool EventPool to subscribe to for viewport events

Note:

Framebuffer pointers must be set before handling click events.

Note:

ID buffer rendering must occur before picking is valid.

Implements Controllers::bind



The documentation for this class was generated from the following file src/editor/controllers/ViewportController.h