Skip to content

OrbitControls ​

Camera controls for orbiting a perspective camera around a target.

Dragging with the left mouse button orbits, dragging with Shift held or with the middle button pans the target, and the scroll wheel zooms by changing the orbit radius. Input adds velocity that damping decays over time.

ts
const camera = new PerspectiveCamera({ near: 1.0 });

const idetik = new Idetik({
  canvas,
  viewports: [{
    camera,
    layers: [volumeLayer],
    cameraControls: new OrbitControls(camera, {
      radius: 100,
      target: [40, 40, 10],
    }),
  }],
});

Implements CameraControls.

Constructor ​

Creates orbit controls and moves the camera to the initial pose.

ts
new OrbitControls(camera, params?): OrbitControls;
ParameterDescription
camera: PerspectiveCameraThe perspective camera to control.
params?: OrbitControlsPropsInitialization properties.

Types ​

OrbitControlsProps ​

Initialization properties for constructing orbit controls.

PropertyDescription
radius?: numberDistance from the target in world units. Defaults to 1.
yaw?: numberInitial azimuth angle in radians. Defaults to 0.
pitch?: numberInitial elevation angle in radians. Defaults to 0.
target?: vec3The point the camera orbits. Defaults to the origin.
dampingFactor?: numberVelocity decay rate between 0 and 1. Defaults to 0.5.
scrollZoom?: ScrollZoomModeWhen the scroll wheel zooms. Defaults to "always".

Accessors ​

radius number ​

The current distance from the target in world units.

ts
get radius(): number;

yaw number ​

The current azimuth angle in radians.

ts
get yaw(): number;

pitch number ​

The current elevation angle in radians.

ts
get pitch(): number;

target vec3 ​

A copy of the point the camera orbits.

ts
get target(): vec3;

isMoving boolean ​

Whether any orbit, pan, or zoom velocity remains.

ts
get isMoving(): boolean;

Methods ​

onEvent() void ​

Handles a pointer or wheel event. Called automatically by the owning viewport unless a layer stops propagation.

ts
onEvent(event): void;
ParameterDescription
event: EventContextThe event with clip and world coordinates attached.

onUpdate() void ​

Applies pending velocities to the camera and decays them toward zero. Called automatically by the render loop once per frame.

ts
onUpdate(dt): void;
ParameterDescription
dt: numberTime since the last frame in seconds.

Released under the MIT License