Class: Camera

Camera

Camera class that manages viewport parameters and camera transformations. Acts as a container for parameters needed to define the viewport and camera position, supporting smooth animations between positions using source and target transforms.

The camera maintains two Transform objects:

  • source: represents current position
  • target: represents destination position

Animation between positions is handled automatically by the OpenLIME system unless manually interrupted by user input.


new Camera( [options])

Creates a new Camera instance.

Parameters:
Name Type Argument Description
options Object <optional>

Configuration options

Properties
Name Type Argument Default Description
bounded boolean <optional>
true

Whether to limit camera translation to scene boundaries

maxFixedZoom number <optional>
2

Maximum allowed pixel size

minScreenFraction number <optional>
1

Minimum portion of screen to show when zoomed in

target Transform <optional>

Initial target transform

Source:
Fires:

Methods


copy()

Creates a deep copy of the camera instance.

Source:
Returns:

A new Camera instance with copied properties

Type
Camera

deltaZoom(dt, dz [, x] [, y])

Applies a relative zoom change at a specific point.

Parameters:
Name Type Argument Default Description
dt number

Animation duration in milliseconds

dz number

Relative zoom change factor

x number <optional>
0

X coordinate to zoom around

y number <optional>
0

Y coordinate to zoom around

Source:

fit(box [, dt])

Adjusts the camera to frame a specified bounding box.

Parameters:
Name Type Argument Default Description
box BoundingBox

The box to frame in canvas coordinates

dt number <optional>
0

Animation duration in milliseconds

Source:

fitCameraBox(dt)

Resets the camera to show the entire scene.

Parameters:
Name Type Description
dt number

Animation duration in milliseconds

Source:

getCurrentTransform(time)

Gets the camera transform at a specific time.

Parameters:
Name Type Description
time number

Current time in milliseconds (from performance.now())

Source:
Returns:

The interpolated transform at the specified time

Type
Transform

getGlCurrentTransform(time)

Gets the camera transform at a specific time in device coordinates.

Parameters:
Name Type Description
time number

Current time in milliseconds (from performance.now())

Source:
Returns:

The interpolated transform scaled for device pixels

Type
Transform

glViewport()

Returns the current viewport in device coordinates (accounting for device pixel ratio).

Source:
Returns:

The current viewport scaled for device pixels

Type
Viewport

mapToScene(x, y, transform)

Converts canvas coordinates to scene coordinates using the specified transform.

Parameters:
Name Type Description
x number

X coordinate relative to canvas

y number

Y coordinate relative to canvas

transform Transform

Transform to use for conversion

Source:
Returns:

Coordinates in scene space relative to viewport center

Type
Object

pan(dt, dx, dy)

Pans the camera by a specified amount in canvas coordinates.

Parameters:
Name Type Description
dt number

Animation duration in milliseconds

dx number

Horizontal displacement

dy number

Vertical displacement

Source:

rotate(dt, a)

Rotates the camera around its z-axis.

Parameters:
Name Type Description
dt number

Animation duration in milliseconds

a number

Rotation angle in degrees

Source:

sceneToCanvas(x, y, transform)

Converts scene coordinates to canvas coordinates using the specified transform.

Parameters:
Name Type Description
x number

X coordinate in scene space

y number

Y coordinate in scene space

transform Transform

Transform to use for conversion

Source:
Returns:

Coordinates in canvas space

Type
Object

setPosition(dt, x, y, z, a [, easing])

Sets the camera target parameters for a new position.

Parameters:
Name Type Argument Description
dt number

Animation duration in milliseconds

x number

X component of translation

y number

Y component of translation

z number

Zoom factor

a number

Rotation angle in degrees

easing string <optional>

Easing function name for animation

Source:
Fires:

setViewport(view)

Updates the viewport while maintaining the camera position as close as possible to the previous one.

Parameters:
Name Type Description
view Viewport

The new viewport in CSS coordinates

Source:

zoom(dt, z [, x] [, y])

Zooms the camera to a specific point in canvas coordinates.

Parameters:
Name Type Argument Default Description
dt number

Animation duration in milliseconds

z number

Target zoom level

x number <optional>
0

X coordinate to zoom towards

y number <optional>
0

Y coordinate to zoom towards

Source:

Events


update

The event is fired when the camera target is changed.

Source:

update

The event is fired when a uniform shader variable is changed.

Source: