TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
TurtleBrains::Math Namespace Reference

Contains objects and functions for dealing with Vector and Matrix math. More...

Classes

class  TypedAngle
 
class  BezierCurve
 
class  TypedVector3
 
class  TypedVector4
 
class  TypedMatrix3
 
class  TypedMatrix4
 
class  TypedQuaternion
 
class  TypedVector2
 

Typedefs

typedef TypedAngle< float > Angle
 
typedef TypedMatrix3< float > Matrix3
 
typedef TypedMatrix4< float > Matrix4
 
typedef TypedQuaternion< float > Quaternion
 
typedef TypedVector2< float > Vector2
 
typedef TypedVector3< float > Vector3
 
typedef TypedVector4< float > Vector4
 

Enumerations

enum class  AngleUnit { Degrees , Radians }
 
enum  ColumnMajorMatrix { ColumnMajor = 1 }
 
enum  SkipInitialization { kSkipInitialization = 0 }
 
enum  VectorComponent { kComponentX = 0 , kComponentY , kComponentZ , kComponentW }
 

Functions

template<typename Type >
std::ostream & operator<< (std::ostream &output, const tbMath::TypedAngle< Type > &angle)
 
template<typename Type >
constexpr Type Pi (void)
 
template<typename Type >
constexpr Type TwoPi (void)
 
static const float kTolerance (0.00001f)
 
const float kPoundsToKilograms (0.45359237f)
 A constant for the conversion of 1 pound (lb) to 1 kilogram (kg).
 
const float kKilogramsToPounds (1.0f/kPoundsToKilograms)
 A constant for the conversion of 1 kilogram (kg) to 1 pound (lb).
 
const float kInchesToMeters (0.0254f)
 A constant for the distance conversion of 1 inch to 1 meter.
 
const float kMetersToInches (1.0f/kInchesToMeters)
 A constant for the distance conversion of 1 meter to 1 inch.
 
const float kFeetToMeters (0.3048f)
 A constant for the distance conversion from 1 foot to 1 meter.
 
const float kMetersToFeet (1.0f/kFeetToMeters)
 A constant for the distance conversion from 1 meter to 1 foot.
 
const float kMilesToKilometers (1.609344f)
 A constant for the distance conversion from 1 mile to 1 kilometer.
 
const float kKilometersToMiles (1.0f/kMilesToKilometers)
 A constant for the distance conversion from 1 kilometer to 1 mile.
 
const float kFootPoundsToNewtonMeters (0.73756214837f)
 A constant for the torque in ft-lbs to Nm.
 
const float kNewtonMetersToFootPounds (1.0f/kFootPoundsToNewtonMeters)
 A constant for the torque conversion from Nm to ft-lbs.
 
template<typename Type >
constexpr const Type & Maximum (const Type &leftValue, const Type &rightValue) noexcept
 
template<typename Type >
constexpr const Type & Minimum (const Type &leftValue, const Type &rightValue) noexcept
 
template<typename Type >
bool IsEqual (const Type &leftValue, const Type &rightValue, const Type tolerance=tbMath::kTolerance)
 
template<typename Type >
bool IsZero (const Type &value, const Type tolerance=tbMath::kTolerance)
 
template<typename Type >
constexpr const Type & Clamp (const Type &value, const Type &minimumValue, const Type &maximumValue) noexcept
 
template<typename Type >
Type Sign (const Type &value) noexcept
 
template<typename Type >
TypedVector3< Type > * Vector3MatrixMultiply (TypedVector3< Type > *result, const TypedVector3< Type > *inputVector, const TypedMatrix3< Type > *inputMatrix)
 
template<typename Type >
TypedVector3< Type > * MatrixVector3Multiply (TypedVector3< Type > *result, const TypedMatrix3< Type > *inputMatrix, const TypedVector3< Type > *inputVector)
 
template<typename Type >
TypedMatrix3< Type > * MatrixMultiply (TypedMatrix3< Type > *result, const TypedMatrix3< Type > *input, const Type &scalar)
 
template<typename Type >
TypedMatrix4< Type > * MatrixMultiply (TypedMatrix4< Type > *result, const TypedMatrix4< Type > *input, const Type &scalar)
 
template<typename Type >
TypedMatrix3< Type > * MatrixMultiply (TypedMatrix3< Type > *result, const TypedMatrix3< Type > *leftSide, const TypedMatrix3< Type > *rightSide)
 
template<typename Type >
TypedMatrix4< Type > * MatrixMultiply (TypedMatrix4< Type > *result, const TypedMatrix4< Type > *leftSide, const TypedMatrix4< Type > *rightSide)
 
template<typename Type >
TypedVector4< Type > * MatrixVector4Multiply (TypedVector4< Type > *result, const TypedMatrix4< Type > *inputMatrix, const TypedVector4< Type > *inputVector)
 
template<typename Type >
TypedVector4< Type > * Vector4MatrixMultiply (TypedVector4< Type > *result, const TypedVector4< Type > *inputVector, const TypedMatrix4< Type > *inputMatrix)
 
template<typename Type >
TypedVector3< Type > * Vector3TransformCoordinate (TypedVector3< Type > *result, const TypedVector3< Type > *inputVector, const TypedMatrix4< Type > *inputMatrix)
 
template<typename Type >
TypedVector3< Type > * Vector3TransformNormal (TypedVector3< Type > *result, const TypedVector3< Type > *inputVector, const TypedMatrix4< Type > *inputMatrix)
 
template<typename Type >
TypedMatrix3< Type > * MatrixComputeInverse (TypedMatrix3< Type > *result, const TypedMatrix3< Type > *input)
 
template<typename Type >
TypedMatrix4< Type > * MatrixComputeInverse (TypedMatrix4< Type > *result, const TypedMatrix4< Type > *input)
 
template<typename Type >
TypedMatrix3< Type > * MatrixFastInverse (TypedMatrix3< Type > *result, const TypedMatrix3< Type > *input)
 
template<typename Type >
TypedMatrix4< Type > * MatrixFastInverse (TypedMatrix4< Type > *result, const TypedMatrix4< Type > *input)
 
template<typename Type >
TypedMatrix4< Type > * MatrixCreateTranslation (TypedMatrix4< Type > *result, const TypedVector3< Type > *translation)
 
template<typename Type >
TypedMatrix4< Type > * MatrixCreateTranslation (TypedMatrix4< Type > *result, const Type translationX, const Type translationY, const Type translationZ)
 
template<typename Type >
TypedMatrix3< Type > * MatrixCreateScale (TypedMatrix3< Type > *result, const TypedVector3< Type > *scale)
 
template<typename Type >
TypedMatrix4< Type > * MatrixCreateScale (TypedMatrix4< Type > *result, const TypedVector3< Type > *scale)
 
template<typename Type >
TypedMatrix3< Type > * MatrixCreateScale (TypedMatrix3< Type > *result, const Type scaleX, const Type scaleY, const Type scaleZ)
 
template<typename Type >
TypedMatrix4< Type > * MatrixCreateScale (TypedMatrix4< Type > *result, const Type scaleX, const Type scaleY, const Type scaleZ)
 
template<typename Type >
TypedMatrix3< Type > * MatrixCreateRotationX (TypedMatrix3< Type > *result, const TypedAngle< Type > rotation)
 
template<typename Type >
TypedMatrix4< Type > * MatrixCreateRotationX (TypedMatrix4< Type > *result, const tbMath::TypedAngle< Type > rotation)
 
template<typename Type >
TypedMatrix3< Type > * MatrixCreateRotationY (TypedMatrix3< Type > *result, const TypedAngle< Type > rotation)
 
template<typename Type >
TypedMatrix4< Type > * MatrixCreateRotationY (TypedMatrix4< Type > *result, const tbMath::TypedAngle< Type > rotation)
 
template<typename Type >
TypedMatrix3< Type > * MatrixCreateRotationZ (TypedMatrix3< Type > *result, const TypedAngle< Type > rotation)
 
template<typename Type >
TypedMatrix4< Type > * MatrixCreateRotationZ (TypedMatrix4< Type > *result, const tbMath::TypedAngle< Type > rotation)
 
template<typename Type >
TypedMatrix3< Type > * MatrixCreateRotationA (TypedMatrix3< Type > *result, const TypedVector3< Type > *rotationAxis, const TypedAngle< Type > rotation)
 
template<typename Type >
TypedMatrix4< Type > * MatrixCreateRotationA (TypedMatrix4< Type > *result, const TypedVector3< Type > *rotationAxis, const tbMath::TypedAngle< Type > rotation)
 
template<typename Type >
TypedMatrix3< Type > * MatrixCreateIdentity (TypedMatrix3< Type > *result)
 
template<typename Type >
TypedMatrix4< Type > * MatrixCreateIdentity (TypedMatrix4< Type > *result)
 
template<typename Type >
TypedMatrix4< Type > * MatrixCreateLookAt (TypedMatrix4< Type > *result, const TypedVector3< Type > &eyePosition, const TypedVector3< Type > &targetPosition, const TypedVector3< Type > &unitUp)
 
Matrix4MatrixCreatePerspectiveRH (Matrix4 *result, const float fieldOfView, const float aspectRatio, const float nearPlane, const float farPlane)
 
