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.
- auto min_(T a, T b) -> T
- auto max_(T a, T b) -> T
- auto clamp(T value, T a, T b) -> T
- Ensures that the given number stays in the range
[a, b]
, included;a <= b
. - auto lerp(const T& a, const T& b, float mix) -> T
- Linear interpolation between two values, which can be integers, floats, vectors or colors.
- 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
andb
result invalue
- 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
orangle2 - inc
, in the range [-PI, PI], depending on what's the shortest way to get fromangle1
toangle2
. - auto CorrectAngleRange(float angle) -> float
- Converts the given angle to the [-PI, PI] range, everything in radians.
- 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 differenttarget
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
Function documentation
Math:: ASSERT_SIZE(Color,
0x4)
#include <Spore ModAPI/Spore/MathUtils.h>
namespace Math:: Addresses(BoundingBox)
#include <Spore ModAPI/Spore/MathUtils.h>
ColorRGB Math:: HSVtoRGB(const ColorHSV& hsv)
#include <Spore ModAPI/Spore/MathUtils.h>
Converts the given HSV color into a RGB color.
ColorHSV Math:: RGBtoHSV(const ColorRGB& rgb)
#include <Spore ModAPI/Spore/MathUtils.h>
Converts the given RGB color into a HSV color.
RandomNumberGenerator& Math:: GetRNG()
#include <Spore ModAPI/Spore/MathUtils.h>
Returns the generic random number generator.
int Math:: rand(int range)
#include <Spore ModAPI/Spore/MathUtils.h>
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()
#include <Spore ModAPI/Spore/MathUtils.h>
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)
#include <Spore ModAPI/Spore/MathUtils.h>
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.
namespace Math:: Addresses(RandomNumberGenerator)
#include <Spore ModAPI/Spore/MathUtils.h>
Quaternion Math:: operator*(Quaternion a,
const Quaternion& b)
#include <Spore ModAPI/Spore/MathUtils.h>
Point Math:: operator+(Point a,
float b)
#include <Spore ModAPI/Spore/MathUtils.h>
Point Math:: operator-(Point a,
float b)
#include <Spore ModAPI/Spore/MathUtils.h>
Point Math:: operator*(Point a,
float b)
#include <Spore ModAPI/Spore/MathUtils.h>
Point Math:: operator/(Point a,
float b)
#include <Spore ModAPI/Spore/MathUtils.h>
Point Math:: operator-(const Point& a)
#include <Spore ModAPI/Spore/MathUtils.h>
Vector2 Math:: operator+(Vector2 a,
float b)
#include <Spore ModAPI/Spore/MathUtils.h>
Vector2 Math:: operator-(Vector2 a,
float b)
#include <Spore ModAPI/Spore/MathUtils.h>
Vector2 Math:: operator*(Vector2 a,
float b)
#include <Spore ModAPI/Spore/MathUtils.h>
Vector2 Math:: operator/(Vector2 a,
float b)
#include <Spore ModAPI/Spore/MathUtils.h>
Vector2 Math:: operator-(const Vector2& a)
#include <Spore ModAPI/Spore/MathUtils.h>
Vector3 Math:: operator+(Vector3 a,
float b)
#include <Spore ModAPI/Spore/MathUtils.h>
Vector3 Math:: operator-(Vector3 a,
float b)
#include <Spore ModAPI/Spore/MathUtils.h>
Vector3 Math:: operator*(Vector3 a,
float b)
#include <Spore ModAPI/Spore/MathUtils.h>
Vector3 Math:: operator/(Vector3 a,
float b)
#include <Spore ModAPI/Spore/MathUtils.h>
Vector3 Math:: operator-(const Vector3& a)
#include <Spore ModAPI/Spore/MathUtils.h>
Vector4 Math:: operator-(const Vector4& a)
#include <Spore ModAPI/Spore/MathUtils.h>
Vector4 Math:: operator+(Vector4 a,
float b)
#include <Spore ModAPI/Spore/MathUtils.h>
Vector4 Math:: operator-(Vector4 a,
float b)
#include <Spore ModAPI/Spore/MathUtils.h>
Vector4 Math:: operator*(Vector4 a,
float b)
#include <Spore ModAPI/Spore/MathUtils.h>
Vector4 Math:: operator/(Vector4 a,
float b)
#include <Spore ModAPI/Spore/MathUtils.h>
float Math:: ToRadians(float degrees)
#include <Spore ModAPI/Spore/MathUtils.h>
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)
#include <Spore ModAPI/Spore/MathUtils.h>
Converts the given angle in radians into the angle in degrees.
Parameters | |
---|---|
radians | The angle, in radians. |
Returns | The angle in degrees. |
#include <Spore ModAPI/Spore/MathUtils.h>
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
#include <Spore ModAPI/Spore/MathUtils.h>
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)
#include <Spore ModAPI/Spore/MathUtils.h>
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)
#include <Spore ModAPI/Spore/MathUtils.h>
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)
#include <Spore ModAPI/Spore/MathUtils.h>
Converts the given angle to the [-PI, PI] range, everything in radians.
Parameters | |
---|---|
angle |
float Math:: remap(const Vector2& source,
const Vector2& target,
float value)
#include <Spore ModAPI/Spore/MathUtils.h>
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
#include <Spore ModAPI/Spore/MathUtils.h>
template<>
ColorRGB Math:: lerp<ColorRGB>(const ColorRGB& a,
const ColorRGB& b,
float mix)
#include <Spore ModAPI/Spore/MathUtils.h>
template<>
ColorRGBA Math:: lerp<ColorRGBA>(const ColorRGBA& a,
const ColorRGBA& b,
float mix)
Variable documentation
const float Math:: PI
#include <Spore ModAPI/Spore/MathUtils.h>
const Vector3 Math:: X_AXIS
#include <Spore ModAPI/Spore/MathUtils.h>
const Vector3 Math:: Y_AXIS
#include <Spore ModAPI/Spore/MathUtils.h>
const Vector3 Math:: Z_AXIS
#include <Spore ModAPI/Spore/MathUtils.h>