quat
Interface representing a quaternion. A quaternion is represented by (x, y, z, w) coordinates, and represents a 3D rotation. Quaternions can be converted to and from 4x4 rotation matrices with the interfaces in Mat4. Quaternion objects are created with the ecs.math.quat QuatFactory, or through operations on other Quat objects.
Source
The QuatSource interface represents any object that has x, y, z, and w properties and hence can be used as a data source to create a Quat. In addition, QuatSource can be used as an argument to Quat algorithms, meaning that any object with {x: number, y: number, z: number, w: number} properties can be used.
Properties
Quat has the following enumerable properties:
readonly x: number
Access the x component of the quaternion.
readonly y: number
Access the y component of the quaternion.
readonly z: number
Access the z component of the quaternion.
readonly w: number
Access the w component of the quaternion.
Factory
axisAngle
Create a Quat from an axis-angle representation. The direction of the aa vector gives the axis of rotation, and the magnitude of the vector gives the angle, in radians. For example, quat.axisAngle(vec3.up().scale(Math.PI / 2)) represents a 90-degree rotation about the y-axis, and is equivalent to quat.yDegrees(90). If target is supplied, the result will be stored in target and target will be returned. Otherwise, a new Quat will be created and returned.
ecs.math.quat.axisAngle(aa: Vec3Source, target?: Quat) // -> quat
from
Create a Quat from an object with x, y, z, w properties.
ecs.math.quat.from({x, y, z, w}: {x: number, y: number, z: number, w: number) // -> quat
lookAt
Create a Quat representing the rotation required for an object positioned at ‘eye’ to look at an object positioned at ‘target’, with the given ‘up vector.
ecs.math.quat.lookAt(eye: Vec3Source, target: Vec3Source, up: Vec3Source) // -> quat
pitchYawRollDegrees
Construct a quaternion from a pitch / yaw / roll representation, also known as YXZ Euler angles. Rotation is specified in degrees.
ecs.math.quat.pitchYawRollDegrees(v: Vec3Source) // -> quat
pitchYawRollRadians
Construct a quaternion from a pitch / yaw / roll representation, also known as YXZ Euler angles. Rotation is specified in radians.
ecs.math.quat.pitchYawRollRadians(v: Vec3Source) // -> quat
xDegrees
Create a Quat which represents a rotation about the x-axis. Rotation is specified in degrees.
ecs.math.quat.xDegrees(degrees: number) // -> quat
xRadians
Create a Quat which represents a rotation about the x-axis. Rotation is specified in radians.
ecs.math.quat.xRadians(radians: number) // -> quat
xyzw
Create a Quat from x, y, z, w values.
ecs.math.quat.xyzw(x: number, y: number, z: number, w: number) // -> quat
yDegrees
Create a Quat which represents a rotation about the y-axis. Rotation is specified in degrees.
ecs.math.quat.yDegrees(degrees: number) // -> quat
yRadians
Create a Quat which represents a rotation about the y-axis. Rotation is specified in radians.
ecs.math.quat.yRadians(radians: number) // -> quat
zDegrees
Create a Quat which represents a rotation about the z-axis. Rotation is specified in degrees.
ecs.math.quat.zDegrees(degrees: number) // -> quat
zRadians
Create a Quat which represents a rotation about the z-axis. Rotation is specified in radians.
ecs.math.quat.zRadians(radians: number) // -> quat
zero
Create a Quat which represents a zero rotation.
ecs.math.quat.zero() // -> quat
Immutable
The following methods perform calculations using the current value of a Quat without modifying its contents. Methods that return Quat types create new instances. While immutable APIs are generally safer, more readable, and reduce the likelihood of errors, they can become inefficient when a large number of objects are allocated per frame.
If garbage collection impacts performance, consider using the Mutable API described below.
axisAngle
Convert the quaternion to an axis-angle representation. The direction of the vector gives the axis of rotation, and the magnitude of the vector gives the angle, in radians. If ‘target’ is supplied, the result will be stored in ‘target’ and ‘target’ will be returned. Otherwise, a new Vec3 will be created and returned.
existingQuat.axisAngle(target?: Vec3) // -> vec3