Matrix4MatrixCreatePerspectiveLH (Matrix4 *result, const float fieldOfView, const float aspectRatio, const float nearPlane, const float farPlane)
 
Matrix4MatrixCreateOrthoRH (Matrix4 *result, const float left, const float right, const float top, const float bottom, const float nearPlane, const float farPlane)
 
Matrix4MatrixCreateOrthoLH (Matrix4 *result, const float left, const float right, const float top, const float bottom, const float nearPlane, const float farPlane)
 
Matrix3MatrixAdd (Matrix3 *result, const Matrix3 *leftSide, const Matrix3 *rightSide)
 
Matrix4MatrixAdd (Matrix4 *result, const Matrix4 *leftSide, const Matrix4 *rightSide)
 
Matrix3MatrixSubtract (Matrix3 *result, const Matrix3 *leftSide, const Matrix3 *rightSide)
 
Matrix4MatrixSubtract (Matrix4 *result, const Matrix4 *leftSide, const Matrix4 *rightSide)
 
Matrix3MatrixTranspose (Matrix3 *result, const Matrix3 *input)
 
Matrix4MatrixTranspose (Matrix4 *result, const Matrix4 *input)
 
template<typename Type >
Type Matrix2x2Determinant (const Type f11, const Type f12, const Type f21, const Type f22)
 
template<typename Type >
Type Matrix3x3Determinant (const Type f11, const Type f12, const Type f13, const Type f21, const Type f22, const Type f23, const Type f31, const Type f32, const Type f33)
 
template<typename Type >
Type MatrixDeterminant (const TypedMatrix3< Type > *input)
 
template<typename Type >
Type MatrixDeterminant (const TypedMatrix4< Type > *input)
 
template<typename Type >
std::ostream & operator<< (std::ostream &output, const tbMath::TypedMatrix3< Type > &data)
 
template<typename Type >
std::istream & operator>> (std::istream &input, tbMath::TypedMatrix3< Type > &data)
 
template<typename Type >
std::ostream & operator<< (std::ostream &output, const tbMath::TypedMatrix4< Type > &data)
 
template<typename Type >
std::istream & operator>> (std::istream &input, tbMath::TypedMatrix4< Type > &data)
 
template<typename Type >
TypedVector3< Type > MultiplyVector3Quaternion (const TypedVector3< Type > &left, const TypedQuaternion< Type > &right)
 
template<typename Type >
TypedQuaternion< Type > * QuaternionMultiply (TypedQuaternion< Type > *result, const TypedQuaternion< Type > *left, const TypedQuaternion< Type > *right)
 
template<typename Type >
TypedQuaternion< Type > * QuaternionAdd (TypedQuaternion< Type > *result, const TypedQuaternion< Type > *left, const TypedQuaternion< Type > *right)
 
template<typename Type >
TypedQuaternion< Type > * QuaternionSubtract (TypedQuaternion< Type > *result, const TypedQuaternion< Type > *left, const TypedQuaternion< Type > *right)
 
template<typename Type >
TypedQuaternion< Type > * QuaternionScale (TypedQuaternion< Type > *result, const TypedQuaternion< Type > *input, const Type scalar)
 
template<typename Type >
TypedQuaternion< Type > * QuaternionScaleDivide (TypedQuaternion< Type > *result, const TypedQuaternion< Type > *input, const Type scalar)
 
template<typename Type >
TypedQuaternion< Type > * QuaternionNegate (TypedQuaternion< Type > *result, const TypedQuaternion< Type > *input)
 
template<typename Type >
Type QuaternionMagnitude (const TypedQuaternion< Type > *input)
 
template<typename Type >
Type QuaternionMagnitudeSquared (const TypedQuaternion< Type > *input)
 
template<typename Type >
TypedQuaternion< Type > * QuaternionNormalize (TypedQuaternion< Type > *result, const TypedQuaternion< Type > *input)
 
template<typename Type >
TypedQuaternion< Type > * QuaternionNormalizeMagnitude (TypedQuaternion< Type > *result, const TypedQuaternion< Type > *input, Type &magnitude)
 
template<typename Type >
TypedQuaternion< Type > * QuaternionInverse (TypedQuaternion< Type > *result, const TypedQuaternion< Type > *input)
 
template<typename Type >
Type QuaternionDotProduct (const TypedQuaternion< Type > *leftSide, const TypedQuaternion< Type > *rightSide)
 
template<typename Type >
TypedQuaternion< Type > * QuaternionLerp (TypedQuaternion< Type > *result, const TypedQuaternion< Type > *start, const TypedQuaternion< Type > *final, const Type time)
 
template<typename Type >
TypedQuaternion< Type > QuaternionSlerp (const TypedQuaternion< Type > &start, const TypedQuaternion< Type > &final, const Type time)
 
template<typename Type >
std::ostream & operator<< (std::ostream &output, const tbMath::TypedQuaternion< Type > &data)
 
unsigned int SeedRandomGenerator (void)
 
unsigned int SeedRandomGenerator (const String &seed)
 
void SeedRandomGenerator (unsigned int seed)
 
int RandomInt (void)
 
int RandomInt (const int minimumValue, const int maximumValue)
 
float RandomFloat (void)
 
float RandomFloat (const float minimumValue, const float maximumValue)
 
template<typename Type >
Type Vector2DotProduct (const TypedVector2< Type > *leftSide, const TypedVector2< Type > *rightSide)
 
template<typename Type >
Type Vector3DotProduct (const TypedVector3< Type > *leftSide, const TypedVector3< Type > *rightSide)
 
template<typename Type >
Type Vector4DotProduct (const TypedVector4< Type > *leftSide, const TypedVector4< Type > *rightSide)
 
template<typename Type >
TypedVector3< Type > * Vector3CrossProduct (TypedVector3< Type > *result, const TypedVector3< Type > *leftSide, const TypedVector3< Type > *rightSide)
 
template<typename Type >
TypedVector2< Type > * Vector2Normalize (TypedVector2< Type > *result, const TypedVector2< Type > *value)
 
template<typename Type >
TypedVector3< Type > * Vector3Normalize (TypedVector3< Type > *result, const TypedVector3< Type > *input)
 
template<typename Type >
TypedVector4< Type > * Vector4Normalize (TypedVector4< Type > *result, const TypedVector4< Type > *input)
 
template<typename Type >
TypedVector2< Type > * Vector2NormalizeMagnitude (TypedVector2< Type > *result, const TypedVector2< Type > *value, Type &magnitude)
 
template<typename Type >
TypedVector3< Type > * Vector3NormalizeMagnitude (TypedVector3< Type > *result, const TypedVector3< Type > *input, Type &magnitude)
 
template<typename Type >
TypedVector4< Type > * Vector4NormalizeMagnitude (TypedVector4< Type > *result, const TypedVector4< Type > *input, Type &magnitude)
 
Vector2Vector2Add (Vector2 *result, const Vector2 *leftSide, const Vector2 *rightSide)
 
Vector3Vector3Add (Vector3 *result, const Vector3 *leftSide, const Vector3 *rightSide)
 
Vector4Vector4Add (Vector4 *result, const Vector4 *leftSide, const Vector4 *rightSide)
 
Vector2Vector2Subtract (Vector2 *result, const Vector2 *leftSide, const Vector2 *rightSide)
 
Vector3Vector3Subtract (Vector3 *result, const Vector3 *leftSide, const Vector3 *rightSide)
 
Vector4Vector4Subtract (Vector4 *result, const Vector4 *leftSide, const Vector4 *rightSide)
 
Vector2Vector2Scale (Vector2 *result, const Vector2 *input, const float scalar)
 
Vector3Vector3Scale (Vector3 *result, const Vector3 *input, const float scalar)
 
Vector4Vector4Scale (Vector4 *result, const Vector4 *input, const float scalar)
 
Vector2Vector2ScaleDivide (Vector2 *result, const Vector2 *input, const float scalar)
 
Vector3Vector3ScaleDivide (Vector3 *result, const Vector3 *input, const float scalar)
 
Vector4Vector4ScaleDivide (Vector4 *result, const Vector4 *input, const float scalar)
 
Vector2Vector2Negate (Vector2 *result, const Vector2 *input)
 
Vector3Vector3Negate (Vector3 *result, const Vector3 *input)
 
Vector4Vector4Negate (Vector4 *result, const Vector4 *input)
 
template<typename Type >
Type Vector2Magnitude (const TypedVector2< Type > *input)
 
template<typename Type >
Type Vector3Magnitude (const TypedVector3< Type > *input)
 
template<typename Type >
Type Vector4Magnitude (const TypedVector4< Type > *input)
 
template<typename Type >
Type Vector2MagnitudeSquared (const TypedVector2< Type > *input)
 
template<typename Type >
Type Vector3MagnitudeSquared (const TypedVector3< Type > *input)
 
template<typename Type >
Type Vector4MagnitudeSquared (const TypedVector4< Type > *input)
 
template<typename Type >
TypedAngle< Type > Vector3AngleBetween (const TypedVector3< Type > *left, const TypedVector3< Type > *right)
 
static Vector3RotationXZToForwardVector3 (Vector3 &result, const Angle &orientation)
 
static Vector2RotationToForwardVector2 (Vector2 &result, const Angle &orientation)
 
static Angle ForwardVector3ToRotationXZ (const Vector3 &forward)
 
