Skip to content

TrsTransform ​

Transform defined by translation, rotation, and scale components.

TRS transform represents a placement in world space composed as translation times rotation times scale. It is used to position cameras and renderable objects through their transform property. The matrix is computed lazily and cached.

ts
const transform = camera.transform;
transform.setTranslation([0, 0, radius]);
transform.targetTo([0, 0, 0]);

Accessors ​

rotation vec4 ​

A copy of the rotation quaternion.

ts
get rotation(): vec4;

translation vec3 ​

A copy of the translation vector.

ts
get translation(): vec3;

scale vec3 ​

A copy of the scale vector.

ts
get scale(): vec3;

matrix mat4 ​

The composed transform matrix. Recomputed when stale.

ts
get matrix(): mat4;

inverse mat4 ​

The inverse of the composed transform matrix.

ts
get inverse(): mat4;

Methods ​

addRotation() void ​

Composes the given rotation onto the current rotation.

ts
addRotation(q): void;
ParameterDescription
q: quatThe rotation to apply.

setRotation() void ​

Replaces the rotation with the given quaternion.

ts
setRotation(q): void;
ParameterDescription
q: quatThe new rotation.

addTranslation() void ​

Adds the given offset to the translation.

ts
addTranslation(vec): void;
ParameterDescription
vec: vec3The offset to add.

setTranslation() void ​

Replaces the translation with the given vector.

ts
setTranslation(vec): void;
ParameterDescription
vec: vec3The new translation.

addScale() void ​

Multiplies the scale componentwise by the given vector.

ts
addScale(vec): void;
ParameterDescription
vec: vec3The scale factors to apply.

setScale() void ​

Replaces the scale with the given vector.

ts
setScale(vec): void;
ParameterDescription
vec: vec3The new scale.

targetTo() void ​

Rotates the transform to face the given target point. Uses +Y as world up.

ts
targetTo(target): void;
ParameterDescription
target: vec3The world-space point to face.

Released under the MIT License