Class MathUtils
Namespace: ValveResourceFormat.Utils
Assembly: ValveResourceFormat.dll
Common math utility functions for rendering and animation.
public static class MathUtilsInheritance
Methods
CubicBezier(Vector3, Vector3, Vector3, Vector3, float)
Evaluates a cubic Bezier curve at t in [0, 1].
public static Vector3 CubicBezier(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t)Parameters
p0 Vector3
p1 Vector3
p2 Vector3
p3 Vector3
t float
Returns
DecibelsToLinear(float)
Converts a decibel value to a linear amplitude multiplier (0 dB is 1.0, -6 dB is roughly half).
public static float DecibelsToLinear(float decibels)Parameters
decibels float
Returns
Fract(float)
Returns the fractional part of a value (x - floor(x)).
public static float Fract(float x)Parameters
x float
Returns
LerpAngle(float, float, float)
Linearly interpolates between two angles in radians, taking the shortest path around the circle.
public static float LerpAngle(float from, float to, float amount)Parameters
from float
Start angle in radians.
to float
End angle in radians.
amount float
Interpolation weight (0.0 = from, 1.0 = to).
Returns
Interpolated angle in radians.
MinMaxFixUp<T>(ref T, ref T)
Swaps min and max if min > max.
public static void MinMaxFixUp<T>(ref T min, ref T max) where T : INumber<T>Parameters
min T
max T
Type Parameters
T
Remap(float, float, float)
Remaps a value from input range to 0-1.
public static float Remap(float x, float inputMin, float inputMax)Parameters
x float
Value to remap.
inputMin float
Input range minimum.
inputMax float
Input range maximum.
Returns
Value remapped to 0-1 range.
RemapRange(float, float, float, float, float)
Remaps a value from one range to another.
public static float RemapRange(float x, float inputMin, float inputMax, float outputMin, float outputMax)Parameters
x float
Value to remap.
inputMin float
Input range minimum.
inputMax float
Input range maximum.
outputMin float
Output range minimum.
outputMax float
Output range maximum.
Returns
Value remapped to output range.
RemapValClamped(float, float, float, float, float)
Remaps a value from one range to another, holding the output at the range ends for inputs outside the input range. Mirrors Source's RemapValClamped.
public static float RemapValClamped(float x, float inputMin, float inputMax, float outputMin, float outputMax)Parameters
x float
Value to remap.
inputMin float
Input range minimum.
inputMax float
Input range maximum.
outputMin float
Output range minimum.
outputMax float
Output range maximum.
Returns
Value remapped to the output range, clamped to it.
Saturate(float)
Clamps a value to [0, 1].
public static float Saturate(float x)Parameters
x float
Returns
Smoothstep(float, float, float)
GLSL's smoothstep: 0 below edge0, 1 above edge1, and a Hermite ease between them. Edges may be given in either order, so a descending pair produces a falling curve.
public static float Smoothstep(float edge0, float edge1, float x)Parameters
edge0 float
Value at which the result reaches 0.
edge1 float
Value at which the result reaches 1.
x float
Value to interpolate.
Returns
The eased value in the 0-1 range.
ToPerceptualVolume(float)
Maps a linear 0-1 value onto an exponential curve approximating perceptual loudness, so the middle of a volume control (or a linear distance falloff) does not sound louder than it should.
public static float ToPerceptualVolume(float linear)Parameters
linear float
Returns
Wrap(float, float, float)
Wraps a value into the half-open range [lowBounds, highBounds).
public static float Wrap(float x, float lowBounds, float highBounds)Parameters
x float
lowBounds float
highBounds float