static Angle ForwardVector2ToRotation (const Vector2 &forward)
 
template<typename Type >
std::ostream & operator<< (std::ostream &output, const tbMath::TypedVector2< Type > &data)
 
template<typename Type >
std::istream & operator>> (std::istream &input, const tbMath::TypedVector2< Type > &data)
 
template<typename Type >
std::ostream & operator<< (std::ostream &output, const tbMath::TypedVector3< Type > &data)
 
template<typename Type >
std::istream & operator>> (std::istream &input, const tbMath::TypedVector3< Type > &data)
 
template<typename Type >
std::ostream & operator<< (std::ostream &output, const tbMath::TypedVector4< Type > &data)
 
template<typename Type >
std::istream & operator>> (std::istream &input, const tbMath::TypedVector4< Type > &data)
 

Variables

static const float kPi = Pi<float>()
 A constant for the mathematical concept of Pi stored in a float.
 
static const float kTwoPi = TwoPi<float>()
 A constant for Pi * 2 stored in a float.
 

Detailed Description

Also known as tbMath, the objects and functions within the namespace TurtleBrains::Math are aimed to help reduce the burden with math by providing 2, 3 and 4 component Vector, 4x4 Matrix for transforms and a variety of helper functions for general purpose, converting values or interpolating.

Requirements:
TurtleBrains::Core

Typedef Documentation

◆ Angle

Specialization of the most common use of Angle, as a float.

Enumeration Type Documentation

◆ AngleUnit

Used to specify whether an Angle object is in Degrees or Radians when constructing.

Enumerator
Degrees 

Specifies the angle input value is in units of Degrees.

Radians 

Specifies the angle input value is in units of Radians.

◆ SkipInitialization

The SkipInitialization type is used to provide a non-constructor to a few objects, essentially TypedVector2, TypedVector3, TypedVector4 objects. The non-constructor essentially leaves the members of the object uninitialized. This is unsafe but allows for slightly faster creation of the object with the premise that the values will be set immediately after.

Note
Should be used only if the consequences are understood, and even then only sparingly.

◆ VectorComponent

Provides constant values for each component of the TypedVector2, TypedVector3 and TypedVector4 objects to get the component values by index using operator[].

Enumerator
kComponentX 

The index of the x component of the TypedVector2, TypedVector3 and TypedVector4 objects.

kComponentY 

The index of the y component of the TypedVector2, TypedVector3 and TypedVector4 objects.

kComponentZ 

The index of the z component of the TypedVector3, TypedVector4 objects.

kComponentW 

The index of the w component of the TypedVector4 object.

Function Documentation

◆ Clamp()

template<typename Type >
constexpr const Type& TurtleBrains::Math::Clamp ( const Type &  value,
const Type &  minimumValue,
const Type &  maximumValue 
)
constexprnoexcept

Returns a value that falls within the given range of minimumValue to maximumValue using only the less-than operator for the type.

Parameters
valueThe value that will be returned if it is within the range provided.
minimumValueThe lower end of the range to clamp the value at, will be returned if the value is less-than the range.
maximumValueThe upper end of the range to clamp the value at, will be returned if the value is greater-than the range.
Note
There will be compile issues if called on a type that does not have an operator< to use.

◆ ForwardVector2ToRotation()

static Angle TurtleBrains::Math::ForwardVector2ToRotation ( const Vector2 forward)
inlinestatic

Converts a normalized 'forward' vector to an orientation value for 2D games. The orientation returned will be the radians in a clockwise (in normal 2D TurtleBrains with +X being to screen right, and +Y being to screen down) from the negative Y-Axis, meaning that something pointing up the screen (-Y) will return 0.

Parameters
forwardshould be a normalized vector.

◆ ForwardVector3ToRotationXZ()

static Angle TurtleBrains::Math::ForwardVector3ToRotationXZ ( const Vector3 forward)
inlinestatic

Converts a normalized 'forward' vector to an orientation value for 2D games. The orientation returned will be an Angle object clockwise (TODO: TIM: Double check this directional comment) from the ZAxis, meaning the input vector should be something like forwardX, 0, forwardZ instead of the forwardX, forwardY.

Parameters
forwardshould be a vector on the XZ plane.

◆ IsEqual()

template<typename Type >
bool TurtleBrains::Math::IsEqual ( const Type &  leftValue,
const Type &  rightValue,
const Type  tolerance = tbMath::kTolerance 
)

Compares two floating point values returning true if the difference between the two values is less-than or equal to the tolerance allowed.

Parameters
leftValueThe value that would be on the left side of the comparison operator.
rightValueThe value that would be on the right side of the comparison operator.
toleranceAn optional value to change the tolerance of the comparison, smaller value means the floats need to be closer together, defaults to kTolerance.

◆ IsZero()

template<typename Type >
bool TurtleBrains::Math::IsZero ( const Type &  value,
const Type  tolerance = tbMath::kTolerance 
)

Compares a floating point values returning true if the difference between the value and zero is less-than or equal to the tolerance allowed.

Parameters
valueThe value to check if it is within the tolerance range of zero.
toleranceAn optional value to change the tolerance of the comparison, smaller value means the floats need to be closer together, defaults to kTolerance.

◆ kTolerance()

static const float TurtleBrains::Math::kTolerance ( 0.  00001f)
static

When comparing a float for equality or to zero, this is the default tolerance used. When the difference is less than the tolerance, the values are considered the same.

◆ Matrix3x3Determinant()

template<typename Type >
Type TurtleBrains::Math::Matrix3x3Determinant ( const Type  f11,
const Type  f12,
const Type  f13,
const Type  f21,
const Type  f22,
const Type  f23,
const Type  f31,
const Type  f32,
const Type  f33 
)

Computes the determinant of the 3x3 matrix components and returns the result. Essentially a supporting function for MatrixDeterminant and ComputeInverse below for the 4x4 matrix.

◆ MatrixAdd() [1/2]

Matrix3* TurtleBrains::Math::MatrixAdd ( Matrix3 result,
const Matrix3 leftSide,
const Matrix3 rightSide 
)
inline

Adds two Matrix objects together into matrixResult and then the results matrix is returned.

Parameters
resultThe matrix to fill out and return with the result of the two matrices added together.
leftSideThe matrix on the left side of the addition operator.
rightSideThe matrix on the right side of the addition operator.

◆ MatrixAdd() [2/2]

Matrix4* TurtleBrains::Math::MatrixAdd ( Matrix4 result,
const Matrix4 leftSide,
const Matrix4 rightSide 
)
inline

Adds two Matrix objects together into matrixResult and then the results matrix is returned.

Parameters
resultThe matrix to fill out and return with the result of the two matrices added together.
leftSideThe matrix on the left side of the addition operator.
rightSideThe matrix on the right side of the addition operator.

◆ MatrixComputeInverse() [1/2]

template<typename Type >
TypedMatrix3< Type > * TurtleBrains::Math::MatrixComputeInverse ( TypedMatrix3< Type > *  result,
const TypedMatrix3< Type > *  input 
)

TODO: TurtleBrains: Math: This is not documented or implemented or tested... (Why does it exist at all?)

◆ MatrixComputeInverse() [2/2]

template<typename Type >
TypedMatrix4< Type > * TurtleBrains::Math::MatrixComputeInverse ( TypedMatrix4< Type > *  result,
const TypedMatrix4< Type > *  input 
)

Computes the inverse matrix that when multiplied against the initial input would result in an identity matrix.

Parameters
resultThe matrix to store and return the computed inverse matrix of input. This cannot be the same matrix as the input matrix or an error condition will be triggered.
inputThe matrix to compute the inverse of, cannot be the same as the result matrix or an error condition will be triggered.
Note
this is a fairly heavy lifter so use lightly.

◆ MatrixCreateIdentity() [1/2]

template<typename Type >
TypedMatrix3<Type>* TurtleBrains::Math::MatrixCreateIdentity ( TypedMatrix3< Type > *  result)

---------------------------------------------------------------------------------------------------------------—/// ---------------------------------------------------------------------------------------------------------------—/// ---------------------------------------------------------------------------------------------------------------—///

Fills the matrix with the values from the identity matrix and returns the result.

Parameters
resultThe matrix to fill out and return.

◆ MatrixCreateIdentity() [2/2]

template<typename Type >
TypedMatrix4<Type>* TurtleBrains::Math::MatrixCreateIdentity ( TypedMatrix4< Type > *  result)

◆ MatrixCreateLookAt()

template<typename Type >
TypedMatrix4<Type>* TurtleBrains::Math::MatrixCreateLookAt ( TypedMatrix4< Type > *  result,
const TypedVector3< Type > &  eyePosition,
const TypedVector3< Type > &  targetPosition,
const TypedVector3< Type > &  unitUp 
)

Creates a transform Matrix from a forward vector and up vector, similar to creating a LookAt.

Parameters
resultThe matrix to fill out with the resulting LookAt matrix.
forwardThe direction the transform matrix will be pointing at, must be a unit vector of the direction.
upA unit vector representing the up vector, this is expected to be normalized / length of 1.0.
Note
this is implemented as a "LookAtRH" if "LookAtLH" is ever needed, it will be added at that time.

◆ MatrixCreateOrthoLH()

