Skip to content

@web-engine-dev/math


@web-engine-dev/math / Transform

Class: Transform ​

A 3D transform composed of position, rotation, and scale. Immutable by design - all operations return new instances.

Example ​

ts
// Create a transform at position (10, 0, 5) rotated 45° around Y
const transform = new Transform(
  new Vec3(10, 0, 5),
  Quat.fromAxisAngle(Vec3.up(), Math.PI / 4),
  Vec3.one()
);

// Transform a point from local to world space
const worldPos = transform.transformPoint(localPos);

Constructors ​

Constructor ​

new Transform(position?, rotation?, scale?): Transform

Parameters ​

position? ​

Vec3 = ...

rotation? ​

Quat = ...

scale? ​

Vec3 = ...

Returns ​

Transform

Properties ​

position ​

readonly position: Vec3


rotation ​

readonly rotation: Quat


scale ​

readonly scale: Vec3

Methods ​

compose() ​

compose(parent): Transform

Computes the composition of transforms: parent * this. The result represents this transform in the parent's space.

Parameters ​

parent ​

Transform

Parent transform

Returns ​

Transform

Combined transform

Example ​

ts
const parent = Transform.fromPosition(new Vec3(10, 0, 0));
const child = Transform.fromPosition(new Vec3(0, 5, 0));
const worldTransform = child.compose(parent);  // Child at (10, 5, 0)

equals() ​

equals(t, epsilon?): boolean

Parameters ​

t ​

Transform

epsilon? ​

number = 0

Returns ​

boolean


forward() ​

forward(): Vec3

Returns ​

Vec3


inverseTransformDirection() ​

inverseTransformDirection(direction): Vec3

Transforms a direction from world space to local space (ignores position).

Parameters ​

direction ​

Vec3

Returns ​

Vec3


inverseTransformPoint() ​

inverseTransformPoint(point): Vec3

Transforms a point from world space to local space.

Parameters ​

point ​

Vec3

Returns ​

Vec3


invert() ​

invert(): Transform

Computes the inverse transform.

Returns ​

Transform


lerp() ​

lerp(target, t): Transform

Parameters ​

target ​

Transform

t ​

number

Returns ​

Transform


right(): Vec3

Returns ​

Vec3


rotate() ​

rotate(rotation): Transform

Parameters ​

rotation ​

Quat

Returns ​

Transform


rotateLocal() ​

rotateLocal(rotation): Transform

Parameters ​

rotation ​

Quat

Returns ​

Transform


scaleBy() ​

scaleBy(factor): Transform

Parameters ​

factor ​

Vec3

Returns ​

Transform


scaleUniform() ​

scaleUniform(factor): Transform

Parameters ​

factor ​

number

Returns ​

Transform


toMat4() ​

toMat4(): Mat4

Converts to a 4x4 transformation matrix.

Returns ​

Mat4


toString() ​

toString(): string

Returns ​

string


transformDirection() ​

transformDirection(direction): Vec3

Transforms a direction from local space to world space (ignores position).

Parameters ​

direction ​

Vec3

Returns ​

Vec3


transformPoint() ​

transformPoint(point): Vec3

Transforms a point from local space to world space.

Parameters ​

point ​

Vec3

Point in local space

Returns ​

Vec3

Point in world space

Example ​

ts
const transform = Transform.fromPosition(new Vec3(100, 0, 0));
const localPoint = new Vec3(5, 0, 0);
const worldPoint = transform.transformPoint(localPoint);  // (105, 0, 0)

translate() ​

translate(delta): Transform

Parameters ​

delta ​

Vec3

Returns ​

Transform


up() ​

up(): Vec3

Returns ​

Vec3


withPosition() ​

withPosition(position): Transform

Parameters ​

position ​

Vec3

Returns ​

Transform


withRotation() ​

withRotation(rotation): Transform

Parameters ​

rotation ​

Quat

Returns ​

Transform


withScale() ​

withScale(scale): Transform

Parameters ​

scale ​

Vec3

Returns ​

Transform


withUniformScale() ​

withUniformScale(scale): Transform

Parameters ​

scale ​

number

Returns ​

Transform


fromMat4() ​

static fromMat4(m): Transform

Creates a transform from a 4x4 matrix. Note: The matrix should be a valid TRS (Translation-Rotation-Scale) matrix.

Parameters ​

m ​

Mat4

Returns ​

Transform


fromPosition() ​

static fromPosition(position): Transform

Parameters ​

position ​

Vec3

Returns ​

Transform


fromRotation() ​

static fromRotation(rotation): Transform

Parameters ​

rotation ​

Quat

Returns ​

Transform


fromScale() ​

static fromScale(scale): Transform

Parameters ​

scale ​

Vec3

Returns ​

Transform


fromUniformScale() ​

static fromUniformScale(scale): Transform

Parameters ​

scale ​

number

Returns ​

Transform


identity() ​

static identity(): Transform

Returns ​

Transform

Proprietary software. All rights reserved.