Inventory Engine  v4.0
Static Public Member Functions | List of all members
MoreMountains.Tools.MMMaths Class Reference

Math helpers More...

Static Public Member Functions

static void Spring (ref float currentValue, float targetValue, ref float velocity, float damping, float frequency, float deltaTime)
 Springs a float towards a target value More...
 
static void Spring (ref Vector2 currentValue, Vector2 targetValue, ref Vector2 velocity, float damping, float frequency, float deltaTime)
 Springs a Vector2 towards a target value More...
 
static void Spring (ref Vector3 currentValue, Vector3 targetValue, ref Vector3 velocity, float damping, float frequency, float deltaTime)
 Springs a Vector3 towards a target value More...
 
static void Spring (ref Vector4 currentValue, Vector4 targetValue, ref Vector4 velocity, float damping, float frequency, float deltaTime)
 Springs a Vector4 towards a target value More...
 
static float Lerp (float value, float target, float rate, float deltaTime)
 Lerps a float towards a target at the specified rate More...
 
static Vector2 Lerp (Vector2 value, Vector2 target, float rate, float deltaTime)
 Lerps a Vector2 towards a target at the specified rate More...
 
static Vector3 Lerp (Vector3 value, Vector3 target, float rate, float deltaTime)
 Lerps a Vector3 towards a target at the specified rate More...
 
static Vector4 Lerp (Vector4 value, Vector4 target, float rate, float deltaTime)
 Lerps a Vector4 towards a target at the specified rate More...
 
static Quaternion Lerp (Quaternion value, Quaternion target, float rate, float deltaTime)
 Lerps a Quaternion towards a target at the specified rate More...
 
static Color Lerp (Color value, Color target, float rate, float deltaTime)
 Lerps a Color towards a target at the specified rate More...
 
static Color32 Lerp (Color32 value, Color32 target, float rate, float deltaTime)
 Lerps a Color32 towards a target at the specified rate More...
 
static float Clamp (float value, float min, float max, bool clampMin, bool clampMax)
 Clamps a float between min and max, both bounds being optional and driven by clampMin and clampMax respectively More...
 
static float RoundToNearestHalf (float a)
 Rounds a float to the nearest half value : 1, 1.5, 2, 2.5 etc More...
 
static Quaternion LookAt2D (Vector2 direction)
 
static Vector2 Vector3ToVector2 (Vector3 target)
 Takes a Vector3 and turns it into a Vector2 More...
 
static Vector3 Vector2ToVector3 (Vector2 target)
 Takes a Vector2 and turns it into a Vector3 with a null z value More...
 
static Vector3 Vector2ToVector3 (Vector2 target, float newZValue)
 Takes a Vector2 and turns it into a Vector3 with the specified z value More...
 
static Vector3 RoundVector3 (Vector3 vector)
 Rounds all components of a Vector3. More...
 
static Vector2 RandomVector2 (Vector2 minimum, Vector2 maximum)
 Returns a random Vector2 from 2 defined Vector2. More...
 
static Vector3 RandomVector3 (Vector3 minimum, Vector3 maximum)
 Returns a random Vector3 from 2 defined Vector3. More...
 
static Vector2 RandomPointOnCircle (float circleRadius)
 Returns a random point on the circle of the specified radius More...
 
static Vector3 RandomPointOnSphere (float sphereRadius)
 Returns a random point on the sphere of the specified radius More...
 
static Vector3 RotatePointAroundPivot (Vector3 point, Vector3 pivot, float angle)
 Rotates a point around the given pivot. More...
 
static Vector3 RotatePointAroundPivot (Vector3 point, Vector3 pivot, Vector3 angle)
 Rotates a point around the given pivot. More...
 
static Vector3 RotatePointAroundPivot (Vector3 point, Vector3 pivot, Quaternion quaternion)
 Rotates a point around the given pivot. More...
 
static Vector2 RotateVector2 (Vector2 vector, float angle)
 Rotates a vector2 by the angle (in degrees) specified and returns it More...
 