Matrix4* TurtleBrains::Math::MatrixCreateOrthoLH ( Matrix4 result,
const float  left,
const float  right,
const float  top,
const float  bottom,
const float  nearPlane,
const float  farPlane 
)
inline

Creates a right-handed orthographic matrix for 2D rendering given a few setup parameters. The Matrix will look something like the following once returned:

2 / (r - l), 0, 0, -(r + l) / (r - l), 0, 2 / (t - b), 0, -(t + b) / (t - b), 0, 0, 2 / (f - n), -(f + n) / (f - n), 0, 0, 0 1

Parameters
resultWhere to store the resulting matrix and return.
widthThe width of the screen/window/surface available for the 2D rendering.
heightThe height of the screen/window/surface available for the 2D rendering.
nearPlaneThe distance to the near plane of the orthographic matrix. (closest Z value).
farPlaneThe distance to the far plane of the orthographic matrix. (farthest Z value).

◆ MatrixCreateOrthoRH()

Matrix4* TurtleBrains::Math::MatrixCreateOrthoRH ( Matrix4 result,
const float  left,
const float  right,
const float  top,
const float  bottom,
const float  nearPlane,
const float  farPlane 
)
inline

Creates a right-handed orthographic matrix for 2D rendering given a few setup parameters. The Matrix will look something like the following once returned:

2 / (r - l), 0, 0, -(r + l) / (r - l), 0, 2 / (t - b), 0, -(t + b) / (t - b), 0, 0, -2 / (f - n), -(f + n) / (f - n), 0, 0, 0 1

Parameters
resultWhere to store the resulting matrix and return.
widthThe width of the screen/window/surface available for the 2D rendering.
heightThe height of the screen/window/surface available for the 2D rendering.
nearPlaneThe distance to the near plane of the orthographic matrix. (closest Z value).
farPlaneThe distance to the far plane of the orthographic matrix. (farthest Z value).

◆ MatrixCreatePerspectiveLH()

Matrix4* TurtleBrains::Math::MatrixCreatePerspectiveLH ( Matrix4 result,
const float  fieldOfView,
const float  aspectRatio,
const float  nearPlane,
const float  farPlane 
)
inline

Creates a left-handed projection matrix for 3D rendering given a few setup parameters.

Parameters
resultWhere to store the resulting matrix and return.
fieldOfViewThe angle (in radians) of the vertical field of vision for the projection matrix. To use horizontal field of view, just use verticalFOV / aspectRatio when calling.
aspectRatioThe aspect ratio of the window/screen or target render.
nearPlaneThe distance to the near plane of the projection matrix.
farPlaneThe distance to the far plane of the projection matrix.
Note
To use horizontal field of view, just use verticalFOV / aspectRatio when calling.

◆ MatrixCreatePerspectiveRH()

Matrix4* TurtleBrains::Math::MatrixCreatePerspectiveRH ( Matrix4 result,
const float  fieldOfView,
const float  aspectRatio,
const float  nearPlane,
const float  farPlane 
)
inline

Creates a right-handed projection matrix for 3D rendering given a few setup parameters.

Parameters
resultWhere to store the resulting matrix and return.
fieldOfViewThe angle (in radians) of the vertical field of vision for the projection matrix. To use horizontal field of view, just use verticalFOV / aspectRatio when calling.
aspectRatioThe aspect ratio of the window/screen or target render.
nearPlaneThe distance to the near plane of the projection matrix.
farPlaneThe distance to the far plane of the projection matrix.
Note
To use horizontal field of view, just use verticalFOV / aspectRatio when calling.

◆ MatrixCreateRotationA() [1/2]

template<typename Type >
TypedMatrix3< Type > * TurtleBrains::Math::MatrixCreateRotationA ( TypedMatrix3< Type > *  result,
const TypedVector3< Type > *  rotationAxis,
const tbMath::TypedAngle< Type >  rotation 
)

Creates a rotation transform Matrix object with no translation or scaling that will rotate around the specied rotationAxis by the amount specified by the rotation parameter.

Parameters
resultThe matrix to hold the result and be returned.
rotationAxisThe axis to rotate around, should be a unit vector, can be an arbitrary direction.
rotationInDegreesThe amount to rotate around the Z-axis in degrees.

◆ MatrixCreateRotationA() [2/2]

template<typename Type >
TypedMatrix4< Type > * TurtleBrains::Math::MatrixCreateRotationA ( TypedMatrix4< Type > *  result,
const TypedVector3< Type > *  rotationAxis,
const tbMath::TypedAngle< Type >  rotation 
)

Creates a rotation transform Matrix object with no translation or scaling that will rotate around the specied rotationAxis by the amount specified by the rotation parameter.

Parameters
resultThe matrix to hold the result and be returned.
rotationAxisThe axis to rotate around, should be a unit vector, can be an arbitrary direction.
rotationInDegreesThe amount to rotate around the Z-axis in degrees.

◆ MatrixCreateRotationX() [1/2]

template<typename Type >
TypedMatrix3< Type > * TurtleBrains::Math::MatrixCreateRotationX ( TypedMatrix3< Type > *  result,
const tbMath::TypedAngle< Type >  rotation 
)

Creates a rotation transform Matrix object with no translation or scaling that will rotate around the X-axis by the amount specified by the rotation parameter.

Parameters
resultThe matrix to hold the result and be returned.
rotationInDegreesThe amount to rotate around the X-axis in degrees.

◆ MatrixCreateRotationX() [2/2]

template<typename Type >
TypedMatrix4< Type > * TurtleBrains::Math::MatrixCreateRotationX ( TypedMatrix4< Type > *  result,
const tbMath::TypedAngle< Type >  rotation 
)

Creates a rotation transform Matrix object with no translation or scaling that will rotate around the X-axis by the amount specified by the rotation parameter.

Parameters
resultThe matrix to hold the result and be returned.
rotationInDegreesThe amount to rotate around the X-axis in degrees.

◆ MatrixCreateRotationY() [1/2]

template<typename Type >
TypedMatrix3< Type > * TurtleBrains::Math::MatrixCreateRotationY ( TypedMatrix3< Type > *  result,
const tbMath::TypedAngle< Type >  rotation 
)

Creates a rotation transform Matrix object with no translation or scaling that will rotate around the Y axis by the amount specified by the rotation parameter.

Parameters
resultThe matrix to hold the result and be returned.
rotationInDegreesThe amount to rotate around the Y-axis in degrees.

◆ MatrixCreateRotationY() [2/2]

template<typename Type >
TypedMatrix4< Type > * TurtleBrains::Math::MatrixCreateRotationY ( TypedMatrix4< Type > *  result,
const tbMath::TypedAngle< Type >  rotation 
)

Creates a rotation transform Matrix object with no translation or scaling that will rotate around the Y axis by the amount specified by the rotation parameter.

Parameters
resultThe matrix to hold the result and be returned.
rotationInDegreesThe amount to rotate around the Y-axis in degrees.

◆ MatrixCreateRotationZ() [1/2]

template<typename Type >
TypedMatrix3< Type > * TurtleBrains::Math::MatrixCreateRotationZ ( TypedMatrix3< Type > *  result,
const tbMath::TypedAngle< Type >  rotation 
)

Creates a rotation transform Matrix object with no translation or scaling that will rotate around the X-axis by the amount specified by the rotation parameter.

Parameters
resultThe matrix to hold the result and be returned.
rotationInDegreesThe amount to rotate around the Z-axis in degrees.

◆ MatrixCreateRotationZ() [2/2]

template<typename Type >
TypedMatrix4< Type > * TurtleBrains::Math::MatrixCreateRotationZ ( TypedMatrix4< Type > *  result,
const tbMath::TypedAngle< Type >  rotation 
)

Creates a rotation transform Matrix object with no translation or scaling that will rotate around the X-axis by the amount specified by the rotation parameter.

Parameters
resultThe matrix to hold the result and be returned.
rotationInDegreesThe amount to rotate around the Z-axis in degrees.

◆ MatrixCreateScale() [1/4]

template<typename Type >
TypedMatrix3< Type > * TurtleBrains::Math::MatrixCreateScale ( TypedMatrix3< Type > *  result,
const Type  scaleX,
const Type  scaleY,
const Type  scaleZ 
)

Creates a scale transform Matrix object with no translation or rotation set to the position specified by the x, y, z parameter values.

Parameters
resultThe matrix to hold the result and be returned.
scaleXThe amount of scaling for the transform matrix in the X-axis.
scaleYThe amount of scaling for the transform matrix in the Y-axis.
scaleZThe amount of scaling for the transform matrix in the Z-axis.

◆ MatrixCreateScale() [2/4]

template<typename Type >
TypedMatrix3< Type > * TurtleBrains::Math::MatrixCreateScale ( TypedMatrix3< Type > *  result,
const TypedVector3< Type > *  scale 
)

Creates a scale transform Matrix object with no translation or rotation set to the position specified by the Vector object.

Parameters
resultThe matrix to hold the result and be returned.
scaleThe amount of scaling of each axis represented by the vector components.

◆ MatrixCreateScale() [3/4]

template<typename Type >
TypedMatrix4< Type > * TurtleBrains::Math::MatrixCreateScale ( TypedMatrix4< Type > *  result,
const Type  scaleX,
const Type  scaleY,
const Type  scaleZ 
)

