persona-3-dual
A DS demake of Persona 3
Loading...
Searching...
No Matches
MathManager Class Reference

#include <MathManager.hpp>

Inheritance diagram for MathManager:
Collaboration diagram for MathManager:

Public Types

enum class  EaseMode {
  Linear , InQuad , OutQuad , InOutQuad ,
  InCubic , OutCubic , InBack , OutBack
}
 Easing curves for fixed-point interpolation (t in [0, 1]). More...

Public Member Functions

void init () override
void process () override
void shutdown () override
ae::q20_12_t atan2 (ae::q20_12_t y, ae::q20_12_t x)
 Computes the angle (in radians) between the positive x-axis and (x, y).
ae::q20_12_t atan (ae::q20_12_t y)
 Computes the arctangent of a single ratio.
ae::q20_12_t div (ae::q20_12_t num, ae::q20_12_t den)
 Divides two Q20.12 values.
ae::q20_12_t sqrt (ae::q20_12_t v)
 Computes the square root of a Q20.12 value.
ae::q20_12_t mod (ae::q20_12_t num, ae::q20_12_t den)
 Computes the modulo of two Q20.12 values.
ae::angle16_t radiansToAngle (ae::q20_12_t radians)
 Converts an angle in radians (Q20.12).
ae::angle16_t degreesToCyclicAngle (ae::q20_12_t degrees)
 Converts an angle in degrees (Q20.12) to a cyclic angle.
ae::q20_12_t angleToRadians (ae::angle16_t angle)
 Converts a cyclic angle to radians (Q20.12).
ae::q4_12_t sin (ae::angle16_t angle)
 Sine of a cyclic angle.
ae::q4_12_t sin (ae::q20_12_t radians)
 Sine, accepting radians (Q20.12).
ae::q4_12_t cos (ae::angle16_t angle)
 Cosine of a cyclic angle.
ae::q4_12_t cos (ae::q20_12_t radians)
 Cosine, accepting radians (Q20.12).
ae::q20_12_t tan (ae::q20_12_t radians)
 Tangent, accepting radians (Q20.12).
ae::angle16_t asin (ae::q4_12_t ratio)
 Computes the arcsine of a ratio.
ae::angle16_t acos (ae::q4_12_t ratio)
 Computes the arccosine of a ratio.
ae::q20_12_t dot (ae::q20_12_t x1, ae::q20_12_t y1, ae::q20_12_t z1, ae::q20_12_t x2, ae::q20_12_t y2, ae::q20_12_t z2)
 Computes the dot product of two Q20.12 3D vectors.
ae::q20_12_t lengthSq (ae::q20_12_t x, ae::q20_12_t y, ae::q20_12_t z)
 Computes the squared length of a Q20.12 3D vector.
ae::q20_12_t length (ae::q20_12_t x, ae::q20_12_t y, ae::q20_12_t z)
 Computes the length of a Q20.12 3D vector.
void normalize (ae::q20_12_t &x, ae::q20_12_t &y, ae::q20_12_t &z)
 Normalizes a Q20.12 3D vector in place.
u32 secondsToSamples (ae::q20_12_t seconds, u32 sampleRate)
 Converts a Q20.12 seconds value to a sample count, avoiding overflow when seconds * sampleRate exceeds Q20.12's integer range.
ae::q20_12_t randFrac ()
 Returns a uniformly distributed random fraction from 0 to 1.
ae::q20_12_t lerp (ae::q20_12_t a, ae::q20_12_t b, ae::q20_12_t t)
 Linearly interpolates two Q20.12 values.
int lerp (int a, int b, ae::q20_12_t t)
 Linearly interpolates two integers with a fixed-point blend factor.
ae::q20_12_t ease (EaseMode mode, ae::q20_12_t t)
 Applies an easing curve to a normalized time value.
ae::q20_12_t clamp (ae::q20_12_t v, ae::q20_12_t lo, ae::q20_12_t hi)
 Clamps a Q20.12 value to [lo, hi].

Private Member Functions

 MathManager ()=default

Friends

class Singleton< MathManager >

Detailed Description

Definition at line 16 of file MathManager.hpp.

Member Enumeration Documentation

◆ EaseMode

enum class MathManager::EaseMode
strong

Easing curves for fixed-point interpolation (t in [0, 1]).

Enumerator
Linear 
InQuad 
OutQuad 
InOutQuad 
InCubic 
OutCubic 
InBack 
OutBack 

Definition at line 224 of file MathManager.hpp.

Constructor & Destructor Documentation

◆ MathManager()

MathManager::MathManager ( )
privatedefault
Here is the caller graph for this function:

Member Function Documentation

◆ acos()

