Math namespace

Basic mathematical objects and functions, such as vectors, random numbers,...

Classes

struct BoundingBox
A pair of two Vector3 that define the boundaries of an object (the minimum point and the maximum point in the space).
struct Color
An ARGB color represented by a 32 bit integer value.
struct ColorHSV
Three float values that represent a color (the hue, saturation and value/brightness values).
struct ColorRGB
Three float values in the range [0, 1] that represent a color (the red, green and blue components).
struct ColorRGBA
Four float values in the range [0, 1] that represent a color (the red, green, blue and alpha components).
struct Dimensions
A pair of two float values that represents the dimensions of an image (width, height).
struct IntDimensions
A pair of two integer values that represents the dimensions of an image (width, height).
struct IntRectangle
Represents a rectangular space, defined by two points or by the four edges.
struct Matrix3
A 3x3 matrix.
struct Matrix4
A 4x4 matrix.
struct PlaneEquation
struct Point
Represents a point in the space, defined by two float coordinates (x, y).
struct Quaternion
A vector of 4 float values (x, y, z, w) representing a quaternion rotation, similar to a Vector4.
struct RandomNumberGenerator
struct Rectangle
Represents a rectangular space, defined by two points or by the four edges.
struct Vector2
A vector of 2 float values (x, y).
struct Vector3
A vector of 3 float values (x, y, z).
struct Vector4
A vector of 4 float values (x, y, z, w).

Functions

ASSERT_SIZE(Color, 0x4)
auto Addresses(BoundingBox) -> namespace
auto HSVtoRGB(const ColorHSV& hsv) -> ColorRGB
Converts the given HSV color into a RGB color.
auto RGBtoHSV(const ColorRGB& rgb) -> ColorHSV
Converts the given RGB color into a HSV color.
auto GetRNG() -> RandomNumberGenerator&
Returns the generic random number generator.
auto rand(int range) -> int
Generates a random integer between 0 and the given parameter, excluded.
auto randf() -> float
Generates a random float number between 0.0 and 1.0.
auto randf(float minValue, float maxValue) -> float
Generates a random float number between minValue and maxValue.
auto Addresses(RandomNumberGenerator) -> namespace
auto operator*(Matrix3 a, const Vector3& b) -> Vector3
auto operator*(Matrix3 a, const Matrix3& b) -> Matrix3
auto operator*(Quaternion a, const Quaternion& b) -> Quaternion
auto operator+(Point a, const Point& b) -> Point
auto operator+(Point a, float b) -> Point
auto operator-(Point a, const Point& b) -> Point
auto operator-(Point a, float b) -> Point
auto operator*(Point a, float b) -> Point
auto operator/(Point a, float b) -> Point
auto operator-(const Point& a) -> Point
auto operator+(float a, const Point& b) -> Point
auto operator-(float a, const Point& b) -> Point
auto operator*(float a, const Point& b) -> Point
auto operator+(Vector2 a, const Vector2& b) -> Vector2
auto operator+(Vector2 a, float b) -> Vector2
auto operator-(Vector2 a, const Vector2& b) -> Vector2
auto operator-(Vector2 a, float b) -> Vector2
auto operator*(Vector2 a, float b) -> Vector2
auto operator/(Vector2 a, float b) -> Vector2
auto operator-(const Vector2& a) -> Vector2
auto operator+(float a, const Vector2& b) -> Vector2
auto operator-(float a, const Vector2& b) -> Vector2
auto operator*(float a, const Vector2& b) -> Vector2
auto operator+(Vector3 a, const Vector3& b) -> Vector3
auto operator+(Vector3 a, float b) -> Vector3
auto operator-(Vector3 a, const Vector3& b) -> Vector3
auto operator-(Vector3 a, float b) -> Vector3
auto operator*(Vector3 a, float b) -> Vector3
auto operator/(Vector3 a, float b) -> Vector3
auto operator-(const Vector3& a) -> Vector3
auto operator+(float a, const Vector3& b) -> Vector3
auto operator-(float a, const Vector3& b) -> Vector3
auto operator*(float a, const Vector3& b) -> Vector3
auto operator-(const Vector4& a) -> Vector4
auto operator+(Vector4 a, const Vector4& b) -> Vector4
auto operator+(Vector4 a, float b) -> Vector4
auto operator-(Vector4 a, const Vector4& b) -> Vector4
auto operator-(Vector4 a, float b) -> Vector4
auto operator*(Vector4 a, float b) -> Vector4
auto operator/(Vector4 a, float b) -> Vector4
auto operator+(float a, const Vector4& b) -> Vector4
auto operator-(float a, const Vector4& b) -> Vector4
auto operator*(float a, const Vector4& b) -> Vector4
auto ToRadians(float degrees) -> float
Converts the given angle in degrees into the angle in radians.
auto ToDegrees(float radians) -> float
Converts the given angle in radians into the angle in degrees.
template<typename T>
auto min_(T a, T b) -> T
template<typename T>
auto max_(T a, T b) -> T
template<typename T>
auto clamp(T value, T a, T b) -> T
Ensures that the given number stays in the range [a, b], included; a <= b.
template<typename T>
auto lerp(const T& a, const T& b, float mix) -> T
Linear interpolation between two values, which can be integers, floats, vectors or colors.
template<typename T>
auto invLerp(const T& a, const T& b, const T& value) -> float
Inverse operation of lerp(): given a range and a value, returns the parameter that would make a linear interpolation between a and b result in value
auto GetAngleDifference(float angle1, float angle2) -> float
Returns the shortest difference between two angles (in radians), the result is always in the range [0, PI].
auto IncrementAngleTo(float angle1, float angle2, float inc) -> float
Returns angle1 + inc or angle2 - inc, in the range [-PI, PI], depending on what's the shortest way to get from angle1 to angle2.
auto CorrectAngleRange(float angle) -> float
Converts the given angle to the [-PI, PI] range, everything in radians.
template<typename T>
auto sgn(T val) -> int
Returns -1 for negative numbers, +1 for positive numbers, and 0 if the value is 0.
auto remap(const Vector2& source, const Vector2& target, float value) -> float
Remaps a value from one source range to a different target range.
auto distance(const Vector3& point1, const Vector3& point2) -> float
Returns the distance between two points.
template<>
auto lerp<ColorRGB>(const ColorRGB& a, const ColorRGB& b, float mix) -> ColorRGB
template<>
auto lerp<ColorRGBA>(const ColorRGBA& a, const ColorRGBA& b, float mix) -> ColorRGBA