static float AngleBetween (Vector2 vectorA, Vector2 vectorB)
 Computes and returns the angle between two vectors, on a 360° scale More...
 
static float AngleDirection (Vector3 vectorA, Vector3 vectorB, Vector3 up)
 Computes and returns the direction between two vector3, used to check if a vector is pointing left or right of another one More...
 
static float DistanceBetweenPointAndLine (Vector3 point, Vector3 lineStart, Vector3 lineEnd)
 Returns the distance between a point and a line. More...
 
static Vector3 ProjectPointOnLine (Vector3 point, Vector3 lineStart, Vector3 lineEnd)
 Projects a point on a line (perpendicularly) and returns the projected point. More...
 
static int Sum (params int[] thingsToAdd)
 Returns the sum of all the int passed in parameters More...
 
static int RollADice (int numberOfSides)
 Returns the result of rolling a dice of the specified number of sides More...
 
static bool Chance (int percent)
 Returns a random success based on X% of chance. More...
 
static float Approach (float from, float to, float amount)
 Moves from "from" to "to" by the specified amount and returns the corresponding value More...
 
static float Remap (float x, float A, float B, float C, float D)
 Remaps a value x in interval [A,B], to the proportional value in interval [C,D] More...
 
static float ClampAngle (float angle, float minimumAngle, float maximumAngle)
 Clamps the angle in parameters between a minimum and maximum angle (all angles expressed in degrees) More...
 
static float RoundToDecimal (float value, int numberOfDecimals)
 
static float RoundToClosest (float value, float[] possibleValues, bool pickSmallestDistance=false)
 Rounds the value passed in parameters to the closest value in the parameter array More...
 
static Vector3 DirectionFromAngle (float angle, float additionalAngle)
 Returns a vector3 based on the angle in parameters More...
 
static Vector3 DirectionFromAngle2D (float angle, float additionalAngle)
 Returns a vector3 based on the angle in parameters More...
 

Detailed Description

Math helpers

Member Function Documentation

◆ AngleBetween()

static float MoreMountains.Tools.MMMaths.AngleBetween ( Vector2  vectorA,
Vector2  vectorB 
)
static

Computes and returns the angle between two vectors, on a 360° scale

Returns
The System.Single.
Parameters
vectorAVector a.
vectorBVector b.

◆ AngleDirection()

static float MoreMountains.Tools.MMMaths.AngleDirection ( Vector3  vectorA,
Vector3  vectorB,
Vector3  up 
)
static

Computes and returns the direction between two vector3, used to check if a vector is pointing left or right of another one

Returns
The System.Single.
Parameters
vectorAVector a.
vectorBVector b.

◆ Approach()

static float MoreMountains.Tools.MMMaths.Approach ( float  from,
float  to,
float  amount 
)
static

Moves from "from" to "to" by the specified amount and returns the corresponding value

Parameters
fromFrom.
toTo.
amountAmount.

◆ Chance()

static bool MoreMountains.Tools.MMMaths.Chance ( int  percent)
static

Returns a random success based on X% of chance.

Example : I have 20% of chance to do X, Chance(20) > true, yay!

Parameters
percentPercent of chance.

◆ Clamp()

static float MoreMountains.Tools.MMMaths.Clamp ( float  value,
float  min,
float  max,
bool  clampMin,
bool  clampMax 
)
static

Clamps a float between min and max, both bounds being optional and driven by clampMin and clampMax respectively

Parameters
value
min
max
clampMin
clampMax
Returns

◆ ClampAngle()

static float MoreMountains.Tools.MMMaths.ClampAngle ( float  angle,
float  minimumAngle,
float  maximumAngle 
)
static

Clamps the angle in parameters between a minimum and maximum angle (all angles expressed in degrees)

Parameters
angle
minimumAngle
maximumAngle
Returns

◆ DirectionFromAngle()

