quat
Lens Studio v1.0.0+
Description
A quaternion, used to represent rotation.
Constructor
new quat(Number w, Number x, Number y, Number z)
: quat
Creates a new quat.
Methods
dot(quat quat)
: Number
Returns the dot product of the two quats.
equal(quat b)
: Boolean
Returns whether this quat and b
are equal.
getAngle()
: Number
Returns the rotation angle of the quat.
getAxis()
: vec3
Returns the rotation axis of the quat.
invert()
: quat
Returns an inverted version of the quat.
multiply(quat b)
: quat
Returns the product of this quat and b
.
multiplyVec3(vec3 vec3)
: vec3
Returns the result of rotating direction vector vec3
by this quat.
normalize()
: void
Normalizes the quat.
toEulerAngles()
: vec3
Returns an euler angle representation of the quat, in radians.
toString()
: String
Returns a string representation of the quat.
static angleAxis(Number angle, vec3 axis)
: quat
Returns a new quat with angle angle
and axis axis
.
static angleBetween(quat a, quat b)
: Number
Returns the angle between a
and b
.
static fromEulerAngles(Number x, Number y, Number z)
: quat
Returns a new quat using the euler angles x
, y
, z
(in radians).
static fromEulerVec(vec3 eulerVec)
: quat
Returns a new quat using the euler angle eulerVec
(in radians).
static lerp(quat a, quat b, Number t)
: quat
Returns a new quat linearly interpolated between a
and b
.
static lookAt(vec3 forward, vec3 up)
: quat
Returns a new quat with a forward vector forward
and up vector up
.
static quatIdentity()
: quat
Returns the identity quaternion.
static rotationFromTo(vec3 from, vec3 to)
: quat
Returns a rotation quat between direction vectors from
and to
.
static slerp(quat a, quat b, Number t)
: quat
Returns a new quat spherically linearly interpolated between a
and b
.
Properties
w
: Number
w component of the quat.
x
: Number
x component of the quat.
y
: Number
y component of the quat.
z
: Number
z component of the quat.
Examples
// 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);
Still Looking for help?
Visit Support