Enfusion Script API
Loading...
Searching...
No Matches
Static Public Member Functions | Static Public Attributes | List of all members
Math Interface Reference

Static Public Member Functions

static proto float Round (float f)
 Returns value f rounded to the closest whole number.
 
static proto float Floor (float f)
 Returns value f rounded down to the closest whole number.
 
static proto float Ceil (float f)
 Returns value f rounded up to the closest whole number.
 
static proto float Min (float x, float y)
 Returns lower of two values x and y.
 
static proto float Max (float x, float y)
 Returns larger of two values x and y.
 
static proto float Sin (float angleRad)
 Returns sine of an angle specified in radians.
 
static proto float Cos (float angleRad)
 Returns cosine of an angle specified in radians.
 
static proto float Tan (float angleRad)
 Returns tangent of an angle specified in radians.
 
static proto float Asin (float s)
 Returns angle in radians from sine.
 
static proto float Acos (float c)
 Returns angle in radians from cosine.
 
static proto float Atan2 (float y, float x)
 Returns angle in radians from tangent.
 
static proto float Pow (float v, float power)
 Returns v raised to the power.
 
static proto float Mod (float v, float div)
 Returns remainder of division v/div.
 
static proto float AbsFloat (float f)
 Returns absolute value of f.
 
static proto int AbsInt (int i)
 Returns absolute value of i.
 
static proto float Sqrt (float val)
 Returns square root of val.
 
static proto float Log2 (float x)
 Returns the binary (base-2) logarithm of x.
 
static proto float Log10 (float x)
 Returns the common (base-10) logarithm of x.
 
static proto float Log (float x)
 Returns the natural (base-e) logarithm of x.
 
static proto float SmoothCD (float val, float target, inout float velocity, float smoothTime, float maxVelocity, float dt)
 Does the CD smoothing function - easy in | easy out / S shaped smoothing.
 
static proto float SmoothCDPI2PI (float val, float target, inout float velocity, float smoothTime, float maxVelocity, float dt)
 SmoothCD() version that wraps around on [-PI,PI] range.
 
static proto float SmoothSpring (float val, float target, inout float velocity, float spring, float damping, float dt)
 Does spring smoothing function.
 
static proto float PerlinNoise (float x, float y=0, float z=0)
 Returns value (between -1 and 1) of Perlin noise for given parameters x, y, z To get 1D or 2D noise simply leave the respective parameters to 0 (y and z or just z)
 
static proto float PerlinNoise01 (float x, float y=0, float z=0)
 PerlinNoise() but normalized to (0, 1).
 
static proto float SimplexNoise1D (float x)
 Returns value (between -1 and 1) of Simplex noise for given input x.
 
static proto int RandomInt (int min, int max)
 Returns a random int number between min [inclusive] and max [exclusive].
 
static proto int Randomize (int seed)
 Sets the seed for the random number generator.
 
static proto float RandomFloat (float min, float max)
 Returns a random float number between min [inclusive] and max [exclusive].
 