Variables

const float PI
const Vector3 X_AXIS
const Vector3 Y_AXIS
const Vector3 Z_AXIS

Function documentation

ColorRGB Math::HSVtoRGB(const ColorHSV& hsv)

Converts the given HSV color into a RGB color.

ColorHSV Math::RGBtoHSV(const ColorRGB& rgb)

Converts the given RGB color into a HSV color.

RandomNumberGenerator& Math::GetRNG()

Returns the generic random number generator.

int Math::rand(int range)

Generates a random integer between 0 and the given parameter, excluded.

Parameters
range The maximum value that can be generated.

This uses the default RNG, which uses the time stamp as seed.

float Math::randf()

Generates a random float number between 0.0 and 1.0.

This uses the default RNG, which uses the time stamp as seed.

float Math::randf(float minValue, float maxValue)

Generates a random float number between minValue and maxValue.

Parameters
minValue The minimum possible value.
maxValue The maximum possible value.

This uses the default RNG, which uses the time stamp as seed.

float Math::ToRadians(float degrees)

Converts the given angle in degrees into the angle in radians.

Parameters
degrees The angle, in degrees.
Returns The angle in radians.

float Math::ToDegrees(float radians)

Converts the given angle in radians into the angle in degrees.

Parameters
radians The angle, in radians.
Returns The angle in degrees.

template<typename T>
T Math::min_(T a, T b)

template<typename T>
T Math::max_(T a, T b)

template<typename T>
T Math::clamp(T value, T a, T b)

Ensures that the given number stays in the range [a, b], included; a <= b.

Parameters
value The value to clamp
a The minimum value
b The maximum value

If value > b, it returns b; if value < a, it returns a.

template<typename T>
T Math::lerp(const T& a, const T& b, float mix)

Linear interpolation between two values, which can be integers, floats, vectors or colors.

Parameters
a The first value of the range
b The second value of the range
mix The mix factor, between 0.0 and 1.0

A mix value of 0 returns a, a value of 1 returns b.

The returned value will be equal to mix*a + (1-mix)*b

template<typename T>
float Math::invLerp(const T& a, const T& b, const T& value)

Inverse operation of lerp(): given a range and a value, returns the parameter that would make a linear interpolation between a and b result in value

Parameters
a The first value of the range
b The second value of the range
value A value between a and b

float Math::GetAngleDifference(float angle1, float angle2)

Returns the shortest difference between two angles (in radians), the result is always in the range [0, PI].

Parameters
angle1
angle2

The order of the angles does not matter.

float Math::IncrementAngleTo(float angle1, float angle2, float inc)

Returns angle1 + inc or angle2 - inc, in the range [-PI, PI], depending on what's the shortest way to get from angle1 to angle2.

Parameters
angle1 "Source" angle
angle2 "Dest" angle
inc How many radians are incremented.

All the angles are in radians.

float Math::CorrectAngleRange(float angle)

Converts the given angle to the [-PI, PI] range, everything in radians.

Parameters
angle

template<typename T>
int Math::sgn(T val)

Returns -1 for negative numbers, +1 for positive numbers, and 0 if the value is 0.

float Math::remap(const Vector2& source, const Vector2& target, float value)

Remaps a value from one source range to a different target range.

Parameters
source The source range
target The target range
value A value inside the source range

This is the combination of invLerp() for the source range and lerp() for the target range

float Math::distance(const Vector3& point1, const Vector3& point2)

Returns the distance between two points.

Parameters
point1
point2

Variable documentation