SQuaternion
On this classToString
| Function | ToString | Converts a quaternion to a human readable string |
| Function | Angle | Returns the angle between two quaternions |
| Function | Lerp | Linearly interpolates between this and other quaternion, by factor t and returns the result |
| Function | Slerp | Spherically interpolates between this and other quaternion, by factor t and returns the result |
| Function | RotateTowards | Rotates this towards other, by no more than t degrees |
| Function | Dot | Returns the dot product of this and another quaternion |
| Function | Equals | – |
| Function | New | Creates a new Quaternion |
| Function | Euler | Creates a quaternion using Euler angles. |
| Function | AngleAxis | Creates a quaternion from an Angle/Axis pair |
| Function | LookRotation | Creates a quaternion a forward vector; presuming up is (0,1,0) |
| Function | operator* | The result of using the * operator. |
| Function | FromToRotation | Creates a rotation which rotates from a to b. |
| Property | X | X axis |
| Property | Y | Y axis |
| Property | Z | Z axis |
| Property | W | W axis |
| Property | EulerAngles | Returns the Euler rotation for this Quaternion |
| Property | Inverse | Returns the inverse of this quaternion |
| Property | Identity | Equivalent of new SQuaternion(0,0,0,1) |
Functions
ToString
Converts a quaternion to a human readable string
Returns
string
Example
aQuaternion = Quaternion.New(0.0, 1.0, 0.0, 0.0)
theString = aQuaternion.ToString()
Angle
Returns the angle between two quaternions
Parameters
| Name | Type | Default |
|---|---|---|
| b | SQuaternion | – |
Returns
float
Example
local newQuat = Quaternion.New(0.0, 0.707, 0.0, 0.707);
local otherQuat = Quaternion.New(0.0, 1.0, 0.0, 0.0);
angle = newQuat.Angle(otherQuat);
Space.Log(angle);
-- prints 90.0173034667969
Lerp
Linearly interpolates between this and other quaternion, by factor t and returns the result
Parameters
| Name | Type | Default |
|---|---|---|
| b | SQuaternion | – |
| t | float | – |
Returns
SQuaternion
Example
QuatA = Quaternion.New(0.0, 0.707, 0.0, 0.707)
QuatB = Quaternion.New(0.0, 1.0, 0.0, 0.0)
QuatLerpAB = QuatA.Lerp(QuatB, Space.Time * 0.1)
local cube = Space.Host.ExecutingObject
local fromQuat = cube.LocalRotation
local toQuat = Quaternion.New(0.0, 0.707, 0.0, 0.707)
local speed = 0.1
-- The cube will rotate 90 degrees from current rotation by speed amount.
local moveCube = function()
cube.LocalRotation = fromQuat.Lerp(toQuat, Space.Time * speed);
end
cube.OnUpdate(moveCube)
Slerp
Spherically interpolates between this and other quaternion, by factor t and returns the result
Parameters
| Name | Type | Default |
|---|---|---|
| b | SQuaternion | – |
| t | float | – |
Returns
SQuaternion
Example
QuatA = Quaternion.New(0.0, 0.707, 0.0, 0.707)
QuatB = Quaternion.New(0.0, 1.0, 0.0, 0.0)
QuatLerpAB = QuatA.Slerp(QuatB, Space.Time * 0.1)
local cube = Space.Host.ExecutingObject;
local fromQuat = cube.LocalRotation;
local toQuat = Quaternion.New(0.0, 1.0, 0.0, 0.0);
local speed = 0.1;
-- The cube will rotate 180 degrees from current rotation by speed amount.
local moveCube = function()
cube.LocalRotation = fromQuat.Slerp(toQuat, Space.Time * speed)
end
cube.OnUpdate(moveCube)
RotateTowards
Rotates this towards other, by no more than t degrees
Parameters
| Name | Type | Default |
|---|---|---|
| b | SQuaternion | – |
| delta | float | – |
Returns
SQuaternion
Example
QuatA = Quaternion.New(0.0, 0.707, 0.0, 0.707)
QuatB = Quaternion.New(0.0, 1.0, 0.0, 0.0)
ARotatedTowardB = QuatA.RotateTowards(QuatB, Space.Time * 0.1)
local cube = Space.Host.ExecutingObject
local fromQuat = cube.LocalRotation
local target = Quaternion.New(0.0, 0.707, 0.0, 0.707)
local speed = 10.0
-- The cube will rotate 90 degrees from current rotation by step amount.
local moveCube = function()
local step = speed * Space.Time
cube.LocalRotation = fromQuat.RotateTowards(target, step)
end
cube.OnUpdate(moveCube)
Dot
Returns the dot product of this and another quaternion
Parameters
| Name | Type | Default |
|---|---|---|
| b | SQuaternion | – |
Returns
float
Example
local quat = Quaternion.New(0.0, 0.707, 0.0, 0.707);
local quatOther = Quaternion.New(0.0, 0.0, 0.0, 1.0);
Space.Log(quat.Dot(quatOther));
-- prints 0.707000017166138
Equals
Parameters
| Parameter | Type | Description |
|---|---|---|
| other | SQuaternion | The other Quaternion that we are comparing with. |
Returns
bool
Example
QuatA = Quaternion.New(0.0, 0.707, 0.0, 0.707)
QuatB = Quaternion.New(0.0, 1.0, 0.0, 0.0)
isEqual = QuatA.Equals(QuatB)
New
Creates a new Quaternion
Parameters
| Name | Type | Default |
|---|---|---|
| x | float | – |
| y | float | – |
| z | float | – |
| w | float | – |
Returns
SQuaternion
Example
newQuat = Quaternion.New(0.0, 0.707, 0.0, 0.707)
Euler
Creates a quaternion using Euler angles.
Parameters
| Name | Type | Default |
|---|---|---|
| x | float | – |
| y | float | – |
| z | float | – |
Returns
SQuaternion
Example
newQuat = Quaternion.Euler(0.0, 90.0, 0.0)
AngleAxis
Creates a quaternion from an Angle/Axis pair
Parameters
| Name | Type | Default |
|---|---|---|
| axis | SVector | – |
| angle | float | – |
Returns
SQuaternion
Example
newVector = Vector.New(0.0, 90.0, 0.0)
newQuat = Quaternion.AngleAxis(newVector, 90.0)
LookRotation
Creates a quaternion a forward vector; presuming up is (0,1,0)
Parameters
| Name | Type | Default |
|---|---|---|
| forward | SVector | – |
| up | SVector | – |
Returns
SQuaternion
Example
local newQuat = Quaternion.LookRotation(Vector.Forward);
-- or
local newQuat = Quaternion.LookRotation(Vector.Forward, Vector.Up);
operator*
The result of using the * operator.
Parameters
| Name | Type | Default |
|---|---|---|
| a | SQuaternion | – |
| b | SVector | – |
| b | SQuaternion | – |
Returns
SVector SQuaternion
Example
newQuat = Quaternion.New(0.0, 1.0, 0.0, 0.0)
newVector = Vector.Forward
rotatedVector = newQuat * newVector
--or
newQuat = Quaternion.New(0.0, 0.707, 0.0, 0.707)
newVector = Vector.New(0.0, 0.0, 0.0)
rotatedVector = newQuat * newQuat
FromToRotation
Creates a rotation which rotates from a to b.
Usually you use this to rotate a transform so that one of its axes eg. the y-axis - follows a target direction b in world space.
Parameters
| Name | Type | Default |
|---|---|---|
| a | SVector | – |
| b | SVector | – |
Returns
SQuaternion
Example
VectorA = Vector.New(0.0,1.0,0.0)
VectorB = Vector.New(1.0,0.0,0.0)
QuaternionFromToRotation = Quaternion.FromToRotation(VectorA, VectorB)
Properties
X
X axis
Example
newQuat = Quaternion.New(0.0, 1.0, 0.0, 0.0)
newQuat.X = 40.0
obj = Space.Host.ExecutingObject
originalRot = obj.LocalRotation
onStartMethod = function()
Space.Log(originalRot.x)
-- prints the X component of this object as a float
originalRot.x = 0.25
-- assigns 0.25 value to the X component
obj.LocalRotation = originalRot
-- sets the the new rotation
end
obj.OnStart(onStartMethod)
Y
Y axis
Example
newQuat = Quaternion.New(0.0, 1.0, 0.0, 0.0)
newQuat.Y = 40.0
obj = Space.Host.ExecutingObject
originalRot = obj.LocalRotation
onStartMethod = function()
Space.Log(originalRot.y);
-- prints the Y component of this object as a float
originalRot.y = 0.25;
-- assigns 0.25 value to the Y component
obj.LocalRotation = originalRot;
-- sets the the new rotation
end
obj.OnStart(onStartMethod);
Z
Z axis
Example
newQuat = Quaternion.New(0.0, 1.0, 0.0, 0.0)
newQuat.Z = 40.0
local obj = Space.Host.ExecutingObject;
local originalRot = obj.LocalRotation;
obj.SubscribeToEvents();
local onStartMethod = function()
Space.Log(originalRot.z);
-- prints the Z component of this object as a float
originalRot.z = 0.25;
-- assigns 0.25 value to the Z component
obj.LocalRotation = originalRot;
-- sets the the new rotation
end
obj.OnStart(onStartMethod);
W
W axis
Example
newQuat = Quaternion.New(0.0, 1.0, 0.0, 0.0)
newQuat.W = 40.0
local obj = Space.Host.ExecutingObject;
local originalRot = obj.LocalRotation;
obj.SubscribeToEvents();
local onStartMethod = function()
Space.Log(originalRot.w);
-- prints the W component of this object as a float
originalRot.w = 0.25;
-- assigns 0.25 value to the W component
obj.LocalRotation = originalRot;
-- sets the the new rotation
end
obj.OnStart(onStartMethod);
EulerAnglesRead only
Returns the Euler rotation for this Quaternion
Example
newQuat = Quaternion.New(0.0, 0.707, 0.0, 0.707)
euler = newQuat.EulerAngles
InverseRead only
Returns the inverse of this quaternion
Example
quat = Quaternion.New(0.0, 0.707, 0.0, 0.707)
inverseQuat = quat.Inverse
IdentityRead only
Equivalent of new SQuaternion(0,0,0,1)
Example
identity = Quaternion.Identity