static proto float RandomGaussFloat (float sigma, float mean)
 Returns random number with Gauss distribution (http://en.wikipedia.org/wiki/File:Normal_Distribution_PDF.svg)
 
static proto int RandomIntInclusive (int min, int max)
 Returns a random int number between min [inclusive] and max [inclusive].
 
static proto float RandomFloatInclusive (float min, float max)
 Returns a random float number between min [inclusive] and max [inclusive].
 
static proto float RandomFloat01 ()
 Returns a random float number in range [0.0, 1.0] inclusive on both ends.
 
static proto float Repeat (float value, float range)
 Loop the value in given range (similar to modulo).
 
static proto float Map (float value, float fromLow, float fromHigh, float toLow, float toHigh)
 Re-maps a number from one range to another.
 
static proto float MapAngle (float value, float fFromRange=360, float fToLow=-180, float fToHigh=180)
 Re-maps angle from one range to another.
 
static proto bool IsInRange (float value, float min, float max)
 Returns true when value is greater than or equal to min and less than or equal to max.
 
static proto bool IsInRangeSharp (float value, float min, float max)
 Returns true when value is greater than min and less than max.
 
static proto float Clamp (float value, float min, float max)
 Clamps value to range specified by [min, max].
 
static proto int ClampInt (int value, int min, int max)
 Clamps value to range specified by [min, max].
 
static proto float Lerp (float a, float b, float t)
 Does linear interpolation between a and b using t.
 
static proto float InverseLerp (float a, float b, float value)
 Calculates the interpolation parameter that produces the value by interpolating from a to b.
 

Static Public Attributes

static const float PI = 3.14159265358979
 
static const float PI2 = 6.28318530717958
 
static const float PI_HALF = 1.570796326794
 
static const float RAD2DEG = 57.2957795130823208768
 
static const float DEG2RAD = 0.01745329251994329577
 
static const float E = 2.71828182845905
 

Member Function Documentation

◆ AbsFloat()

static proto float Math.AbsFloat ( float  f)
static

Returns absolute value of f.

Print( Math.AbsFloat(-12.5) );
>> 12.5
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
Definition: Math.c:13
static proto float AbsFloat(float f)
Returns absolute value of f.

◆ AbsInt()

static proto int Math.AbsInt ( int  i)
static

Returns absolute value of i.

Print( Math.AbsInt(-12) );
>> 12
static proto int AbsInt(int i)
Returns absolute value of i.

◆ Acos()

static proto float Math.Acos ( float  c)
static

Returns angle in radians from cosine.

Print( Math.Acos(0.707107) ); // (cosine 45)
>> 0.785398
static proto float Acos(float c)
Returns angle in radians from cosine.

◆ Asin()

static proto float Math.Asin ( float  s)
static

Returns angle in radians from sine.

Print( Math.Asin(0.707107) ); // (sine 45)
>> 0.785398
static proto float Asin(float s)
Returns angle in radians from sine.

◆ Atan2()

static proto float Math.Atan2 ( float  y,
float  x 
)
static

Returns angle in radians from tangent.

Tangent is specified as 2D coordinates [x,y] of a point on circle centered at coordinates [0,0].

Print ( Math.Atan2(1, 1) );
>> 0.785398
static proto float Atan2(float y, float x)
Returns angle in radians from tangent.
Parameters
yY coordinate on the circle.
xX coordinate on the circle.

◆ Ceil()

static proto float Math.Ceil ( float  f)
static

Returns value f rounded up to the closest whole number.

Print( Math.Ceil(5.3) );
Print( Math.Ceil(5.8) );
>> 6
>> 6
static proto float Ceil(float f)
Returns value f rounded up to the closest whole number.

◆ Clamp()

static proto float Math.Clamp ( float  value,
float  min,
float  max 
)
static

Clamps value to range specified by [min, max].

  • When value is less than min, returns min.
  • When value is greater than max, returns max.
  • In all other cases, returns value.
Print( Math.Clamp(-0.1, 0, 1) );
Print( Math.Clamp(2, 0, 1) );
Print( Math.Clamp(0.5, 0, 1) );
>> 0
>> 1
>> 0.5
static proto float Clamp(float value, float min, float max)
Clamps value to range specified by [min, max].

◆ ClampInt()

static proto int Math.ClampInt ( int  value,
int  min,
int  max 
)
static

Clamps value to range specified by [min, max].

  • When value is less than min, returns min.
  • When value is greater than max, returns max.
  • In all other cases, returns value.
Print( Math.ClampInt(-1, 0, 1) );
Print( Math.ClampInt(2, 0, 1) );
Print( Math.ClampInt(1, 0, 2) );
>> 0
>> 1
>> 1
static proto int ClampInt(int value, int min, int max)
Clamps value to range specified by [min, max].

◆ Cos()

static proto float Math.Cos ( float  angleRad)
static

Returns cosine of an angle specified in radians.

Print( Math.Cos(0.785398) ); // (45)
>> 0.707107
static proto float Cos(float angleRad)
Returns cosine of an angle specified in radians.

◆ Floor()

static proto float Math.Floor ( float  f)
static

Returns value f rounded down to the closest whole number.

Print( Math.Floor(5.3) );
Print( Math.Floor(5.8) );
>> 5
>> 5
static proto float Floor(float f)
Returns value f rounded down to the closest whole number.

◆ InverseLerp()

static proto float Math.InverseLerp ( float  a,
float  b,
float  value 
)
static

Calculates the interpolation parameter that produces the value by interpolating from a to b.

It's an inverse of Lerp().

Print( Math.InverseLerp(3, 7, 5) );
>> 0.5
static proto float InverseLerp(float a, float b, float value)
Calculates the interpolation parameter that produces the value by interpolating from a to b.

◆ IsInRange()

static proto bool Math.IsInRange ( float  value,
float  min,
float  max 
)
static

Returns true when value is greater than or equal to min and less than or equal to max.

Print( Math.IsInRange(-0.1, 0, 1) );
Print( Math.IsInRange(2, 0, 1) );
Print( Math.IsInRange(0.5, 0, 1) );
Print( Math.IsInRange(0, 0, 1) );
Print( Math.IsInRange(1, 0, 1) );
>> false
>> false
>> true
>> true
>> true
static proto bool IsInRange(float value, float min, float max)
Returns true when value is greater than or equal to min and less than or equal to max.

◆ IsInRangeSharp()

static proto bool Math.IsInRangeSharp ( float  value,
float  min,
float  max 
)
static

Returns true when value is greater than min and less than max.

Print( Math.IsInRange(-0.1, 0, 1) );
Print( Math.IsInRange(2, 0, 1) );
Print( Math.IsInRange(0.5, 0, 1) );
Print( Math.IsInRange(0, 0, 1) );
Print( Math.IsInRange(1, 0, 1) );
>> false
>> false
>> true
>> false
>> false

◆ Lerp()

static proto float Math.Lerp ( float  a,
float  b,
float  t 
)
static

Does linear interpolation between a and b using t.

Print( Math.Lerp(3, 7, 0.5) );
>> 5
static proto float Lerp(float a, float b, float t)
Does linear interpolation between a and b using t.
Parameters
tInterpolation parameter, must be in range 0..1 [inclusive]

◆ Log()

static proto float Math.Log ( float  x)
static

Returns the natural (base-e) logarithm of x.

Print( Math.Log2(1.0) );
>> 0.0
static proto float Log2(float x)
Returns the binary (base-2) logarithm of x.
Parameters
xValue whose logarithm is calculated.
Returns
Result depends on the value of x:
  • If x is positive, result is natural logarithm of x.
  • if x is negative or zero, an error occurs and result is undefined.

◆ Log10()

static proto float Math.Log10 ( float  x)
static

Returns the common (base-10) logarithm of x.

Print( Math.Log10(100.0) );
>> 2.0
static proto float Log10(float x)
Returns the common (base-10) logarithm of x.
Parameters
xValue whose logarithm is calculated.
Returns
Result depends on the value of x:
  • If x is positive, result is common logarithm of x.
  • If x is negative or zero, an error occurs and result is undefined.

◆ Log2()

static proto float Math.Log2 ( float  x)
static

Returns the binary (base-2) logarithm of x.

Print( Math.Log2(1.0) );
>> 0.0
Parameters
xValue whose logarithm is calculated.
Returns
Result depends on the value of x:
  • If x is positive, result is binary logarithm of x.
  • If x is negative or zero, an error occurs and result is undefined.

◆ Map()

static proto float Math.Map ( float  value,
float  fromLow,
float  fromHigh,
float  toLow,
float  toHigh 
)
static

Re-maps a number from one range to another.

Print( Math.Map(0, -5, 5, 100, 200) );
>> 150
static proto float Map(float value, float fromLow, float fromHigh, float toLow, float toHigh)
Re-maps a number from one range to another.

◆ MapAngle()

static proto float Math.MapAngle ( float  value,
float  fFromRange = 360,
float  fToLow = -180,
float  fToHigh = 180 
)
static

Re-maps angle from one range to another.

Print( Math.MapAngle(-45, 360, -Math.PI, Math.PI) );
>> -0.785398
static const float PI
Definition: Math.c:17
static proto float MapAngle(float value, float fFromRange=360, float fToLow=-180, float fToHigh=180)
Re-maps angle from one range to another.

◆ Max()

static proto float Math.Max ( float  x,
float  y 
)
static

Returns larger of two values x and y.

Print( Math.Max(5.3, 2.8) );
>> 5.3
static proto float Max(float x, float y)
Returns larger of two values x and y.

◆ Min()

static proto float Math.Min ( float  x,
float  y 
)
static

Returns lower of two values x and y.

Print( Math.Min(5.3, 2.8) );
>> 2.8
static proto float Min(float x, float y)
Returns lower of two values x and y.

◆ Mod()

static proto float Math.Mod ( float  v,
float  div 
)
static

Returns remainder of division v/div.

Print( Math.Mod(5.0, 2.0) );
>> 1.0
static proto float Mod(float v, float div)
Returns remainder of division v/div.

◆ PerlinNoise()

static proto float Math.PerlinNoise ( float  x,
float  y = 0,
float  z = 0 
)
static

Returns value (between -1 and 1) of Perlin noise for given parameters x, y, z To get 1D or 2D noise simply leave the respective parameters to 0 (y and z or just z)

◆ PerlinNoise01()

static proto float Math.PerlinNoise01 ( float  x,
float  y = 0,
float  z = 0 
)
static

PerlinNoise() but normalized to (0, 1).

◆ Pow()

static proto float Math.Pow ( float  v,
float  power 
)
static

Returns v raised to the power.

Print( Math.Pow(2, 4) ); // (2*2*2*2)=16
>> 16
static proto float Pow(float v, float power)
Returns v raised to the power.

◆ RandomFloat()

static proto float Math.RandomFloat ( float  min,
float  max 
)
static

Returns a random float number between min [inclusive] and max [exclusive].

>> 0.597561
>> 1.936456
static proto float RandomFloat(float min, float max)
Returns a random float number between min [inclusive] and max [exclusive].
Parameters
minRange start [inclusive]
maxRange end [exclusive]
Returns
Random number in range

◆ RandomFloat01()

static proto float Math.RandomFloat01 ( )
static

Returns a random float number in range [0.0, 1.0] inclusive on both ends.

Print( Math.RandomFloat01() ); // 0.0 .. 1.0
>> 0.3
>> 1.0
static proto float RandomFloat01()
Returns a random float number in range [0.0, 1.0] inclusive on both ends.
Returns
Random number in range 0.0 .. 1.0

◆ RandomFloatInclusive()

static proto float Math.RandomFloatInclusive ( float  min,
float  max 
)
static

Returns a random float number between min [inclusive] and max [inclusive].

Print( Math.RandomFloatInclusive(0, 1) ); // 0.0 .. 1.0
Print( Math.RandomFloatInclusive(1, 2) ); // 1.0 .. 2.0
>> 0.3
>> 2.0
static proto float RandomFloatInclusive(float min, float max)
Returns a random float number between min [inclusive] and max [inclusive].
Parameters
minRange start [inclusive]
maxRange end [inclusive]
Returns
Random number in range

◆ RandomGaussFloat()

static proto float Math.RandomGaussFloat ( float  sigma,
float  mean 
)
static

Returns random number with Gauss distribution (http://en.wikipedia.org/wiki/File:Normal_Distribution_PDF.svg)

◆ RandomInt()

static proto int Math.RandomInt ( int  min,
int  max 
)
static

Returns a random int number between min [inclusive] and max [exclusive].

Print( Math.RandomInt(0, 1) ); // only 0
Print( Math.RandomInt(0, 2) ); // 0 or 1
>> 0
>> 1
static proto int RandomInt(int min, int max)
Returns a random int number between min [inclusive] and max [exclusive].
Parameters
minRange starts [inclusive]
maxRange ends [exclusive]
Returns
Random number in range

◆ RandomIntInclusive()

static proto int Math.RandomIntInclusive ( int  min,
int  max 
)
static

Returns a random int number between min [inclusive] and max [inclusive].

Print( Math.RandomIntInclusive(0, 1) ); // 0 or 1
Print( Math.RandomIntInclusive(0, 2) ); // 0, 1, 2
>> 1
>> 2
static proto int RandomIntInclusive(int min, int max)
Returns a random int number between min [inclusive] and max [inclusive].
Parameters
minRange start [inclusive]
maxRange end [inclusive]
Returns
Random number in range

◆ Randomize()

static proto int Math.Randomize ( int  seed)
static

Sets the seed for the random number generator.

>> 5
static proto int Randomize(int seed)
Sets the seed for the random number generator.
Parameters
seedNew seed for the random number generator or -1 to use current time as seed.
Returns
Returns new seed.

◆ Repeat()

static proto float Math.Repeat ( float  value,
float  range 
)
static

Loop the value in given range (similar to modulo).

Print( Math.Repeat(370, 360) );
Print( Math.Repeat(-20, 360) );
>> 10
>> 340
static proto float Repeat(float value, float range)
Loop the value in given range (similar to modulo).

◆ Round()

static proto float Math.Round ( float  f)
static

Returns value f rounded to the closest whole number.

Print( Math.Round(5.3) );
Print( Math.Round(5.8) );
>> 5
>> 6
static proto float Round(float f)
Returns value f rounded to the closest whole number.

◆ SimplexNoise1D()

static proto float Math.SimplexNoise1D ( float  x)
static

Returns value (between -1 and 1) of Simplex noise for given input x.

◆ Sin()

static proto float Math.Sin ( float  angleRad)
static

Returns sine of an angle specified in radians.

Print( Math.Sin(0.785398) ); // (45)
>> 0.707107
static proto float Sin(float angleRad)
Returns sine of an angle specified in radians.

◆ SmoothCD()

static proto float Math.SmoothCD ( float  val,
float  target,
inout float  velocity,
float  smoothTime,
float  maxVelocity,
float  dt 
)
static

Does the CD smoothing function - easy in | easy out / S shaped smoothing.

val = EnfMath.SmoothCD(val, varTarget, valVelocity, 0.3, 1000, dt);
Parameters
valactual value
targetvalue we are reaching for -> Target
velocityAcceleration/deceleration rate, need to be zeroed when filter is about to be reset.
smoothTimeSmoothing parameter, 0.1 .. 0.4 are reasonable values, 0.1 is sharp, 0.4 is very smooth.
maxVelocityMaximum value change when multiplied by dt.
dtTime delta.
Returns
smoothed/filtered value

◆ SmoothCDPI2PI()

static proto float Math.SmoothCDPI2PI ( float  val,
float  target,
inout float  velocity,
float  smoothTime,
float  maxVelocity,
float  dt 
)
static

SmoothCD() version that wraps around on [-PI,PI] range.

val = EnfMath.SmoothCDPI2PI(val, varTarget, valVelocity, 0.3, 1000, dt);

◆ SmoothSpring()

static proto float Math.SmoothSpring ( float  val,
float  target,
inout float  velocity,
float  spring,
float  damping,
float  dt 
)
static

Does spring smoothing function.

Parameters
valactual value
targetvalue we are reaching for -> Target
velocitykind of memory and actual accel/decel rate, need to be zeroed when filter is about to be reset
springspring amount 0...1
dampingdamper amount 0...1
dtdelta time

◆ Sqrt()

static proto float Math.Sqrt ( float  val)
static

Returns square root of val.

Print( Math.Sqrt(25) );
>> 5
static proto float Sqrt(float val)
Returns square root of val.

◆ Tan()

static proto float Math.Tan ( float  angleRad)
static

Returns tangent of an angle specified in radians.

Print( Math.Tan(0.785398) ); // (45)
>> 1
static proto float Tan(float angleRad)
Returns tangent of an angle specified in radians.

Member Data Documentation

◆ DEG2RAD

const float Math.DEG2RAD = 0.01745329251994329577
static

◆ E

const float Math.E = 2.71828182845905
static

◆ PI

const float Math.PI = 3.14159265358979
static

◆ PI2

const float Math.PI2 = 6.28318530717958
static

◆ PI_HALF

const float Math.PI_HALF = 1.570796326794
static

◆ RAD2DEG

const float Math.RAD2DEG = 57.2957795130823208768
static

The documentation for this interface was generated from the following file: