Skip to contents

A 2D camera with position, zoom (frame width/height), and rotation. The camera defines the coordinate-to-pixel mapping used by the renderer.

Public fields

frame_center

Center of the camera frame in world coordinates

frame_width

Width of the visible frame in world units

frame_height

Height of the visible frame in world units

rotation

Camera rotation in radians

background_color

Background color

pixel_width

Output width in pixels

pixel_height

Output height in pixels

Methods


Method new()

Create a new Camera

Usage

Camera$new(
  frame_center = ORIGIN,
  frame_width = FRAME_WIDTH,
  frame_height = FRAME_HEIGHT,
  background_color = "#000000",
  pixel_width = 1920,
  pixel_height = 1080
)

Arguments

frame_center

Center position c(x, y, z)

frame_width

Visible width in world units

frame_height

Visible height in world units

background_color

Background color

pixel_width

Output pixel width

pixel_height

Output pixel height


Method get_zoom()

Get the zoom level (1.0 = default frame width)

Usage

Camera$get_zoom()


Method set_zoom()

Set zoom level

Usage

Camera$set_zoom(zoom)

Arguments

zoom

Zoom factor (> 1 = zoomed in, < 1 = zoomed out)


Method move_to()

Move the camera to a position

Usage

Camera$move_to(point)

Arguments

point

Target position


Method shift()

Shift the camera by a vector

Usage

Camera$shift(direction)

Arguments

direction

Shift vector


Method world_to_pixel()

Convert world coordinates to pixel coordinates

Usage

Camera$world_to_pixel(point)

Arguments

point

World position c(x, y, z)

Returns

Pixel position c(px, py)


Method pixel_to_world()

Convert pixel coordinates to world coordinates

Usage

Camera$pixel_to_world(px, py)

Arguments

px, py

Pixel position

Returns

World position c(x, y, z)


Method get_visible_bounds()

Get the visible bounding box in world coordinates

Usage

Camera$get_visible_bounds()

Returns

List with min and max


Method is_in_frame()

Check if a point is within the visible frame

Usage

Camera$is_in_frame(point, buff = 0)

Arguments

point

World position

buff

Optional buffer around the frame

Returns

Logical


Method print()

Print camera summary

Usage

Camera$print()


Method clone()

The objects of this class are cloneable with this method.

Usage

Camera$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.