static Vector3 MoreMountains.Tools.MMMaths.DirectionFromAngle ( float  angle,
float  additionalAngle 
)
static

Returns a vector3 based on the angle in parameters

Parameters
angle
Returns

◆ DirectionFromAngle2D()

static Vector3 MoreMountains.Tools.MMMaths.DirectionFromAngle2D ( float  angle,
float  additionalAngle 
)
static

Returns a vector3 based on the angle in parameters

Parameters
angle
Returns

◆ DistanceBetweenPointAndLine()

static float MoreMountains.Tools.MMMaths.DistanceBetweenPointAndLine ( Vector3  point,
Vector3  lineStart,
Vector3  lineEnd 
)
static

Returns the distance between a point and a line.

Returns
The between point and line.
Parameters
pointPoint.
lineStartLine start.
lineEndLine end.

◆ Lerp() [1/7]

static Color MoreMountains.Tools.MMMaths.Lerp ( Color  value,
Color  target,
float  rate,
float  deltaTime 
)
static

Lerps a Color towards a target at the specified rate

Parameters
value
target
rate
Returns

◆ Lerp() [2/7]

static Color32 MoreMountains.Tools.MMMaths.Lerp ( Color32  value,
Color32  target,
float  rate,
float  deltaTime 
)
static

Lerps a Color32 towards a target at the specified rate

Parameters
value
target
rate
Returns

◆ Lerp() [3/7]

static float MoreMountains.Tools.MMMaths.Lerp ( float  value,
float  target,
float  rate,
float  deltaTime 
)
static

Lerps a float towards a target at the specified rate

Parameters
value
target
rate
Returns

◆ Lerp() [4/7]

static Quaternion MoreMountains.Tools.MMMaths.Lerp ( Quaternion  value,
Quaternion  target,
float  rate,
float  deltaTime 
)
static

Lerps a Quaternion towards a target at the specified rate

Parameters
value
target
rate
Returns

◆ Lerp() [5/7]

static Vector2 MoreMountains.Tools.MMMaths.Lerp ( Vector2  value,
Vector2  target,
float  rate,
float  deltaTime 
)
static

Lerps a Vector2 towards a target at the specified rate

Parameters
value
target
rate
Returns

◆ Lerp() [6/7]

static Vector3 MoreMountains.Tools.MMMaths.Lerp ( Vector3  value,
Vector3  target,
float  rate,
float  deltaTime 
)
static

Lerps a Vector3 towards a target at the specified rate

Parameters
value
target
rate
Returns

◆ Lerp() [7/7]

static Vector4 MoreMountains.Tools.MMMaths.Lerp ( Vector4  value,
Vector4  target,
float  rate,
float  deltaTime 
)
static

Lerps a Vector4 towards a target at the specified rate

Parameters
value
target
rate
Returns

◆ LookAt2D()

static Quaternion MoreMountains.Tools.MMMaths.LookAt2D ( Vector2  direction)
static

Parameters
direction
Returns

◆ ProjectPointOnLine()

static Vector3 MoreMountains.Tools.MMMaths.ProjectPointOnLine ( Vector3  point,
Vector3  lineStart,
Vector3  lineEnd 
)
static

Projects a point on a line (perpendicularly) and returns the projected point.

Returns
The point on line.
Parameters
pointPoint.
lineStartLine start.
lineEndLine end.

◆ RandomPointOnCircle()

static Vector2 MoreMountains.Tools.MMMaths.RandomPointOnCircle ( float  circleRadius)
static

Returns a random point on the circle of the specified radius

Parameters
circleRadius
Returns

◆ RandomPointOnSphere()

static Vector3 MoreMountains.Tools.MMMaths.RandomPointOnSphere ( float  sphereRadius)
static

Returns a random point on the sphere of the specified radius

Parameters
sphereRadius
Returns

◆ RandomVector2()

static Vector2 MoreMountains.Tools.MMMaths.RandomVector2 ( Vector2  minimum,
Vector2  maximum 
)
static

