Skip to content

OrthographicCamera ​

A camera using an orthographic (parallel) projection.

Orthographic projection has no perspective foreshortening: objects render at the same size regardless of their distance from the camera, which makes this the camera to use for 2D image viewing. It pairs naturally with PanZoomControls.

The constructor frames a world-space rectangle, typically the physical extent of the image being viewed. Zoom and pan are then applied as scale and translation on top of that frame, and setFrame resets them. When the viewport's aspect ratio differs from the frame's, the frame is padded rather than stretched, so image pixels always stay square.

ts
const camera = new OrthographicCamera({
 left: 0,
 right: 1024,
 top: 0,
 bottom: 1024
});

const idetik = new Idetik({
  canvas: document.querySelector('canvas')!,
  viewports: [{
    camera,
    layers: [imageLayer],
    cameraControls: new PanZoomControls(camera),
  }],
});

Extends Camera and inherits all public properties and methods.

Constructor ​

Creates an orthographic camera framing the given world-space rectangle.

ts
new OrthographicCamera(props): OrthographicCamera;
ParameterDescription
props: OrthographicCameraPropsInitialization properties.

Types ​

OrthographicCameraFrame ​

A world-space rectangle for the camera to frame.

PropertyDescription
left: numberLeft edge of the view frame in world units.
right: numberRight edge of the view frame in world units.
top: numberTop edge of the view frame in world units.
bottom: numberBottom edge of the view frame in world units.

OrthographicCameraProps ​

Initialization properties for constructing an orthographic camera.

PropertyDescription
left: numberLeft edge of the view frame in world units.
right: numberRight edge of the view frame in world units.
top: numberTop edge of the view frame in world units.
bottom: numberBottom edge of the view frame in world units.
near?: numberNear clipping plane distance. Defaults to -1e6.
far?: numberFar clipping plane distance. Defaults to 1e6.
orientation?: SliceOrientationSlice orientation. Defaults to "XY".

Accessors ​

viewportSize [number, number] ​

The world-space size of the rendered view as [width, height].

This is the camera frame padded to match the viewport's aspect ratio, so it reflects what is actually visible rather than the frame that was set.

ts
get viewportSize(): [number, number];

type CameraType overrides ​

Identifies the camera type as OrthographicCamera.

ts
get type(): CameraType;

orientation SliceOrientation ​

The slice orientation the camera faces.

ts
get orientation(): SliceOrientation;

Methods ​

setAspectRatio() void overrides ​

Sets the aspect ratio (width / height) of the viewport the camera renders into. Called automatically by the owning viewport when it resizes.

ts
setAspectRatio(aspectRatio): void;
ParameterDescription
aspectRatio: numberThe viewport's width divided by its height.

setFrame() void ​

Reframes the camera to the given world-space rectangle, resetting any accumulated zoom and pan.

The frame may be padded horizontally or vertically at render time to match the viewport's aspect ratio (see viewportSize).

ts
setFrame(frame): void;
ParameterDescription
frame: OrthographicCameraFrameThe view frame edges in world units.

setOrientation() void ​

Changes the slice orientation the camera faces. The current frame and zoom carry over numerically to the new plane axes. Call setFrame to reframe the view for the new plane.

ts
setOrientation(orientation): void;
ParameterDescription
orientation: SliceOrientationThe slice plane for the camera to face.

zoom() void overrides ​

Zooms the view by the given factor relative to the current zoom level. Factors greater than 1 zoom in and factors between 0 and 1 zoom out.

ts
zoom(factor): void;
ParameterDescription
factor: numberThe magnification factor to apply.

getWorldViewRect() Box2 ​

Computes the world-space rectangle currently visible in the viewport, accounting for zoom, pan, and aspect-ratio padding.

ts
getWorldViewRect(): Box2;

Released under the MIT License