Skip to main content

quat

Class

A quaternion, used to represent rotation.

  • Available on all platforms
Platform details: Snapchat, SPECS, Camera Kit Web, Camera Kit Mobile fully supported.

Platform details

  • Snapchat — Fully supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Fully supported.

  • Camera Kit Mobile — Fully supported.

Index

Example

// Rotate a SceneObject around the world Y axis
//@input SceneObject obj

// Degrees to rotate by
var degrees = 90 * getDeltaTime();

// Convert degrees to radians
var radians = degrees * (Math.PI / 180);

// Axis to rotate around
var axis = vec3.up();

// Rotation we will apply to the object's current rotation
var rotationToApply = quat.angleAxis(radians, axis);

// Get the object's current world rotation
var oldRotation = script.obj.getTransform().getWorldRotation();

// Get the new rotation by rotating the old rotation by rotationToApply
var newRotation = rotationToApply.multiply(oldRotation);

// Set the object's world rotation to the new rotation
script.obj.getTransform().setWorldRotation(newRotation);

Constructors

Constructor

new quat(w, x, y, z): quat

Parameters

ParameterType
wnumber
xnumber
ynumber
znumber

Returns

quat

Properties

w

w: number

w component of the quat.


x

x: number

x component of the quat.


y

y: number

y component of the quat.


z

z: number

z component of the quat.

Methods

angleAxis()

static angleAxis(angle, axis): quat

Returns a new quat with angle angle and axis axis.

Parameters

ParameterType
anglenumber
axisvec3

Returns

quat


angleBetween()

static angleBetween(a, b): number

Returns the angle between a and b.

Parameters

ParameterType
aquat
bquat

Returns

number


dot()

dot(quat): number

Returns the dot product of the two quats.

Parameters

ParameterType
quatquat

Returns

number


equal()

equal(quat): boolean

Returns whether this quat and b are equal.

Parameters

ParameterType
quatquat

Returns

boolean


fromEulerAngles()

static fromEulerAngles(x, y, z): quat

Returns a new quat using the euler angles x, y, z (in radians).

Parameters

ParameterType
xnumber
ynumber
znumber

Returns

quat


fromEulerVec()

static fromEulerVec(eulerAngles): quat

Returns a new quat using the euler angle eulerVec (in radians).

Parameters

ParameterType
eulerAnglesvec3

Returns

quat


fromRotationMat()

static fromRotationMat(rotationMat): quat

Creates a quaternion from a matrix.

Parameters

ParameterType
rotationMatmat3

Returns

quat


fromRotationMat4()

static fromRotationMat4(rotationMat4): quat

Creates a quaternion from a mat4.

Parameters

ParameterType
rotationMat4mat4

Returns

quat


getAngle()

getAngle(): number

Returns the rotation angle of the quat.

Returns

number


getAxis()

getAxis(): vec3

Returns the rotation axis of the quat.

Returns

vec3


invert()

invert(): quat

Returns an inverted version of the quat.

Returns

quat


lerp()

static lerp(a, b, time): quat

Returns a new quat linearly interpolated between a and b.

Parameters

ParameterType
aquat
bquat
timenumber

Returns

quat


lookAt()

static lookAt(forward, up): quat

Returns a new quat with a forward vector forward and up vector up.

Parameters

ParameterType
forwardvec3
upvec3

Returns

quat


multiply()

multiply(quat): quat

Returns the product of this quat and b.

Parameters

ParameterType
quatquat

Returns

quat


multiplyVec3()

multiplyVec3(vec3): vec3

Returns the result of rotating direction vector vec3 by this quat.

Parameters

ParameterType
vec3vec3

Returns

vec3


normalize()

normalize(): void

Normalizes the quat.

Returns

void


quatIdentity()

static quatIdentity(): quat

Returns the identity quaternion.

Returns

quat


rotationFromTo()

static rotationFromTo(from, to): quat

Returns a rotation quat between direction vectors from and to.

Parameters

ParameterType
fromvec3
tovec3

Returns

quat


slerp()

static slerp(a, b, time): quat

Returns a new quat spherically linearly interpolated between a and b.

Parameters

ParameterType
aquat
bquat
timenumber

Returns

quat


toEulerAngles()

toEulerAngles(): vec3

Returns an euler angle representation of the quat, in radians.

Returns

vec3


toString()

toString(): string

Returns a string representation of the quat.

Returns

string