SQuaternion
Dans cette classeToString
| Fonction | ToString | Converts a quaternion to a human readable string |
| Fonction | Angle | Returns the angle between two quaternions |
| Fonction | Lerp | Linearly interpolates between this and other quaternion, by factor t and returns the result |
| Fonction | Slerp | Spherically interpolates between this and other quaternion, by factor t and returns the result |
| Fonction | RotateTowards | Rotates this towards other, by no more than t degrees |
| Fonction | Dot | Returns the dot product of this and another quaternion |
| Fonction | Equals | – |
| Fonction | New | Creates a new Quaternion |
| Fonction | Euler | Creates a quaternion using Euler angles. |
| Fonction | AngleAxis | Creates a quaternion from an Angle/Axis pair |
| Fonction | LookRotation | Creates a quaternion a forward vector; presuming up is (0,1,0) |
| Fonction | operator* | The result of using the * operator. |
| Fonction | FromToRotation | Creates a rotation which rotates from a to b. |
| Propriété | X | X axis |
| Propriété | Y | Y axis |
| Propriété | Z | Z axis |
| Propriété | W | W axis |
| Propriété | EulerAngles | Returns the Euler rotation for this Quaternion |
| Propriété | Inverse | Returns the inverse of this quaternion |
| Propriété | Identity | Equivalent of new SQuaternion(0,0,0,1) |
Fonctions
ToString
Converts a quaternion to a human readable string
Valeurs de retour
string
Exemple
aQuaternion = Quaternion.New(0.0, 1.0, 0.0, 0.0)
theString = aQuaternion.ToString()
Angle
Returns the angle between two quaternions
Paramètres
| Nom | Type | Valeur par défaut |
|---|---|---|
| b | SQuaternion | – |
Valeurs de retour
float
Exemple
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
Paramètres
| Nom | Type | Valeur par défaut |
|---|---|---|
| b | SQuaternion | – |
| t | float | – |
Valeurs de retour
SQuaternion
Exemple
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
Paramètres
| Nom | Type | Valeur par défaut |
|---|---|---|
| b | SQuaternion | – |
| t | float | – |
Valeurs de retour
SQuaternion
Exemple
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
Paramètres
| Nom | Type | Valeur par défaut |
|---|---|---|
| b | SQuaternion | – |
| delta | float | – |
Valeurs de retour
SQuaternion
Exemple
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
Paramètres
| Nom | Type | Valeur par défaut |
|---|---|---|
| b | SQuaternion | – |
Valeurs de retour
float
Exemple
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
Paramètres
| Paramètre | Type | Description |
|---|---|---|
| other | SQuaternion | The other Quaternion that we are comparing with. |
Valeurs de retour
bool
Exemple
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
Paramètres
| Nom | Type | Valeur par défaut |
|---|---|---|
| x | float | – |
| y | float | – |
| z | float | – |
| w | float | – |
Valeurs de retour
SQuaternion
Exemple
newQuat = Quaternion.New(0.0, 0.707, 0.0, 0.707)
Euler
Creates a quaternion using Euler angles.
Paramètres
| Nom | Type | Valeur par défaut |
|---|---|---|
| x | float | – |
| y | float | – |
| z | float | – |
Valeurs de retour
SQuaternion
Exemple
newQuat = Quaternion.Euler(0.0, 90.0, 0.0)
AngleAxis
Creates a quaternion from an Angle/Axis pair
Paramètres
| Nom | Type | Valeur par défaut |
|---|---|---|
| axis | SVector | – |
| angle | float | – |
Valeurs de retour
SQuaternion
Exemple
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)
Paramètres
| Nom | Type | Valeur par défaut |
|---|---|---|
| forward | SVector | – |
| up | SVector | – |
Valeurs de retour
SQuaternion
Exemple
local newQuat = Quaternion.LookRotation(Vector.Forward);
-- or
local newQuat = Quaternion.LookRotation(Vector.Forward, Vector.Up);
operator*
The result of using the * operator.
Paramètres
| Nom | Type | Valeur par défaut |
|---|---|---|
| a | SQuaternion | – |
| b | SVector | – |
| b | SQuaternion | – |
Valeurs de retour
SVector SQuaternion
Exemple
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.
Paramètres
| Nom | Type | Valeur par défaut |
|---|---|---|
| a | SVector | – |
| b | SVector | – |
Valeurs de retour
SQuaternion
Exemple
VectorA = Vector.New(0.0,1.0,0.0)
VectorB = Vector.New(1.0,0.0,0.0)
QuaternionFromToRotation = Quaternion.FromToRotation(VectorA, VectorB)
Propriétés
X
X axis
Exemple
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
Exemple
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
Exemple
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
Exemple
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);
EulerAnglesLecture seule
Returns the Euler rotation for this Quaternion
Exemple
newQuat = Quaternion.New(0.0, 0.707, 0.0, 0.707)
euler = newQuat.EulerAngles
InverseLecture seule
Returns the inverse of this quaternion
Exemple
quat = Quaternion.New(0.0, 0.707, 0.0, 0.707)
inverseQuat = quat.Inverse
IdentityLecture seule
Equivalent of new SQuaternion(0,0,0,1)
Exemple
identity = Quaternion.Identity



