Camera2D

class Camera2D : Extension, ChangeEvents(source)

The Camera2D extension enables panning, rotating, and zooming the view with the mouse:

  • left click and drag to pan

  • right click and drag to rotate

  • use the mouse wheel to zoom in and out

Usage: extend(Camera2D())

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
open override val changed: Event<Unit>
Link copied to clipboard
var controls: (MouseEvents, KeyEvents) -> Unit

Sets up and applies mouse and keyboard controls for interacting with the camera. This variable provides event-driven logic to handle user input for panning, rotation, and zooming.

Link copied to clipboard
var defaults: () -> Unit

Reinitialize the camera to its default state, where no transformations (such as rotation, translation, or scaling) are applied.

Link copied to clipboard
open override var enabled: Boolean
Link copied to clipboard
open override val hasChanged: Boolean
Link copied to clipboard
var rotationCenter: Vector2

Represents the center of rotation for the camera in 2D space.

Link copied to clipboard
var view: Matrix44

Represents the 4x4 transformation matrix of the camera view in a 2D drawing environment. This matrix is used to apply custom transformations such as translation, rotation, or scaling to the viewport. By default, it is set to the identity matrix.

Functions

Link copied to clipboard
open override fun afterDraw(drawer: Drawer, program: Program)
Link copied to clipboard
open override fun beforeDraw(drawer: Drawer, program: Program)
Link copied to clipboard
fun isolated(function: Drawer.() -> Unit)

Executes the provided drawing function in an isolated scope, preserving the current drawing state and then restoring it after the function is executed. The ortho projection and custom view transformation are applied during the isolated drawing session.

Link copied to clipboard
fun pan(displacement: Vector2)

Applies a panning transformation to the camera view. The method modifies the current view by translating it based on the provided displacement vector, effectively shifting the camera's view in the scene.

Link copied to clipboard
fun rotate(angle: Double)

Rotates the camera view by a specified angle around its rotation center.

Link copied to clipboard
open override fun setup(program: Program)
Link copied to clipboard
fun setupControls(mouse: MouseEvents, keyboard: KeyEvents)

Configures the mouse interaction events for controlling the camera view and handling transformations such as translation, rotation, and scaling via mouse inputs.

Link copied to clipboard
open fun shutdown(program: Program)
Link copied to clipboard
fun zoom(center: Vector2, factor: Double)

Applies a zoom transformation to the camera view. The transformation is centered around the specified point while adjusting the zoom level by the given factor.