◆ MatrixCreateScale() [4/4]

template<typename Type >
TypedMatrix4< Type > * TurtleBrains::Math::MatrixCreateScale ( TypedMatrix4< Type > *  result,
const TypedVector3< Type > *  scale 
)

◆ MatrixCreateTranslation() [1/2]

template<typename Type >
TypedMatrix4< Type > * TurtleBrains::Math::MatrixCreateTranslation ( TypedMatrix4< Type > *  result,
const Type  translationX,
const Type  translationY,
const Type  translationZ 
)

Creates a translation transform Matrix object with no rotation set to the position specified by the x, y, z parameter values.

Parameters
resultThe matrix to hold the result and be returned.
translationXThe amount of translation to add to the transform matrix in the X-axis.
translationYThe amount of translation to add to the transform matrix in the Y-axis.
translationZThe amount of translation to add to the transform matrix in the Z-axis.

◆ MatrixCreateTranslation() [2/2]

template<typename Type >
TypedMatrix4< Type > * TurtleBrains::Math::MatrixCreateTranslation ( TypedMatrix4< Type > *  result,
const TypedVector3< Type > *  translation 
)

Creates a translation transform Matrix object with no rotation set to the position specified by the Vector.

Parameters
resultThe matrix to hold the result and be returned.
translationThe amount of translation to add in each axis represented by the vector components.

◆ MatrixDeterminant() [1/2]

template<typename Type >
Type TurtleBrains::Math::MatrixDeterminant ( const TypedMatrix3< Type > *  input)

Computes the determinant of the 3x3 matrix by breaking it down into 2x2 determinants and returns the resulting scalar determinant.

◆ MatrixDeterminant() [2/2]

template<typename Type >
Type TurtleBrains::Math::MatrixDeterminant ( const TypedMatrix4< Type > *  input)

Computes the determinant of the 4x4 matrix by breaking it down into 3x3 determinants and returns the resulting scalar determinant.

◆ MatrixFastInverse() [1/2]

template<typename Type >
TypedMatrix3< Type > * TurtleBrains::Math::MatrixFastInverse ( TypedMatrix3< Type > *  result,
const TypedMatrix3< Type > *  input 
)

Creates the inverse matrix for a special, ortho-normalized matrix by transposing the 3x3.

Parameters
resultThe matrix to store and return the computed inverse matrix of input. This cannot be the same matrix as the input matrix or an error condition will be triggered.
inputThe matrix to compute the inverse of, cannot be the same as the result matrix or an error condition will be triggered.

◆ MatrixFastInverse() [2/2]

template<typename Type >
TypedMatrix4< Type > * TurtleBrains::Math::MatrixFastInverse ( TypedMatrix4< Type > *  result,
const TypedMatrix4< Type > *  input 
)

Creates the inverse matrix for a special, ortho-normalized matrix by transposing the 3x3 in the top-left, negating the translation and multiplying it by that new 3x3 and keeping the diagonal equal.

A = [ M b ] [ 0 1 ] where, M is 3x3, b is 1x3, and bottom is 0, 0, 0, 1 inv(A) = [ inv(M) -inv(M) * b ] [ 0 1 ]

Parameters
resultThe matrix to store and return the computed inverse matrix of input. This cannot be the same matrix as the input matrix or an error condition will be triggered.
inputThe matrix to compute the inverse of, cannot be the same as the result matrix or an error condition will be triggered.

◆ MatrixMultiply() [1/4]

template<typename Type >
TypedMatrix3< Type > * TurtleBrains::Math::MatrixMultiply ( TypedMatrix3< Type > *  result,
const TypedMatrix3< Type > *  input,
const Type &  scalar 
)

Scales/multiplies each component of the matrix by the given scalar value.

Parameters
resultThe result matrix which will be the product of input * scalar when finished.
inputThe original matrix that should be scaled / multiplied with the scalar.
scalarHow much to multiply each component of the matrix by.

TODO: TurtleBrains: Math: This will need some simple unit testing, though really it is easy enough.

◆ MatrixMultiply() [2/4]

template<typename Type >
TypedMatrix3< Type > * TurtleBrains::Math::MatrixMultiply ( TypedMatrix3< Type > *  result,
const TypedMatrix3< Type > *  leftSide,
const TypedMatrix3< Type > *  rightSide 
)

Multiplies two matrices together and stores the resulting matrix to be returned.

Parameters
resultThe result matrix which will be the product of leftSide * rightSide when finished. This matrix cannot be the same as leftSide or rightSide or an error condition will be triggered.
leftSideThe matrix on the left side of the multiplication operation. This cannot be the same as the result matrix or an error condition will be triggered.
rightSideThe matrix on the right side of the multiplication operation. This cannot be the same as the result matrix or an error condition will be trtiggered.

◆ MatrixMultiply() [3/4]

template<typename Type >
TypedMatrix4< Type > * TurtleBrains::Math::MatrixMultiply ( TypedMatrix4< Type > *  result,
const TypedMatrix4< Type > *  input,
const Type &  scalar 
)

Scales/multiplies each component of the matrix by the given scalar value.

Parameters
resultThe result matrix which will be the product of input * scalar when finished.
inputThe original matrix that should be scaled / multiplied with the scalar.
scalarHow much to multiply each component of the matrix by.

TODO: TurtleBrains: Math: This will need some simple unit testing, though really it is easy enough.

◆ MatrixMultiply() [4/4]

template<typename Type >
TypedMatrix4< Type > * TurtleBrains::Math::MatrixMultiply ( TypedMatrix4< Type > *  result,
const TypedMatrix4< Type > *  leftSide,
const TypedMatrix4< Type > *  rightSide 
)

◆ MatrixSubtract() [1/2]

Matrix3* TurtleBrains::Math::MatrixSubtract ( Matrix3 result,
const Matrix3 leftSide,
const Matrix3 rightSide 
)
inline

Subtracts rightSide matrix from the leftSide matrix and stores the result into result before returning.

Parameters
resultThe matrix to fill out and return with the result of: leftSide - rightSide.
leftSideThe matrix on the left side of the subtration operator.
rightSideThe matrix on the right side of the subtraction operator.

◆ MatrixSubtract() [2/2]

Matrix4* TurtleBrains::Math::MatrixSubtract ( Matrix4 result,
const Matrix4 leftSide,
const Matrix4 rightSide 
)
inline

Subtracts rightSide matrix from the leftSide matrix and stores the result into result before returning.

Parameters
resultThe matrix to fill out and return with the result of: leftSide - rightSide.
leftSideThe matrix on the left side of the subtration operator.
rightSideThe matrix on the right side of the subtraction operator.

◆ MatrixTranspose() [1/2]

Matrix3* TurtleBrains::Math::MatrixTranspose ( Matrix3 result,
const Matrix3 input 
)
inline

Fills the compoments of result Matrix3 object so it would be the transposed of the input Matrix.

Parameters
resultThe resulting matrix of the transposed operation on input, cannot be the same as the input matrix.
inputThe matrix to get the transposed result of, cannot be the same as the result matrix.

◆ MatrixTranspose() [2/2]

Matrix4* TurtleBrains::Math::MatrixTranspose ( Matrix4 result,
const Matrix4 input 
)
inline

Fills the compoments of result Matrix4 object so it would be the transposed of the input Matrix.

Parameters
resultThe resulting matrix of the transposed operation on input, cannot be the same as the input matrix.
inputThe matrix to get the transposed result of, cannot be the same as the result matrix.

◆ MatrixVector3Multiply()

template<typename Type >
TypedVector3< Type > * TurtleBrains::Math::MatrixVector3Multiply ( TypedVector3< Type > *  result,
const TypedMatrix3< Type > *  inputMatrix,
const TypedVector3< Type > *  inputVector 
)

Multiplies a matrix and a vector together treating the vector as a 3(row) 1(column) matrix.

Parameters
resultThe vector to hold the result of the transformed inputVector), must be a different vector object or an error condition will be triggered.
inputVectorThe vector to transform by the input matrix, must not be the same as result.
inputMatrixThe transform matrix to multiply inputVector by.
Note
this is post-multiplication, treating the vector as a matrix with 3 rows and 1 column. This is like matrix * vector.

◆ MatrixVector4Multiply()

template<typename Type >
TypedVector4< Type > * TurtleBrains::Math::MatrixVector4Multiply ( TypedVector4< Type > *  result,
const TypedMatrix4< Type > *  inputMatrix,
const TypedVector4< Type > *  inputVector 
)

Multiplies a matrix and a vector together treating the vector as a 4(row) 1(column) matrix.

Parameters
resultThe vector to hold the result of the transformed inputVector), must be a different vector object or an error condition will be triggered.
inputVectorThe vector to transform by the input matrix), must not be the same as result.
inputMatrixThe transform matrix to multiply inputVector by.
Note
this is post-multiplication, treating the vector as a matrix with 4 rows and 1 column. This is like matrix * vector.

◆ Maximum()

template<typename Type >
constexpr const Type& TurtleBrains::Math::Maximum ( const Type &  leftValue,
const Type &  rightValue 
)
constexprnoexcept

Compares the value of two similar types using the less-than operator returning the greater of the values.

Parameters
leftValueThe value that would be on the left side of the comparison operator.
rightValueThe value that would be on the right side of the comparison operator.
Note
There will be compile issues if called on a type that does not have an operator< to use.

