wiki.sine.space | sinespace

Difference between revisions of "Scripting/SVector"

From wiki.sine.space
Jump to: navigation, search
(Replaced content with "This page has moved to: https://docs.sine.space/v/scripting/client-scripting/types/svector")
 
(23 intermediate revisions by 2 users not shown)
Line 1: Line 1:
The SVector struct contains a simple 3D vector of X, Y and Z floats
+
This page has moved to: https://docs.sine.space/v/scripting/client-scripting/types/svector
 
+
==Fields==
+
{{ScriptFunction|float|X|{ get; set; }|X axis (red axis)|5=
+
local obj = Space.Host.ExecutingObject;<br>
+
local originalPos = obj.LocalPosition;<br>
+
obj.SubscribeToEvents();<br><br>
+
local onStartMethod = function()<br>
+
&nbsp;&nbsp;Space.Log(originalPos.'''x''');<br>
+
&nbsp;&nbsp;''-- prints the X axis position of this object as a float''<br><br>
+
&nbsp;&nbsp;originalPos.'''x''' = 100.0;<br>
+
&nbsp;&nbsp;''-- sets the X axis position of this object to 100.0''<br>
+
end<br><br>
+
obj.OnStart(onStartMethod);}}
+
 
+
{{ScriptFunction|float|Y|{ get; set; }|Y axis (green axis)|5=
+
local obj = Space.Host.ExecutingObject;<br>
+
local originalPos = obj.LocalPosition;<br>
+
obj.SubscribeToEvents();<br><br>
+
local onStartMethod = function()<br>
+
&nbsp;&nbsp;Space.Log(originalPos.'''y''');<br>
+
&nbsp;&nbsp;''-- prints the Y axis position of this object as a float''<br><br>
+
&nbsp;&nbsp;originalPos.'''y''' = 100.0;<br>
+
&nbsp;&nbsp;''-- sets the Y axis position of this object to 100.0''<br>
+
end<br><br>
+
obj.OnStart(onStartMethod);}}
+
 
+
{{ScriptFunction|float|Z|{ get; set; }|Z axis (blue axis)|5=
+
local obj = Space.Host.ExecutingObject;<br>
+
local originalPos = obj.LocalPosition;<br>
+
obj.SubscribeToEvents();<br><br>
+
local onStartMethod = function()<br>
+
&nbsp;&nbsp;Space.Log(originalPos.'''z''');<br>
+
&nbsp;&nbsp;''-- prints the Z axis position of this object as a float''<br><br>
+
&nbsp;&nbsp;originalPos.'''z''' = 100.0;<br>
+
&nbsp;&nbsp;''-- sets the Z axis position of this object to 100.0''<br>
+
end<br><br>
+
obj.OnStart(onStartMethod);}}
+
 
+
==Constructors==
+
{{ScriptFunction|SVector|__new|(float x, float y, float z)|Initialises vector from three floats|5= '''Vector.New'''(0, 1, 0);<br>''-- creates a new vector with value [0, 1, 0]''}}
+
 
+
==Members==
+
Note: Add/Scale/Divide are also implemented as operators (e.g. A + B, A += B)
+
 
+
{{ScriptFunction|SVector|Add|(SVector other);|Adds another vector to this, and returns the result|5=
+
local vector = Vector.New(0, 10, 0);<br>
+
local vectorOther = Vector.New(40, 50, 6);<br>
+
Space.Log(vector.'''Add'''(vectorOther));<br>
+
''-- prints [40, 60, 6]''<br><br>
+
Space.Log(vector '''+''' vectorOther);<br>
+
''-- prints [40, 60, 6]''}}
+
 
+
{{ScriptFunction|SVector|Add|(float other);|Adds a float to each axis of this, and returns the result|5=
+
local vectorB = Vector.New(0, 10, 0);<br>
+
Space.Log(vectorB.'''Add'''(5));<br>
+
''-- prints [5, 15, 5]''}}
+
 
+
{{ScriptFunction|SVector|Scale|(SVector other);|Multiplies another vector to this, and returns the result|5=
+
local vector = Vector.New(0, 10, 0);<br>
+
local vectorOther = Vector.New(2, 5, 4);<br>
+
Space.Log(vector.'''Scale'''(vectorOther));<br>
+
''-- prints [0, 50, 0]''<br><br>
+
Space.Log(vector '''*''' vectorOther);<br>
+
''-- prints [0, 50, 0]''}}
+
 