ae::angle16_t MathManager::acos ( ae::q4_12_t ratio)

Computes the arccosine of a ratio.

Parameters
ratioRatio in Q4.12.
Returns
The cyclic angle whose cosine is ratio.

Definition at line 81 of file MathManager.cpp.

◆ angleToRadians()

ae::q20_12_t MathManager::angleToRadians ( ae::angle16_t angle)

Converts a cyclic angle to radians (Q20.12).

Parameters
angleCyclic angle (full turn = 1<<15).
Returns
The equivalent angle in radians, as a Q20.12 fixed-point value.

Definition at line 45 of file MathManager.cpp.

◆ asin()

ae::angle16_t MathManager::asin ( ae::q4_12_t ratio)

Computes the arcsine of a ratio.

Parameters
ratioRatio in Q4.12.
Returns
The cyclic angle whose sine is ratio.

Definition at line 76 of file MathManager.cpp.

◆ atan()

ae::q20_12_t MathManager::atan ( ae::q20_12_t y)

Computes the arctangent of a single ratio.

Implemented as atan2(y, 1), per BlocksDS's documented approach for deriving atan from atan2_f32.

Parameters
yRatio in Q20.12.
Returns
The angle in radians, as Q20.12.

Definition at line 131 of file MathManager.cpp.

Here is the call graph for this function:

◆ atan2()

ae::q20_12_t MathManager::atan2 ( ae::q20_12_t y,
ae::q20_12_t x )

Computes the angle (in radians) between the positive x-axis and (x, y).

Calls BlocksDS's native fixed-point atan2_f32, which operates directly on 20.12 fixed-point values with no float conversion.

Parameters
yY Point 2.
xX Point 1.
Returns
The angle in radians, as Q20.12.

Definition at line 122 of file MathManager.cpp.

Here is the caller graph for this function:

◆ clamp()

ae::q20_12_t MathManager::clamp ( ae::q20_12_t v,
ae::q20_12_t lo,
ae::q20_12_t hi )

Clamps a Q20.12 value to [lo, hi].

Definition at line 144 of file MathManager.cpp.

Here is the caller graph for this function:

◆ cos() [1/2]

ae::q4_12_t MathManager::cos ( ae::angle16_t angle)

Cosine of a cyclic angle.

Parameters
angleCyclic angle (full turn = 1<<15).
Returns
The cosine in Q4.12.

Definition at line 66 of file MathManager.cpp.

◆ cos() [2/2]

ae::q4_12_t MathManager::cos ( ae::q20_12_t radians)

Cosine, accepting radians (Q20.12).

Parameters
radiansAngle in radians, as a Q20.12 fixed-point value.
Returns
The cosine in Q4.12.

Definition at line 61 of file MathManager.cpp.

Here is the call graph for this function:

◆ degreesToCyclicAngle()

ae::angle16_t MathManager::degreesToCyclicAngle ( ae::q20_12_t degrees)

Converts an angle in degrees (Q20.12) to a cyclic angle.

Parameters
degreesAngle in degrees
Returns
The equivalent cyclic angle

Definition at line 40 of file MathManager.cpp.

◆ div()

ae::q20_12_t MathManager::div ( ae::q20_12_t num,
ae::q20_12_t den )

Divides two Q20.12 values.

Parameters
numNumerator.
denDenominator.
Returns
The quotient in Q20.12.

Definition at line 4 of file MathManager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dot()

ae::q20_12_t MathManager::dot ( ae::q20_12_t x1,
ae::q20_12_t y1,
ae::q20_12_t z1,
ae::q20_12_t x2,
ae::q20_12_t y2,
ae::q20_12_t z2 )

Computes the dot product of two Q20.12 3D vectors.

Parameters
x1X component of the first vector.
y1Y component of the first vector.
z1Z component of the first vector.
x2X component of the second vector.
y2Y component of the second vector.
z2Z component of the second vector.
Returns
The dot product in Q20.12.

Definition at line 86 of file MathManager.cpp.

Here is the caller graph for this function:

◆ ease()

ae::q20_12_t MathManager::ease ( EaseMode mode,
ae::q20_12_t t )

Applies an easing curve to a normalized time value.

Parameters
modeEasing curve to apply.
tNormalized time in [0, 1] as Q20.12 (clamped).
Returns
Eased time in [0, 1] as Q20.12.

Definition at line 168 of file MathManager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init()

void MathManager::init ( )
inlineoverride

Definition at line 19 of file MathManager.hpp.

◆ length()

ae::q20_12_t MathManager::length ( ae::q20_12_t x,
ae::q20_12_t y,
ae::q20_12_t z )

Computes the length of a Q20.12 3D vector.

Parameters
xX component.
yY component.
zZ component.
Returns
The length in Q20.12.