Returns a random Vector2 from 2 defined Vector2.

Returns
The random Vector2.
Parameters
minMinimum.
maxMaximum.

◆ RandomVector3()

static Vector3 MoreMountains.Tools.MMMaths.RandomVector3 ( Vector3  minimum,
Vector3  maximum 
)
static

Returns a random Vector3 from 2 defined Vector3.

Returns
The random Vector3.
Parameters
minMinimum.
maxMaximum.

◆ Remap()

static float MoreMountains.Tools.MMMaths.Remap ( float  x,
float  A,
float  B,
float  C,
float  D 
)
static

Remaps a value x in interval [A,B], to the proportional value in interval [C,D]

Parameters
xThe value to remap.
Athe minimum bound of interval [A,B] that contains the x value
Bthe maximum bound of interval [A,B] that contains the x value
Cthe minimum bound of target interval [C,D]
Dthe maximum bound of target interval [C,D]

◆ RollADice()

static int MoreMountains.Tools.MMMaths.RollADice ( int  numberOfSides)
static

Returns the result of rolling a dice of the specified number of sides

Returns
The result of the dice roll.
Parameters
numberOfSidesNumber of sides of the dice.

◆ RotatePointAroundPivot() [1/3]

static Vector3 MoreMountains.Tools.MMMaths.RotatePointAroundPivot ( Vector3  point,
Vector3  pivot,
float  angle 
)
static

Rotates a point around the given pivot.

Returns
The new point position.
Parameters
pointThe point to rotate.
pivotThe pivot's position.
angleThe angle we want to rotate our point.

◆ RotatePointAroundPivot() [2/3]

static Vector3 MoreMountains.Tools.MMMaths.RotatePointAroundPivot ( Vector3  point,
Vector3  pivot,
Quaternion  quaternion 
)
static

Rotates a point around the given pivot.

Returns
The new point position.
Parameters
pointThe point to rotate.
pivotThe pivot's position.
anglesThe angle as a Vector3.

◆ RotatePointAroundPivot() [3/3]

static Vector3 MoreMountains.Tools.MMMaths.RotatePointAroundPivot ( Vector3  point,
Vector3  pivot,
Vector3  angle 
)
static

Rotates a point around the given pivot.

Returns
The new point position.
Parameters
pointThe point to rotate.
pivotThe pivot's position.
anglesThe angle as a Vector3.

◆ RotateVector2()

static Vector2 MoreMountains.Tools.MMMaths.RotateVector2 ( Vector2  vector,
float  angle 
)
static

Rotates a vector2 by the angle (in degrees) specified and returns it

Returns
The rotated Vector2.
Parameters
vectorThe vector to rotate.
angleDegrees.

◆ RoundToClosest()

static float MoreMountains.Tools.MMMaths.RoundToClosest ( float  value,
float[]  possibleValues,
bool  pickSmallestDistance = false 
)
static

Rounds the value passed in parameters to the closest value in the parameter array

Parameters
value
possibleValues
Returns

◆ RoundToDecimal()

static float MoreMountains.Tools.MMMaths.RoundToDecimal ( float  value,
int  numberOfDecimals 
)
static

◆ RoundToNearestHalf()

static float MoreMountains.Tools.MMMaths.RoundToNearestHalf ( float  a)
static

Rounds a float to the nearest half value : 1, 1.5, 2, 2.5 etc

Parameters
a
Returns

◆ RoundVector3()

static Vector3 MoreMountains.Tools.MMMaths.RoundVector3 ( Vector3  vector)
static

Rounds all components of a Vector3.

Returns
The vector3.
Parameters
vectorVector.

◆ Spring() [1/4]

static void MoreMountains.Tools.MMMaths.Spring ( ref float  currentValue,
float  targetValue,
ref float  velocity,
float  damping,
float  frequency,
float  deltaTime 
)
static

Springs a float towards a target value