+
{{ScriptFunction|SVector|Scale|(float other);|Multiplies a float to each axis of this, and returns the result|5=
+
local vector = Vector.New(0, 10, 0);<br>
+
Space.Log(vector.'''Scale'''(5));<br>
+
''-- prints [0, 50, 0]''<br><br>
+
Space.Log(vector '''*''' 5);<br>
+
''-- prints [0, 50, 0]''}}
+
 
+
{{ScriptFunction|SVector|Divide|(SVector other);|Divides another vector to this, and returns the result|5=
+
local vector = Vector.New(10, 10, 10);<br>
+
local vectorOther = Vector.New(2, 2, 2);<br>
+
Space.Log(vector.'''Divide'''(vectorOther));<br>
+
''-- prints [5, 5, 5]''<br><br>
+
Space.Log(vector '''/''' vectorOther);<br>
+
''-- prints [5, 5, 5]''}}
+
 
+
{{ScriptFunction|SVector|Divide|(float other);|Divides a float to each axis of this, and returns the result|5=
+
local vector = Vector.New(10, 10, 10);<br>
+
Space.Log(vector.'''Divide'''(2));<br>
+
''-- prints [5, 5, 5]''<br><br>
+
Space.Log(vector '''/''' 2);<br>
+
''-- prints [5, 5, 5]''}}
+
 
+
{{ScriptFunction|float|Magnitude|{ get ; }|Returns the magnitude of this vector|5=local vector = Vector.New(1.0, 5.0, 0.0);<br>Space.Log('''vector.Magnitude''');<br>''-- prints 5.0990195274353''}}
+
 
+
{{ScriptFunction|SVector|Normalised|{ get ; }|Returns the normalised version of this vector|5=local vector = Vector.New(0.0, 10.0, 0.0);<br>Space.Log('''vector.Normalised''');<br>''-- prints [0, 1, 0]''}}
+
 
+
{{ScriptFunction|float|Distance|(SVector other);|Returns the distance between this vector and other in meters|5=
+
local vector = Vector.New(3, 3, 3.5);<br>local vectorOther = Vector.New(2, 2, 2);<br>Space.Log('''vector.Distance'''(vectorOther));<br>''-- prints 2.06155276298523''}}
+
 
+
{{ScriptFunction|float|SquareDistance|(SVector other);|Returns the square of the distance between this vector and other in meters, considerably faster than distance()}}
+
{{ScriptFunction|bool|InRange|(SVector other, float range);|Returns if other is within range meters of this vector, inclusive}}
+
{{ScriptFunction|SVector|Cross|(SVector other);|Returns the cross product of this vector and other}}
+
{{ScriptFunction|SVector|Lerp|(SVector other, float t);|Linear interpolates between this and other based on factor t (0..1)}}
+
{{ScriptFunction|SVector|Slerp|(SVector other, float t);|Spherically linear interpolates between this and other based on factor t (0..1)}}
+
{{ScriptFunction|SVector|MoveTowards|(SVector other, float maxDistance);|Moves this vector closer to other by a maximum of maxDistance units}}
+
{{ScriptFunction|float|Dot|(SVector other);|Returns the dot product between this and other (note - normalise your vectors first!)}}
+
 
+
==Static Members==
+
{{ScriptFunction|SVector|Up|{ get; }|Equivalent of new SVector(0,1,0)}}
+
{{ScriptFunction|SVector|Down|{ get; }|Equivalent of new SVector(0,-1,0)}}
+
{{ScriptFunction|SVector|Left|{ get; }|Equivalent of new SVector(-1,0,0)}}
+
{{ScriptFunction|SVector|Right|{ get; }|Equivalent of new SVector(1,0,0)}}
+
{{ScriptFunction|SVector|Forward|{ get; }|Equivalent of new SVector(0,0,1)}}
+
{{ScriptFunction|SVector|Back|{ get; }|Equivalent of new SVector(0,0,-1)}}
+
{{ScriptFunction|SVector|Zero|{ get; }|Equivalent of new SVector(0,0,0)}}
+
{{ScriptFunction|SVector|One|{ get; }|Equivalent of new SVector(1,1,1)}}
+
{{ScriptFunction|SVector|MinValue|{ get; }|Contains the largest possible negative vector}}
+
{{ScriptFunction|SVector|MaxValue|{ get; }|Contains the largest possible vector}}
+
 
+
{{Scripting Navbox}}
+

Latest revision as of 08:09, 19 September 2022

This page has moved to: https://docs.sine.space/v/scripting/client-scripting/types/svector