|
|
(77 intermediate revisions by one other user not shown) |
Line 1: |
Line 1: |
− | The SMath class contains common math functions, see also [[SVector]] and [[SQuaternion]] for Vector and Quaternion related math functions.
| + | https://docs.sine.space/v/scripting/client-scripting/static-classes/smath |
− | | + | |
− | ==Members==
| + | |
− | {{ScriptFunction|float|Random|();|Returns a random float between 0 and 1 (inclusive)|5 = local randomNumber = Space.Math.Random();<br>Space.Log(randomNumber);<br>-- prints 0.689094245433807}}
| + | |
− | {{ScriptFunction|float|RandomRange|(float min, float max);|Returns a random float between min and max (inclusive)|5=local min = 100.0;<br>local max = 500.0;<br>local randomNumber = Space.Math.RandomRange(min, max );
| + | |
− | <br>Space.Log(randomNumber);<br>-- prints 0206.659149169922}}
| + | |
− | {{ScriptFunction|int|RandomInteger|(int min, int max);|Returns a random float between min (inclusive) and max (exclusive)|5=local min = 50;<br>local max = 75;<br>local randomInteger = Space.Math.RandomInteger(min, max);<br>Space.Log(randomInteger);<br>-- prints 52}}
| + | |
− | {{ScriptFunction|float|Abs|(float val);|Returns the absolute value of 'val'|5=local value = -4.2<br>local absoluteNum = Space.Math.Abs(value);<br>Space.Log(absoluteNum);<br>-- prints 4 [BUG] should be 4.2}}
| + | |
− | {{ScriptFunction|int|Abs|(int val);|Returns the absolute value of 'val'|5=local value = -4<br>local absoluteNum = Space.Math.Abs(value);<br>Space.Log(absoluteNum);<br>-- prints 4}}
| + | |
− | {{ScriptFunction|float|Acos|(float val);|Returns the arc cosine value of 'val'}}
| + | |
− | {{ScriptFunction|bool|Approximately|(float a, float b);|True if the difference between a and b is less than epsilon}}
| + | |
− | {{ScriptFunction|bool|Asin|(float val);|Returns the arc sine value of 'val'}}
| + | |
− | {{ScriptFunction|bool|Atan|(float val);|Returns the arc tangent value of 'val'}}
| + | |
− | {{ScriptFunction|bool|Atan2|(float y, float x);|Returns the arc tangent of y/x}}
| + | |
− | {{ScriptFunction|int|Ceil|(float val);|Returns the ceil value of 'val' as an integer}}
| + | |
− | {{ScriptFunction|float|Clamp|(float val, float min, float max);|Clamps val between min and max, and returns the result}}
| + | |
− | {{ScriptFunction|float|Clamp01|(float val);|Clamps val between 0 and 1, and returns the result}}
| + | |
− | {{ScriptFunction|int|ClosestPowerOfTwo|(int val);|Returns the closest power of two to val}}
| + | |
− | {{ScriptFunction|float|Cos|(float val);|Returns the cosine of val}}
| + | |
− | {{ScriptFunction|float|DeltaAngle|(float current, float target);|Returns the difference in degrees between two values (e.g. 350' and 17' returns 27')}}
| + | |
− | {{ScriptFunction|float|Exp|(float val);|Returns Exp of val}}
| + | |
− | {{ScriptFunction|int|Floor|(float val);|Returns floor of val, converted to an int}}
| + | |
− | {{ScriptFunction|float|GammaToLinearSpace|(float val);|Converts a colour value from Gamma to Linear Space (Pow 2.2)}}
| + | |
− | {{ScriptFunction|float|InverseLerp|(float a, float b, float val);|Returns the percentage between a and b that 'val' is on a line (opposite of Lerp)}}
| + | |
− | {{ScriptFunction|bool|IsPowerOfTwo|(int val);|Returns true if val is a power of two}}
| + | |
− | {{ScriptFunction|float|Lerp|(float a, float b, float val);|Interpolates between 'a' and 'b' based on 'val', assuming 'val' is between 0 and 1}}
| + | |
− | {{ScriptFunction|float|LerpAngle|(float a, float b, float val);|Interpolates between angles 'a' and 'b' based on 'val', assuming 'val' is between 0 and 1}}
| + | |
− | {{ScriptFunction|float|LerpUnclamped|(float a, float b, float val);|Interpolates between 'a' and 'b' based on 'val', assuming 'val' is between 0 and 1, but unbounded (allowing higher/lower values)}}
| + | |
− | {{ScriptFunction|float|GammaToLinearSpace|(float val);|Converts a colour value from Linear to Gamma Space (Pow 1/2.2)}}
| + | |
− | {{ScriptFunction|float|Log|(float val);|Returns the natural logarithm for 'val'}}
| + | |
− | {{ScriptFunction|float|Log|(float val, float p);|Returns the logarithm of 'p' for 'val'}}
| + | |
− | {{ScriptFunction|float|Log10|(float val);|Returns the Log10 value for 'val'}}
| + | |
− | {{ScriptFunction|float|Max|(float a, float b);|Returns higher of 'a' or 'b'}}
| + | |
− | {{ScriptFunction|float|Min|(float a, float b);|Returns lower of 'a' or 'b'}}
| + | |
− | {{ScriptFunction|float|MoveTowards|(float value, float target, float delta);|Move value to target, but by no more than delta}}
| + | |
− | {{ScriptFunction|float|MoveTowardsAngle|(float value, float target, float delta);|Move angle value to target, but by no more than delta}}
| + | |
− | {{ScriptFunction|int|NextPowerOfTwo|(int val);|Return the next power of two larger or equal to val}}
| + | |
− | {{ScriptFunction|float|PerlinNoise|(float x, float y);|Return 2D Perlin noise for coordinates x and y}}
| + | |
− | {{ScriptFunction|float|PingPong|(float val, float length);|Return a value between 0 and length that oscillates upwards and back based on the position of 'val'}}
| + | |
− | {{ScriptFunction|float|Pow|(float x, float y);|Return x raised to y power}}
| + | |
− | {{ScriptFunction|float|Repeat|(float val, float length);|Return a value between 0 and length that returns to 0 after exceeding length based on 'val'}}
| + | |
− | {{ScriptFunction|int|Round|(float val);|Returns the nearest integer value to val}}
| + | |
− | {{ScriptFunction|float|Sign|(float val);|Returns either 1 or -1 based on the sign of 'val'}}
| + | |
− | {{ScriptFunction|float|Sin|(float val);|Returns the sine of val}}
| + | |
− | {{ScriptFunction|float|SmoothStep|(float from, float to, float val);|Similar to Lerp but moves slowly closer to the edges ('Spherical Lerp')}}
| + | |
− | {{ScriptFunction|float|Sqrt|(float val);|Returns the square root of val}}
| + | |
− | {{ScriptFunction|float|Tan|(float val);|Returns the tangent value of 'val'}}
| + | |
− | | + | |
− | {{Scripting Navbox}}
| + | |