Parameters
currentValuethe current value to spring, passed as a ref
targetValuethe target value we're aiming for
velocitya velocity value, passed as ref, used to compute the current speed of the springed value
dampingthe damping, between 0.01f and 1f, the higher the daming, the less springy it'll be
frequencythe frequency, in Hz, so the amount of periods the spring should go over in 1 second
speedthe speed (between 0 and 1) at which the spring should operate
deltaTimethe delta time (usually Time.deltaTime or Time.unscaledDeltaTime)

◆ Spring() [2/4]

static void MoreMountains.Tools.MMMaths.Spring ( ref Vector2  currentValue,
Vector2  targetValue,
ref Vector2  velocity,
float  damping,
float  frequency,
float  deltaTime 
)
static

Springs a Vector2 towards a target value

Parameters
currentValuethe current value to spring, passed as a ref
targetValuethe target value we're aiming for
velocitya velocity value, passed as ref, used to compute the current speed of the springed value
dampingthe damping, between 0.01f and 1f, the higher the daming, the less springy it'll be
frequencythe frequency, in Hz, so the amount of periods the spring should go over in 1 second
speedthe speed (between 0 and 1) at which the spring should operate
deltaTimethe delta time (usually Time.deltaTime or Time.unscaledDeltaTime)

◆ Spring() [3/4]

static void MoreMountains.Tools.MMMaths.Spring ( ref Vector3  currentValue,
Vector3  targetValue,
ref Vector3  velocity,
float  damping,
float  frequency,
float  deltaTime 
)
static

Springs a Vector3 towards a target value

Parameters
currentValuethe current value to spring, passed as a ref
targetValuethe target value we're aiming for
velocitya velocity value, passed as ref, used to compute the current speed of the springed value
dampingthe damping, between 0.01f and 1f, the higher the daming, the less springy it'll be
frequencythe frequency, in Hz, so the amount of periods the spring should go over in 1 second
speedthe speed (between 0 and 1) at which the spring should operate
deltaTimethe delta time (usually Time.deltaTime or Time.unscaledDeltaTime)

◆ Spring() [4/4]

static void MoreMountains.Tools.MMMaths.Spring ( ref Vector4  currentValue,
Vector4  targetValue,
ref Vector4  velocity,
float  damping,
float  frequency,
float  deltaTime 
)
static

Springs a Vector4 towards a target value

Parameters
currentValuethe current value to spring, passed as a ref
targetValuethe target value we're aiming for
velocitya velocity value, passed as ref, used to compute the current speed of the springed value
dampingthe damping, between 0.01f and 1f, the higher the daming, the less springy it'll be
frequencythe frequency, in Hz, so the amount of periods the spring should go over in 1 second
speedthe speed (between 0 and 1) at which the spring should operate
deltaTimethe delta time (usually Time.deltaTime or Time.unscaledDeltaTime)

◆ Sum()

static int MoreMountains.Tools.MMMaths.Sum ( params int[]  thingsToAdd)
static

Returns the sum of all the int passed in parameters

Parameters
thingsToAddThings to add.

◆ Vector2ToVector3() [1/2]

static Vector3 MoreMountains.Tools.MMMaths.Vector2ToVector3 ( Vector2  target)
static

Takes a Vector2 and turns it into a Vector3 with a null z value

Returns
The vector3.
Parameters
targetThe Vector2 to turn into a Vector3.

◆ Vector2ToVector3() [2/2]

static Vector3 MoreMountains.Tools.MMMaths.Vector2ToVector3 ( Vector2  target,
float  newZValue 
)
static

Takes a Vector2 and turns it into a Vector3 with the specified z value

Returns
The vector3.
Parameters
targetThe Vector2 to turn into a Vector3.
newZValueNew Z value.

◆ Vector3ToVector2()

static Vector2 MoreMountains.Tools.MMMaths.Vector3ToVector2 ( Vector3  target)
static

Takes a Vector3 and turns it into a Vector2

Returns
The vector2.
Parameters
targetThe Vector3 to turn into a Vector2.

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