quat
ClassA quaternion, used to represent rotation.
- Available on all platforms
Index
Properties
Methods
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
| Parameter | Type |
|---|---|
w | number |
x | number |
y | number |
z | number |
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()
staticangleAxis(angle,axis):quat
Returns a new quat with angle angle and axis axis.
Parameters
| Parameter | Type |
|---|---|
angle | number |
axis | vec3 |
Returns
quat
angleBetween()
staticangleBetween(a,b):number
Returns the angle between a and b.
Parameters
| Parameter | Type |
|---|---|
a | quat |
b | quat |
Returns
number
dot()
dot(
quat):number
Returns the dot product of the two quats.
Parameters
| Parameter | Type |
|---|---|
quat | quat |
Returns
number
equal()
equal(
quat):boolean
Returns whether this quat and b are equal.
Parameters
| Parameter | Type |
|---|---|
quat | quat |
Returns
boolean
fromEulerAngles()
staticfromEulerAngles(x,y,z):quat
Returns a new quat using the euler angles x, y, z (in radians).
Parameters
| Parameter | Type |
|---|---|
x | number |
y | number |
z | number |
Returns
quat
fromEulerVec()
staticfromEulerVec(eulerAngles):quat
Returns a new quat using the euler angle eulerVec (in radians).
Parameters
| Parameter | Type |
|---|---|
eulerAngles | vec3 |
Returns
quat
fromRotationMat()
staticfromRotationMat(rotationMat):quat
Creates a quaternion from a matrix.
Parameters
| Parameter | Type |
|---|---|
rotationMat | mat3 |
Returns
quat
fromRotationMat4()
staticfromRotationMat4(rotationMat4):quat
Creates a quaternion from a mat4.
Parameters
| Parameter | Type |
|---|---|
rotationMat4 | mat4 |
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
invert()
invert():
quat
Returns an inverted version of the quat.
Returns
quat
lerp()
staticlerp(a,b,time):quat
Returns a new quat linearly interpolated between a and b.
Parameters
| Parameter | Type |
|---|---|
a | quat |
b | quat |
time | number |
Returns
quat
lookAt()
staticlookAt(forward,up):quat
Returns a new quat with a forward vector forward and up vector up.
Parameters
Returns
quat
multiply()
multiply(
quat):quat
Returns the product of this quat and b.
Parameters
| Parameter | Type |
|---|---|
quat | quat |
Returns
quat
multiplyVec3()
multiplyVec3(
vec3):vec3
Returns the result of rotating direction vector vec3 by this quat.
Parameters
| Parameter | Type |
|---|---|
vec3 | vec3 |
Returns
normalize()
normalize():
void
Normalizes the quat.
Returns
void
quatIdentity()
staticquatIdentity():quat
Returns the identity quaternion.
Returns
quat
rotationFromTo()
staticrotationFromTo(from,to):quat
Returns a rotation quat between direction vectors from and to.
Parameters
Returns
quat
slerp()
staticslerp(a,b,time):quat
Returns a new quat spherically linearly interpolated between a and b.
Parameters
| Parameter | Type |
|---|---|
a | quat |
b | quat |
time | number |
Returns
quat
toEulerAngles()
toEulerAngles():
vec3
Returns an euler angle representation of the quat, in radians.
Returns
toString()
toString():
string
Returns a string representation of the quat.
Returns
string