|
|
(17 intermediate revisions by one other user not shown) |
Line 1: |
Line 1: |
− | The SQuaternion struct contains a simple 4D vector of X, Y, Z and W floats designed to represent rotations with orientation.
| + | This page has moved to: https://docs.sine.space/v/scripting/client-scripting/types/squaternion |
− | | + | |
− | ==Fields==
| + | |
− | {{ScriptFunction|float|X|{ get; set; }|X axis|5=
| + | |
− | local obj = Space.Host.ExecutingObject;<br>
| + | |
− | local originalRot = obj.LocalRotation;<br>
| + | |
− | obj.SubscribeToEvents();<br><br>
| + | |
− | local onStartMethod = function()<br>
| + | |
− | Space.Log(originalRot.'''x''');<br>
| + | |
− | ''-- prints the X component of this object as a float''<br><br>
| + | |
− | originalRot.'''x''' = 0.25;<br>
| + | |
− | ''-- assigns 0.25 value to the X component''<br><br>
| + | |
− | obj.LocalRotation = originalRot;<br>
| + | |
− | ''-- sets the the new rotation''<br>
| + | |
− | end<br><br>
| + | |
− | obj.OnStart(onStartMethod);}}
| + | |
− | | + | |
− | {{ScriptFunction|float|Y|{ get; set; }|Y axis|5=
| + | |
− | local obj = Space.Host.ExecutingObject;<br>
| + | |
− | local originalRot = obj.LocalRotation;<br>
| + | |
− | obj.SubscribeToEvents();<br><br>
| + | |
− | local onStartMethod = function()<br>
| + | |
− | Space.Log(originalRot.'''y''');<br>
| + | |
− | ''-- prints the Y component of this object as a float''<br><br>
| + | |
− | originalRot.'''y''' = 0.25;<br>
| + | |
− | ''-- assigns 0.25 value to the Y component''<br><br>
| + | |
− | obj.LocalRotation = originalRot;<br>
| + | |
− | ''-- sets the the new rotation''<br>
| + | |
− | end<br><br>
| + | |
− | obj.OnStart(onStartMethod);}}
| + | |
− | | + | |
− | {{ScriptFunction|float|Z|{ get; set; }|Z axis|5=
| + | |
− | local obj = Space.Host.ExecutingObject;<br>
| + | |
− | local originalRot = obj.LocalRotation;<br>
| + | |
− | obj.SubscribeToEvents();<br><br>
| + | |
− | local onStartMethod = function()<br>
| + | |
− | Space.Log(originalRot.'''z''');<br>
| + | |
− | ''-- prints the Z component of this object as a float''<br><br>
| + | |
− | originalRot.'''z''' = 0.25;<br>
| + | |
− | ''-- assigns 0.25 value to the Z component''<br><br>
| + | |
− | obj.LocalRotation = originalRot;<br>
| + | |
− | ''-- sets the the new rotation''<br>
| + | |
− | end<br><br>
| + | |
− | obj.OnStart(onStartMethod);}}
| + | |
− | | + | |
− | {{ScriptFunction|float|W|{ get; set; }|W axis|5=
| + | |
− | local obj = Space.Host.ExecutingObject;<br>
| + | |
− | local originalRot = obj.LocalRotation;<br>
| + | |
− | obj.SubscribeToEvents();<br><br>
| + | |
− | local onStartMethod = function()<br>
| + | |
− | Space.Log(originalRot.'''w''');<br>
| + | |
− | ''-- prints the W component of this object as a float''<br><br>
| + | |
− | originalRot.'''w''' = 0.25;<br>
| + | |
− | ''-- assigns 0.25 value to the W component''<br><br>
| + | |
− | obj.LocalRotation = originalRot;<br>
| + | |
− | ''-- sets the the new rotation''<br>
| + | |
− | end<br><br>
| + | |
− | obj.OnStart(onStartMethod);}}
| + | |
− | | + | |
− | ==Constructors==
| + | |
− | {{ScriptFunction|SQuaternion|__new|(float x, float y, float z, float w)|Initialises quaternion from four floats|5=
| + | |
− | local newQuat = '''Quaternion.New'''(0.0, 0.707, 0.0, 0.707);<br>
| + | |
− | ''-- creates a new quaternion with value [0.0, 0.707, 0.0, 0.707]''<br>
| + | |
− | ''-- which is [0.0, 90.0, 0.0] Euler angles''}}
| + | |
− | | + | |
− | {{ScriptFunction|SQuaternion|__new|(float x, float y, float z)|Creates a quaternion from 3 Euler floats (i.e. 3x 0-360' angles)}}
| + | |
− | {{ScriptFunction|SQuaternion|__new|(SVector angle, float axis)|Creates a quaternion from a Angle / Axis pair}}
| + | |
− | {{ScriptFunction|SQuaternion|__new|(SVector forward)|Creates a quaternion a forward vector; presuming up is (0,1,0)}}
| + | |
− | {{ScriptFunction|SQuaternion|__new|(SVector forward, SVector up)|Creates a quaternion a forward and up vector pair}}
| + | |
− | | + | |
− | ==Members==
| + | |
− | Note: Add/Scale/Divide are also implemented as operators (e.g. A + B, A += B)
| + | |
− | | + | |
− | {{ScriptFunction|SVector|EulerAngles|{ get; }|Returns the Euler rotation for this Quaternion|5=
| + | |
− | local newQuat = Quaternion.New(0.0, 0.707, 0.0, 0.707);
| + | |
− | local euler = newQuat.'''EulerAngles''';<br>
| + | |
− | Space.Log(euler);<br>
| + | |
− | ''-- prints [0, 90, 0]''}}
| + | |
− | | + | |
− | {{ScriptFunction|SVector|OVERLOAD|*(SQuaternion, SVector)|Rotates a vector by a quaternion|5=
| + | |
− | local newQuat = Quaternion.New(0.0, 1.0, 0.0, 0.0);
| + | |
− | local newVector = Vector.Forward;<br>
| + | |
− | rotatedVector = newQuat '''*''' newVector;<br><br>
| + | |
− | | + | |
− | Space.Log(rotatedVector);<br>
| + | |
− | ''-- prints [0, 0, -1]''}}
| + | |
− | | + | |
− | {{ScriptFunction|SQuaternion|OVERLOAD|*(SQuaternion, SQuaternion)|Rotates a quaternion by a quaternion|5=
| + | |
− | local newQuat = Quaternion.New(0.0, 0.707, 0.0, 0.707);
| + | |
− | local newVector = Vector.New(0.0, 0.0, 0.0);<br>
| + | |
− | rotatedVector = newQuat '''*''' newQuat;<br><br>
| + | |
− | | + | |
− | ''-- rotatedVector is a quaternion with value [0.0, 1.0, 0.0, 0.0]''<br>
| + | |
− | ''-- which is [0.0, 180.0, 0.0] Euler angles''}}
| + | |
− | | + | |
− | {{ScriptFunction|float|Angle|(SQuaternion other);|Returns the angle between two quaternions|5=
| + | |
− | local newQuat = Quaternion.New(0.0, 0.707, 0.0, 0.707);
| + | |
− | local otherQuat = Quaternion.New(0.0, 1.0, 0.0, 0.0);<br>
| + | |
− | angle = newQuat.'''Angle'''(otherQuat);<br><br>
| + | |
− | | + | |
− | Space.Log(angle);<br>
| + | |
− | ''-- prints 90.0173034667969''}}
| + | |
− | | + | |
− | {{ScriptFunction|SQuaternion|Lerp|(SQuaternion other, float t);|Linearly interpolates between this and other quaternion, by factor t and returns the result|5=
| + | |
− | ''-- Lua Translation of Unity C# Documentation
| + | |
− | -- Attach this script to a cube or any object.''<br><br>
| + | |
− | | + | |
− | local cube = Space.Host.ExecutingObject;<br>
| + | |
− | cube.SubscribeToEvents();<br><br>
| + | |
− | | + | |
− | local toQuat = Quaternion.New(0.0, 0.707, 0.0, 0.707);<br>
| + | |
− | local speed = 0.05;<br><br>
| + | |
− | | + | |
− | ''-- The cube will rotate 90 degrees from current rotation by speed amount.''
| + | |
− | local moveCube = function()<br>
| + | |
− | local fromQuat = cube.LocalRotation; <br>
| + | |
− | cube.LocalRotation = fromQuat.'''Lerp'''(toQuat, speed);<br>
| + | |
− | end<br><br>
| + | |
− | | + | |
− | cube.OnUpdate(moveCube);}}
| + | |
− | | + | |
− | {{ScriptFunction|SQuaternion|Slerp|(SQuaternion other, float t);|Spherically interpolates between this and other quaternion, by factor t and returns the result}}
| + | |
− | {{ScriptFunction|SQuaternion|RotateTowards|(SQuaternion other, float t);|Rotates this towards other, by no more than t degrees}}
| + | |
− | {{ScriptFunction|float|Dot|(SQuaternion other);|Returns the dot product of this and another quaternion}}
| + | |
− | {{ScriptFunction|SQuaternion|Inverse|{ get; }|Returns the inverse of this quaternion}}
| + | |
− | | + | |
− | ==Static Members==
| + | |
− | {{ScriptFunction|SQuaternion|Identity|{ get; }|Equivalent of new SQuaternion(0,0,0,1)}}
| + | |
− | | + | |
− | {{Scripting Navbox}}
| + | |