Skip to content

PerspectiveCamera ​

A camera using a perspective projection.

Perspective projection applies foreshortening: objects appear smaller the farther they are from the camera, which makes this the camera to use for 3D scenes such as volume rendering. It pairs naturally with OrbitControls.

The projection is defined by a vertical field of view, an aspect ratio, and near/far clipping planes. Zooming narrows or widens the field of view rather than moving the camera.

ts
const camera = new PerspectiveCamera({ fov: 45 });

const controls = new OrbitControls(camera, {
  radius: 1200,
  target: [0, 0, 0],
});

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

Extends Camera and inherits all public properties and methods.

Constructor ​

Creates a perspective camera from the given projection settings.

ts
new PerspectiveCamera(props?): PerspectiveCamera;
ParameterDescription
props: PerspectiveCameraPropsInitialization properties. Defaults to {}.

Types ​

PerspectiveCameraProps ​

Initialization properties for constructing a perspective camera.

PropertyDescription
fov?: numberVertical field of view in degrees. Defaults to 60.
aspectRatio?: numberAspect ratio (width / height). Defaults to 1.77.
near?: numberNear clipping plane distance. Defaults to 0.1.
far?: numberFar clipping plane distance. Defaults to 10000.
position?: vec3World-space camera position. Defaults to the origin.

Accessors ​

type CameraType overrides ​

Identifies the camera type as PerspectiveCamera.

ts
get type(): CameraType;

fov number ​

The vertical field of view in degrees.

ts
get fov(): number;

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.

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.

Zooming narrows or widens the field of view rather than moving the camera, and the result is clamped to valid angles.

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

Released under the MIT License