Definition at line 100 of file MathManager.cpp.

Here is the call graph for this function:

◆ lengthSq()

ae::q20_12_t MathManager::lengthSq ( ae::q20_12_t x,
ae::q20_12_t y,
ae::q20_12_t z )

Computes the squared length of a Q20.12 3D vector.

Parameters
xX component.
yY component.
zZ component.
Returns
The squared length in Q20.12.

Definition at line 95 of file MathManager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lerp() [1/2]

ae::q20_12_t MathManager::lerp ( ae::q20_12_t a,
ae::q20_12_t b,
ae::q20_12_t t )

Linearly interpolates two Q20.12 values.

Parameters
aStart value.
bEnd value.
tBlend factor in [0, 1] as Q20.12.
Returns
The interpolated value.

Definition at line 157 of file MathManager.cpp.

Here is the caller graph for this function:

◆ lerp() [2/2]

int MathManager::lerp ( int a,
int b,
ae::q20_12_t t )

Linearly interpolates two integers with a fixed-point blend factor.

Parameters
aStart value.
bEnd value.
tBlend factor in [0, 1] as Q20.12.
Returns
The interpolated integer.

Definition at line 162 of file MathManager.cpp.

◆ mod()

ae::q20_12_t MathManager::mod ( ae::q20_12_t num,
ae::q20_12_t den )

Computes the modulo of two Q20.12 values.

Parameters
numNumerator.
denDenominator.
Returns
The remainder in Q20.12.

Definition at line 25 of file MathManager.cpp.

Here is the call graph for this function:

◆ normalize()

void MathManager::normalize ( ae::q20_12_t & x,
ae::q20_12_t & y,
ae::q20_12_t & z )

Normalizes a Q20.12 3D vector in place.

Parameters
xX component, updated in place.
yY component, updated in place.
zZ component, updated in place.
Returns
Sets x, y, z to 0,0,0 if length is zero (via out parameters).

Definition at line 105 of file MathManager.cpp.

◆ process()

void MathManager::process ( )
inlineoverride

Definition at line 23 of file MathManager.hpp.

◆ radiansToAngle()

ae::angle16_t MathManager::radiansToAngle ( ae::q20_12_t radians)

Converts an angle in radians (Q20.12).

Parameters
radiansAngle in radians, as a Q20.12 fixed-point value.
Returns
The equivalent cyclic angle (full turn = 1<<15).

Definition at line 35 of file MathManager.cpp.

Here is the caller graph for this function:

◆ randFrac()

ae::q20_12_t MathManager::randFrac ( )

Returns a uniformly distributed random fraction from 0 to 1.

Returns
A random value in Q20.12, from 0 to 1.

Definition at line 116 of file MathManager.cpp.

◆ secondsToSamples()

u32 MathManager::secondsToSamples ( ae::q20_12_t seconds,
u32 sampleRate )

Converts a Q20.12 seconds value to a sample count, avoiding overflow when seconds * sampleRate exceeds Q20.12's integer range.

Parameters
secondsTime value in seconds, as Q20.12.
sampleRateSamples per second.
Returns
The equivalent sample count.

Definition at line 136 of file MathManager.cpp.

◆ shutdown()

void MathManager::shutdown ( )
inlineoverride

Definition at line 27 of file MathManager.hpp.

◆ sin() [1/2]

ae::q4_12_t MathManager::sin ( ae::angle16_t angle)

Sine of a cyclic angle.

Parameters
angleCyclic angle (full turn = 1<<15).
Returns
The sine in Q4.12.

Definition at line 56 of file MathManager.cpp.

◆ sin() [2/2]

ae::q4_12_t MathManager::sin ( ae::q20_12_t radians)

Sine, accepting radians (Q20.12).

Parameters
radiansAngle in radians, as a Q20.12 fixed-point value.
Returns
The sine in Q4.12.

Definition at line 51 of file MathManager.cpp.

Here is the call graph for this function:

◆ sqrt()

ae::q20_12_t MathManager::sqrt ( ae::q20_12_t v)

Computes the square root of a Q20.12 value.

Parameters
vValue to root.
Returns
The square root in Q20.12.

Definition at line 14 of file MathManager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tan()

ae::q20_12_t MathManager::tan ( ae::q20_12_t radians)

Tangent, accepting radians (Q20.12).

Parameters
radiansAngle in radians, as a Q20.12 fixed-point value.
Returns
The tangent in Q20.12.

Definition at line 71 of file MathManager.cpp.

Here is the call graph for this function:

◆ Singleton< MathManager >

friend class Singleton< MathManager >
friend

Definition at line 268 of file MathManager.hpp.


The documentation for this class was generated from the following files: