Skip to content

API reference

Class MathX

Namespace: MicroEngine
Assembly: MicroEngine.Kernel.dll
Guide: Graphics

Small numeric helpers that games repeatedly need for feel and motion.

C#
public static class MathX

Inheritance

object ← MathX

Methods

Approach(float, float, float)

Moves value toward target by at most step.

C#
public static float Approach(float value, float target, float step)

Parameters

value float

target float

step float

Returns

float

Approach(Vector2, Vector2, float)

Moves value toward target by at most step along the straight line.

C#
public static Vector2 Approach(Vector2 value, Vector2 target, float step)

Parameters

value Vector2

target Vector2

step float

Returns

Vector2

Damp(float, float, float, float)

Frame-rate independent exponential smoothing; sharpness is per second.

C#
public static float Damp(float current, float target, float sharpness, float dt)

Parameters

current float

target float

sharpness float

dt float

Returns

float

Damp(Vector2, Vector2, float, float)

Frame-rate independent exponential smoothing of a point; sharpness is per second.

C#
public static Vector2 Damp(Vector2 current, Vector2 target, float sharpness, float dt)

Parameters

current Vector2

target Vector2

sharpness float

dt float

Returns

Vector2

FloorDiv(float, int)

The index of the cell of width size that contains value, rounding toward negative infinity (so -1 is in cell -1).

C#
public static int FloorDiv(float value, int size)

Parameters

value float

size int

Returns

int

FromAngle(float, float)

A vector of length pointing at radians (0 = right, π/2 = down on screen).

C#
public static Vector2 FromAngle(float radians, float length = 1)

Parameters

radians float

length float

Returns

Vector2

Lerp(float, float, float)

Linear interpolation: a at t = 0, b at 1. t is not clamped.

C#
public static float Lerp(float a, float b, float t)

Parameters

a float

b float

t float

Returns

float

PingPong(float, float)

Returns 0..1..0 over a period, useful for pulses and bobbing.

C#
public static float PingPong(float time, float period)

Parameters

time float

period float

Returns

float

Wave(float, float, float)

A sine wave: sin(time × frequency × 2π) × amplitude, with frequency in cycles per second.

C#
public static float Wave(float time, float frequency, float amplitude = 1)

Parameters

time float

frequency float

amplitude float

Returns

float