◆ Minimum()

template<typename Type >
constexpr const Type& TurtleBrains::Math::Minimum ( const Type &  leftValue,
const Type &  rightValue 
)
constexprnoexcept

Compares the value of two similar types using the less-than operator returning the lesser of the values.

Parameters
leftValueThe value that would be on the left side of the comparison operator.
rightValueThe value that would be on the right side of the comparison operator.
Note
There will be compile issues if called on a type that does not have an operator< to use.

◆ operator<<() [1/2]

template<typename Type >
std::ostream& TurtleBrains::Math::operator<< ( std::ostream &  output,
const tbMath::TypedAngle< Type > &  angle 
)

Stream operator for logging an angle, as of 2023-11-28 written will always log in degrees.

◆ operator<<() [2/2]

template<typename Type >
std::ostream& TurtleBrains::Math::operator<< ( std::ostream &  output,
const tbMath::TypedVector2< Type > &  data 
)

I remember doing this about 300 times and then removing it, so, here we go again!

◆ QuaternionAdd()

template<typename Type >
TypedQuaternion<Type>* TurtleBrains::Math::QuaternionAdd ( TypedQuaternion< Type > *  result,
const TypedQuaternion< Type > *  left,
const TypedQuaternion< Type > *  right 
)

Add two the components of one TypedQuaternion to another TypedQuaternion and returns the resulting TypedQuaternion. Behavior is the same as TypedQuaternion::operator+ though no temporary is created in the process.

Parameters
resultis the result of leftSide + rightSide.
leftSideThe TypedQuaternion object to take the left hand side of the addition operation.
rightSideThe TypedQuaternion object to take the right hand side of the addition operation.
Note
None of the inputs can be null.

◆ QuaternionInverse()

template<typename Type >
TypedQuaternion<Type>* TurtleBrains::Math::QuaternionInverse ( TypedQuaternion< Type > *  result,
const TypedQuaternion< Type > *  input 
)

Inverses the quaternion, by negating the necessary components to do so and returns the resulting TypedQuaternion.

Parameters
resultThe result of the inverse quaternion.
inputThe TypedQuaternion object to inverse.
Note
None of the inputs can be null.

◆ QuaternionMagnitude()

template<typename Type >
Type TurtleBrains::Math::QuaternionMagnitude ( const TypedQuaternion< Type > *  input)

Computes the length / magnitude of the TypedQuaternion object and returns the result.

◆ QuaternionMagnitudeSquared()

template<typename Type >
Type TurtleBrains::Math::QuaternionMagnitudeSquared ( const TypedQuaternion< Type > *  input)

Computes the length / magnitude of the TypedQuaternion object left squared so the square root is not taken, then returns the resulting scalar value.

◆ QuaternionMultiply()

template<typename Type >
TypedQuaternion< Type > * TurtleBrains::Math::QuaternionMultiply ( TypedQuaternion< Type > *  result,
const TypedQuaternion< Type > *  left,
const TypedQuaternion< Type > *  right 
)

Multiples two Quaternions together and returns the resulting TypedQuaternion.

Parameters
resultis the result of leftSide * rightSide.
leftSideThe TypedQuaternion object to take the left hand side of the multiplication operation.
rightSideThe TypedQuaternion object to take the right hand side of the multiplication operation.
Note
None of the inputs can be null.

◆ QuaternionNegate()

template<typename Type >
TypedQuaternion<Type>* TurtleBrains::Math::QuaternionNegate ( TypedQuaternion< Type > *  result,
const TypedQuaternion< Type > *  input 
)

Negates each of the components of a TypedQuaternion and returns the resulting TypedQuaternion. This is the same as operator-(void) except it doesn't create the temporary.

Parameters
resultThe result of negating each component in input.
inputThe Vector object to negate.
Note
None of the inputs can be null.

◆ QuaternionNormalize()

template<typename Type >
TypedQuaternion<Type>* TurtleBrains::Math::QuaternionNormalize ( TypedQuaternion< Type > *  result,
const TypedQuaternion< Type > *  input 
)

Calculates the unit-length Quaternion of the input Quaternion and returns the resulting unit-Quaternion.

Parameters
inputThe TypedQuaternion object to get the unit-length of.
resultThe unit length TypedQuaternion from the input, or a Identity TypedQuaternion if the input had no length.
Note
The input and result Quaternions cannot be null.

◆ QuaternionNormalizeMagnitude()

template<typename Type >
TypedQuaternion<Type>* TurtleBrains::Math::QuaternionNormalizeMagnitude ( TypedQuaternion< Type > *  result,
const TypedQuaternion< Type > *  input,
Type &  magnitude 
)

Calculates the unit-length TypedQuaternion of the input TypedQuaternion and returns the resulting unit-TypedQuaternion and to save computing the magnitude elsewhere, this will return the value in the magnitudee parameter.

Parameters
inputThe TypedQuaternion object to get the unit-length of.
resultThe unit length TypedQuaternion from the input, or a Identity TypedQuaternion if the input had no length.
magnitudeThe length of the input TypedQuaternion as it must be computed to normalize anyway.
Note
The input and result Quaternions cannot be null.

◆ QuaternionScale()

template<typename Type >
TypedQuaternion<Type>* TurtleBrains::Math::QuaternionScale ( TypedQuaternion< Type > *  result,
const TypedQuaternion< Type > *  input,
const Type  scalar 
)

Multiples a TypedQuaternion together with a scalar and returns the resulting TypedQuaternion.

Parameters
resultis the result of leftSide * rightSide.
inputThe TypedQuaternion object to take the left hand side of the multiplication operation.
scalarThe amount to scale the input Vector by. 2.0f would double the Vectors magnitude.
Note
None of the inputs can be null.

◆ QuaternionScaleDivide()

template<typename Type >
TypedQuaternion<Type>* TurtleBrains::Math::QuaternionScaleDivide ( TypedQuaternion< Type > *  result,
const TypedQuaternion< Type > *  input,
const Type  scalar 
)

Divides the components of one TypedQuaternion by the scalar and returns the resulting TypedQuaternion.

Parameters
resultThe result of input / scalar.
inputThe TypedQuaternion object to divide components by the scalar value.
scalarThe amount to inverse scale the input TypedQuaternion by. 2.0f would half the TypedQuaternion magnitude.
Note
None of the inputs can be null.

◆ QuaternionSubtract()

template<typename Type >
TypedQuaternion<Type>* TurtleBrains::Math::QuaternionSubtract ( TypedQuaternion< Type > *  result,
const TypedQuaternion< Type > *  left,
const TypedQuaternion< Type > *  right 
)

Subtracts the components of one TypedQuaternion from the other TypedQuaternion and returns the resulting TypedQuaternion. Behavior is the same as TypedQuaternion::operator- though no temporary is created in the process.

Parameters
resultis the result of leftSide - rightSide.
leftSideThe TypedQuaternion object to take the left hand side of the subtraction operation.
rightSideThe TypedQuaternion object to take the right hand side of the subtraction operation.
Note
None of the inputs can be null.

◆ RandomFloat() [1/2]

float TurtleBrains::Math::RandomFloat ( const float  minimumValue,
const float  maximumValue 
)

Returns a random float value between minimumValue and maximumValue inclusively.

Parameters
minimumValueThe smallest possible random value desired, must be less than maximumValue.
maximumValueThe largest possible random value desired, must be greater than minimumValue.
Note
This will trigger an error condition if minimumValue is not less than the maximumValue.

◆ RandomFloat() [2/2]

float TurtleBrains::Math::RandomFloat ( void  )

Create a random float in the range of: 0.0f <= value <= 1.0f

◆ RandomInt() [1/2]

int TurtleBrains::Math::RandomInt ( const int  minimumValue,
const int  maximumValue 
)

Returns a random integer between minimumValue and maximumValue inclusively.

Parameters
minimumValueThe smallest possible random value desired, must be less than maximumValue.
maximumValueThe largest possible random value desired, must be greater than minimumValue.
Note
This will trigger an error condition if minimumValue is not less than the maximumValue.

◆ RandomInt() [2/2]

int TurtleBrains::Math::RandomInt ( void  )

Returns a random integer between 0 and RAND_MAX by returning rand(), a better random-number generator may be used in future versions of TurtleBrains.

◆ RotationToForwardVector2()

static Vector2& TurtleBrains::Math::RotationToForwardVector2 ( Vector2 result,
const Angle orientation 
)
inlinestatic

Converts an orientation value from 2D into a forward vector. Orientation should be in radians, positive for clockwise rotation around the Z axis, 0 pointing along the -Y axis.

◆ RotationXZToForwardVector3()

static Vector3& TurtleBrains::Math::RotationXZToForwardVector3 ( Vector3 result,
const Angle orientation 
)
inlinestatic

Converts an orientation value from 2D (XZ plane) into a forward vector X, 0, Z. Orientation should be in radians, positive for clockwise rotation around the Y axis, 0 pointing along the -Z axis.

◆ SeedRandomGenerator() [1/3]

unsigned int TurtleBrains::Math::SeedRandomGenerator ( const String &  seed)

Generates a seed using the hash of the string passed as parameter seed, then proceeds seed the the random generator, finally return the value as an unsigned int.

Parameters
seedA string, usually shortish, to hash into an unsigned int which will be the generated seed.

◆ SeedRandomGenerator() [2/3]

void TurtleBrains::Math::SeedRandomGenerator ( unsigned int  seed)

Starts the random generator with a specific seed.

◆ SeedRandomGenerator() [3/3]

unsigned int TurtleBrains::Math::SeedRandomGenerator ( void  )

Generates a seed using time() and seeds the random generator, returning the seed used.

◆ Sign()

template<typename Type >
Type TurtleBrains::Math::Sign ( const Type &  value)
noexcept

Returns -1, 0 or 1 depending on the sign or value given.

◆ Vector2Add()

Vector2* TurtleBrains::Math::Vector2Add ( Vector2 result,
const Vector2 leftSide,
const Vector2 rightSide 
)
inline

Add two the components of one Vector to another Vector and return the resulting Vector. Behavior is the same as Vector::operator+

Parameters
resultis the result of leftSide + rightSide.
leftSideThe Vector object to take the left hand side of the addition operation.
rightSideThe Vector object to take the right hand side of the addition operation.
Note
None of the inputs can be null.

◆ Vector2DotProduct()

template<typename Type >
Type TurtleBrains::Math::Vector2DotProduct ( const TypedVector2< Type > *  leftSide,
const TypedVector2< Type > *  rightSide 
)

Performs the DotProduct on two Vector objects returning resulting scalar value.

Parameters
leftSideThe Vector object to take the left hand side of the dot product operation.
rightSideThe Vector object to take the right hand side of the dot product operation.
Note
None of the inputs can be null.

◆ Vector2Magnitude()

template<typename Type >
Type TurtleBrains::Math::Vector2Magnitude ( const TypedVector2< Type > *  input)

Computes the length (magnitude) of a Vector object returning resulting scalar value.

Parameters
inputThe Vector object to compute the length of.
Note
The input vector cannot be null.

◆ Vector2MagnitudeSquared()

template<typename Type >
Type TurtleBrains::Math::Vector2MagnitudeSquared ( const TypedVector2< Type > *  input)

Computes the length (magnitude) of a Vector object without performing the square-root, so the resulting scalar is actually the squared length of the Vector.

Parameters
inputThe Vector object to get the squared length of.
Note
The input vector cannot be null.

◆ Vector2Negate()

Vector2* TurtleBrains::Math::Vector2Negate ( Vector2 result,
const Vector2 input 
)
inline

Negates each of the components of a Vector and returns the resulting Vector.

Parameters
resultThe result of negating each component in input.
inputThe Vector object to negate.
Note
None of the inputs can be null.

◆ Vector2Normalize()

template<typename Type >
TypedVector2< Type > * TurtleBrains::Math::Vector2Normalize ( TypedVector2< Type > *  result,
const TypedVector2< Type > *  input 
)

Calculates the unit-length vector of the input Vector and returns the resulting Vector.

Parameters
resultThe unit length vector from the input, or a zero vector if the input had no length.
inputThe Vector object to get the unit-length of.
Note
The input vector cannot be null.

◆ Vector2NormalizeMagnitude()

template<typename Type >
TypedVector2< Type > * TurtleBrains::Math::Vector2NormalizeMagnitude ( TypedVector2< Type > *  result,
const TypedVector2< Type > *  input,
Type &  magnitude 
)

Calculates the unit-length vector of the input Vector and returns the resulting Vector and to save computing the magnitude elsewhere, this will return the value in the magnitude parameter.

Parameters
resultThe unit length vector from the input, or a zero vector if the input had no length.
inputThe Vector object to get the unit-length of.
magnitudeThe length of the input vector as it must be computed.
Note
The input vector cannot be null.

◆ Vector2Scale()

Vector2* TurtleBrains::Math::Vector2Scale ( Vector2 result,
const Vector2 input,
const float  scalar 
)
inline

Scales the components of one Vector and returns the resulting Vector.

Parameters
resultThe result of input * scalar.
inputThe Vector object to scale by the scalar value.
scalarThe amount to scale the input Vector by. 2.0f would double the Vectors magnitude.
Note
None of the inputs can be null.

◆ Vector2ScaleDivide()

Vector2* TurtleBrains::Math::Vector2ScaleDivide ( Vector2 result,
const Vector2 input,
const float  scalar 
)
inline

Divides the components of one Vector by the scalar and returns the resulting Vector.

Parameters
resultThe result of input * scalar.
inputThe Vector object to scale by the scalar value.
scalarThe amount to inverse scale the input Vector by. 2.0f would half the Vectors magnitude.
Note
None of the inputs can be null.

◆ Vector2Subtract()

Vector2* TurtleBrains::Math::Vector2Subtract ( Vector2 result,
const Vector2 leftSide,
const Vector2 rightSide 
)
inline

Subtracts the components of one Vector from another Vector and returns the resulting Vector. Behavior is the same as using Vector::operator-

Parameters
resultis the result of leftSide - rightSide.
leftSideThe Vector object to take the left hand side of the subtraction operation.
rightSideThe Vector object to take the right hand side of the subtraction operation.
Note
None of the inputs can be null.

◆ Vector3Add()

Vector3* TurtleBrains::Math::Vector3Add ( Vector3 result,
const Vector3 leftSide,
const Vector3 rightSide 
)
inline

Add two the components of one Vector to another Vector and return the resulting Vector. Behavior is the same as Vector::operator+

Parameters
resultis the result of leftSide + rightSide.
leftSideThe Vector object to take the left hand side of the addition operation.
rightSideThe Vector object to take the right hand side of the addition operation.
Note
None of the inputs can be null.

◆ Vector3AngleBetween()

template<typename Type >
TypedAngle<Type> TurtleBrains::Math::Vector3AngleBetween ( const TypedVector3< Type > *  left,
const TypedVector3< Type > *  right 
)

Returns angle between vectors in radians, 0 is both pointing same direction, kPi if both vectors are pointing in opposite directions.

◆ Vector3CrossProduct()

template<typename Type >
TypedVector3< Type > * TurtleBrains::Math::Vector3CrossProduct ( TypedVector3< Type > *  result,
const TypedVector3< Type > *  leftSide,
const TypedVector3< Type > *  rightSide 
)

Computes the CrossProduct of two Vector objects. The resulting Vector will be perpendicular to the input vectors, or become a zero vector if those are parallel. Assuming a right hand coordinate system, X cross Y will result in Z while Y cross X would be -Z. An easy way to get the axis you want is to write xyzxyz, then find the axis you want (ex: Want Y, Y = Z cross X). Again this works for a right handed system because x cross y will be a positive z.

Parameters
resultThe result of leftSide cross rightSide, also performed with operator^
leftSideThe Vector object to take the left hand side of the cross product operation.
rightSideThe Vector object to take the right hand side of the cross product operation.
Note
None of the input parameters can be null, and result must be different than leftSide and rightSide.

◆ Vector3DotProduct()

template<typename Type >
Type TurtleBrains::Math::Vector3DotProduct ( const TypedVector3< Type > *  leftSide,
const TypedVector3< Type > *  rightSide 
)

Performs the DotProduct on two Vector objects returning resulting scalar value.

Parameters
leftSideThe Vector object to take the left hand side of the dot product operation.
rightSideThe Vector object to take the right hand side of the dot product operation.
Note
None of the inputs can be null.

◆ Vector3Magnitude()

template<typename Type >
Type TurtleBrains::Math::Vector3Magnitude ( const TypedVector3< Type > *  input)

Computes the length (magnitude) of a Vector object returning resulting scalar value.

Parameters
inputThe Vector object to compute the length of.
Note
The input vector cannot be null.

◆ Vector3MagnitudeSquared()

template<typename Type >
Type TurtleBrains::Math::Vector3MagnitudeSquared ( const TypedVector3< Type > *  input)

Computes the length (magnitude) of a Vector object without performing the square-root, so the resulting scalar is actually the squared length of the Vector.

Parameters
inputThe Vector object to get the squared length of.
Note
The input vector cannot be null.

◆ Vector3MatrixMultiply()

template<typename Type >
TypedVector3< Type > * TurtleBrains::Math::Vector3MatrixMultiply ( TypedVector3< Type > *  result,
const TypedVector3< Type > *  inputVector,
const TypedMatrix3< Type > *  inputMatrix 
)

Multiplies a vector and a matrix together treating the vector as a 3(row) 1(column) matrix.

Parameters
resultThe vector to hold the result of the transformed inputVector), must be a different vector object or an error condition will be triggered.
inputVectorThe vector to transform by the input matrix), must not be the same as result.
inputMatrixThe transform matrix to multiply inputVector by.
Note
this is pre multiplication, treating the vector as a matrix with 1 row and 3 columns. This is like vector * matrix.

◆ Vector3Negate()

Vector3* TurtleBrains::Math::Vector3Negate ( Vector3 result,
const Vector3 input 
)
inline

Negates each of the components of a Vector and returns the resulting Vector.

Parameters
resultThe result of negating each component in input.
inputThe Vector object to negate.
Note
None of the inputs can be null.

◆ Vector3Normalize()

template<typename Type >
TypedVector3< Type > * TurtleBrains::Math::Vector3Normalize ( TypedVector3< Type > *  result,
const TypedVector3< Type > *  input 
)

Calculates the unit-length vector of the input Vector and returns the resulting Vector.

Parameters
resultThe unit length vector from the input, or a zero vector if the input had no length.
inputThe Vector object to get the unit-length of.
Note
The input vector cannot be null.

◆ Vector3NormalizeMagnitude()

template<typename Type >
TypedVector3< Type > * TurtleBrains::Math::Vector3NormalizeMagnitude ( TypedVector3< Type > *  result,
const TypedVector3< Type > *  input,
Type &  magnitude 
)

Calculates the unit-length vector of the input Vector and returns the resulting Vector and to save computing the magnitude elsewhere, this will return the value in the magnitude parameter.

Parameters
resultThe unit length vector from the input, or a zero vector if the input had no length.
inputThe Vector object to get the unit-length of.
magnitudeThe length of the input vector as it must be computed.
Note
The input vector cannot be null.

◆ Vector3Scale()

Vector3* TurtleBrains::Math::Vector3Scale ( Vector3 result,
const Vector3 input,
const float  scalar 
)
inline

Scales the components of one Vector and returns the resulting Vector.

Parameters
resultThe result of input * scalar.
inputThe Vector object to scale by the scalar value.
scalarThe amount to scale the input Vector by. 2.0f would double the Vectors magnitude.
Note
None of the inputs can be null.

◆ Vector3ScaleDivide()

Vector3* TurtleBrains::Math::Vector3ScaleDivide ( Vector3 result,
const Vector3 input,
const float  scalar 
)
inline

Divides the components of one Vector by the scalar and returns the resulting Vector.

Parameters
resultThe result of input * scalar.
inputThe Vector object to scale by the scalar value.
scalarThe amount to inverse scale the input Vector by. 2.0f would half the Vectors magnitude.
Note
None of the inputs can be null.

◆ Vector3Subtract()

Vector3* TurtleBrains::Math::Vector3Subtract ( Vector3 result,
const Vector3 leftSide,
const Vector3 rightSide 
)
inline

Subtracts the components of one Vector from another Vector and returns the resulting Vector. Behavior is the same as using Vector::operator-

Parameters
resultis the result of leftSide - rightSide.
leftSideThe Vector object to take the left hand side of the subtraction operation.
rightSideThe Vector object to take the right hand side of the subtraction operation.
Note
None of the inputs can be null.

◆ Vector3TransformCoordinate()

template<typename Type >
TypedVector3< Type > * TurtleBrains::Math::Vector3TransformCoordinate ( TypedVector3< Type > *  result,
const TypedVector3< Type > *  inputVector,
const TypedMatrix4< Type > *  inputMatrix 
)

Multiplies a vector and matrix together to transform the inputVector into the space described by the inputMatrix storing and returning the result. This behaves identical to Vector4MatrixMultiply except with Vector3, 1.0f and it can reduce that final round of multiplications.

lower confidence, needs more testing, but this would be the expected way things should work here... With a matrix transform from objectToWorld, the inputVector should be in object space and this function will transform it into world space.

Parameters
resultThe vector to hold the result of the transformed inputVector, must be a different vector object or an error condition will be triggered.
inputVectorThe vector to transform by the input matrix, must not be the same as result.
inputMatrixThe transform matrix to multiply inputVector by.

◆ Vector3TransformNormal()

template<typename Type >
TypedVector3< Type > * TurtleBrains::Math::Vector3TransformNormal ( TypedVector3< Type > *  result,
const TypedVector3< Type > *  inputVector,
const TypedMatrix4< Type > *  inputMatrix 
)

Multiplies a vector and matrix together to transform the inputVector into the space described by the inputMatrix storing and returning the result. This behaves identical to Vector4MatrixMultiply except with Vector3, 0.0f and it can reduces that final round of adding and the multiplications. It differs from TransformCoordinate by not applying the translation, useful for directions/normals.

Parameters
resultThe vector to hold the result of the transformed inputVector, must be a different vector object or an error condition will be triggered.
inputVectorThe vector to transform by the input matrix, must not be the same as result.
inputMatrixThe transform matrix to multiply inputVector by.

◆ Vector4Add()

Vector4* TurtleBrains::Math::Vector4Add ( Vector4 result,
const Vector4 leftSide,
const Vector4 rightSide 
)
inline

Add two the components of one Vector to another Vector and return the resulting Vector. Behavior is the same as Vector::operator+

Parameters
resultis the result of leftSide + rightSide.
leftSideThe Vector object to take the left hand side of the addition operation.
rightSideThe Vector object to take the right hand side of the addition operation.
Note
None of the inputs can be null.

◆ Vector4DotProduct()

template<typename Type >
Type TurtleBrains::Math::Vector4DotProduct ( const TypedVector4< Type > *  leftSide,
const TypedVector4< Type > *  rightSide 
)

Performs the DotProduct on two Vector objects returning resulting scalar value.

Parameters
leftSideThe Vector object to take the left hand side of the dot product operation.
rightSideThe Vector object to take the right hand side of the dot product operation.
Note
None of the inputs can be null.

◆ Vector4Magnitude()

template<typename Type >
Type TurtleBrains::Math::Vector4Magnitude ( const TypedVector4< Type > *  input)

Computes the length (magnitude) of a Vector object returning resulting scalar value.

Parameters
inputThe Vector object to compute the length of.
Note
The input vector cannot be null.

◆ Vector4MagnitudeSquared()

template<typename Type >
Type TurtleBrains::Math::Vector4MagnitudeSquared ( const TypedVector4< Type > *  input)

Computes the length (magnitude) of a Vector object without performing the square-root, so the resulting scalar is actually the squared length of the Vector.

Parameters
inputThe Vector object to get the squared length of.
Note
The input vector cannot be null.

◆ Vector4MatrixMultiply()

template<typename Type >
TypedVector4< Type > * TurtleBrains::Math::Vector4MatrixMultiply ( TypedVector4< Type > *  result,
const TypedVector4< Type > *  inputVector,
const TypedMatrix4< Type > *  inputMatrix 
)

Multiplies a vector and a matrix together treating the vector as a 4(row) 1(column) matrix.

Parameters
resultThe vector to hold the result of the transformed inputVector), must be a different vector object or an error condition will be triggered.
inputVectorThe vector to transform by the input matrix), must not be the same as result.
inputMatrixThe transform matrix to multiply inputVector by.
Note
this is pre multiplication, treating the vector as a matrix with 1 row and 4 columns. This is like vector * matrix.

◆ Vector4Negate()

Vector4* TurtleBrains::Math::Vector4Negate ( Vector4 result,
const Vector4 input 
)
inline

Negates each of the components of a Vector and returns the resulting Vector.

Parameters
resultThe result of negating each component in input.
inputThe Vector object to negate.
Note
None of the inputs can be null.

◆ Vector4Normalize()

template<typename Type >
TypedVector4< Type > * TurtleBrains::Math::Vector4Normalize ( TypedVector4< Type > *  result,
const TypedVector4< Type > *  input 
)

Calculates the unit-length vector of the input Vector and returns the resulting Vector.

Parameters
resultThe unit length vector from the input, or a zero vector if the input had no length.
inputThe Vector object to get the unit-length of.
Note
The input vector cannot be null.

◆ Vector4NormalizeMagnitude()

template<typename Type >
TypedVector4< Type > * TurtleBrains::Math::Vector4NormalizeMagnitude ( TypedVector4< Type > *  result,
const TypedVector4< Type > *  input,
Type &  magnitude 
)

Calculates the unit-length vector of the input Vector and returns the resulting Vector and to save computing the magnitude elsewhere, this will return the value in the magnitude parameter.

Parameters
resultThe unit length vector from the input, or a zero vector if the input had no length.
inputThe Vector object to get the unit-length of.
magnitudeThe length of the input vector as it must be computed.
Note
The input vector cannot be null.

◆ Vector4Scale()

Vector4* TurtleBrains::Math::Vector4Scale ( Vector4 result,
const Vector4 input,
const float  scalar 
)
inline

Scales the components of one Vector and returns the resulting Vector.

Parameters
resultThe result of input * scalar.
inputThe Vector object to scale by the scalar value.
scalarThe amount to scale the input Vector by. 2.0f would double the Vectors magnitude.
Note
None of the inputs can be null.

◆ Vector4ScaleDivide()

Vector4* TurtleBrains::Math::Vector4ScaleDivide ( Vector4 result,
const Vector4 input,
const float  scalar 
)
inline

Divides the components of one Vector by the scalar and returns the resulting Vector.

Parameters
resultThe result of input * scalar.
inputThe Vector object to scale by the scalar value.
scalarThe amount to inverse scale the input Vector by. 2.0f would half the Vectors magnitude.
Note
None of the inputs can be null.

◆ Vector4Subtract()

Vector4* TurtleBrains::Math::Vector4Subtract ( Vector4 result,
const Vector4 leftSide,
const Vector4 rightSide 
)
inline

Subtracts the components of one Vector from another Vector and returns the resulting Vector. Behavior is the same as using Vector::operator-

Parameters
resultis the result of leftSide - rightSide.
leftSideThe Vector object to take the left hand side of the subtraction operation.
rightSideThe Vector object to take the right hand side of the subtraction operation.
Note
None of the inputs can be null.