A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
Kinoko::EGG::Mathf Namespace Reference

Detailed Description

Math functions and constants used in the base game.

Classes

struct  AtanEntry
 
struct  BaseAndDec32
 
struct  BaseAndDec64
 
union  c32
 
union  c64
 
struct  SinCosEntry
 

Functions

static constexpr f64 force25Bit (f64 x)
 This is used to mimic the Wii's floating-point unit.
 
static constexpr f32 fma (f32 x, f32 y, f32 z)
 Fused multiply-add operation.
 
static constexpr f32 fms (f32 x, f32 y, f32 z)
 Fused multiply-subtract operation.
 
static constexpr f32 SinFIdx (f32 fidx)
 
static constexpr f32 CosFIdx (f32 fidx)
 
static constexpr std::pair< f32, f32 > SinCosFIdx (f32 fidx)
 
static constexpr f32 AtanFIdx_ (f32 x)
 
static constexpr f32 Atan2FIdx (f32 y, f32 x)
 
static constexpr f32 sin (f32 x)
 
static constexpr f32 cos (f32 x)
 
static constexpr f32 asin (f32 x)
 
static constexpr f32 acos (f32 x)
 
static constexpr f32 atan2 (f32 y, f32 x)
 
static constexpr f32 abs (f32 x)
 
static constexpr f64 frsqrte (const f64 val)
 
static constexpr f32 fres (const f32 val)
 
static constexpr f32 frsqrt (f32 x)
 
static constexpr f32 sqrt (f32 x)
 
static constexpr u32 FindRootsQuadratic (f32 a, f32 b, f32 c, f32 &root1, f32 &root2)
 
static constexpr f32 finv (f32 x)
 Fused Newton-Raphson operation.
 
static constexpr f32 Hermite (f32 p0, f32 m0, f32 p1, f32 m1, f32 t)
 Evaluates a cubic Hermite curve at a given parameter t.
 

Variables

static constexpr SinCosEntry sSinCosTbl [256+1]
 
static constexpr AtanEntry sArcTanTbl [32+1]
 
static constexpr u64 EXPONENT_SHIFT_F64 = 52
 
static constexpr u64 MANTISSA_MASK_F64 = 0x000fffffffffffffULL
 
static constexpr u64 EXPONENT_MASK_F64 = 0x7ff0000000000000ULL
 
static constexpr u64 SIGN_MASK_F64 = 0x8000000000000000ULL
 
static constexpr std::array< BaseAndDec64, 32 > RSQRTE_TABLE
 
static constexpr std::array< BaseAndDec32, 32 > FRES_TABLE
 

Function Documentation

◆ abs()

static constexpr f32 Kinoko::EGG::Mathf::abs ( f32 x)
inlinestaticnodiscardconstexpr

Definition at line 476 of file Math.hh.

◆ acos()

static constexpr f32 Kinoko::EGG::Mathf::acos ( f32 x)
inlinestaticnodiscardconstexpr0x8022F8C0

Definition at line 467 of file Math.hh.

◆ asin()

static constexpr f32 Kinoko::EGG::Mathf::asin ( f32 x)
inlinestaticnodiscardconstexpr0x8022F89C

Definition at line 462 of file Math.hh.

◆ atan2()

static constexpr f32 Kinoko::EGG::Mathf::atan2 ( f32 y,
f32 x )
inlinestaticnodiscardconstexpr0x8022F8E4

Definition at line 472 of file Math.hh.

◆ Atan2FIdx()

static constexpr f32 Kinoko::EGG::Mathf::Atan2FIdx ( f32 y,
f32 x )
inlinestaticnodiscardconstexpr0x800853C0

Definition at line 413 of file Math.hh.

◆ AtanFIdx_()

static constexpr f32 Kinoko::EGG::Mathf::AtanFIdx_ ( f32 x)
inlinestaticnodiscardconstexpr

Definition at line 405 of file Math.hh.

◆ cos()

static constexpr f32 Kinoko::EGG::Mathf::cos ( f32 x)
inlinestaticnodiscardconstexpr0x8022F86C

Takes in radians

Definition at line 457 of file Math.hh.

◆ CosFIdx()

static constexpr f32 Kinoko::EGG::Mathf::CosFIdx ( f32 fidx)
inlinestaticnodiscardconstexpr0x80085180

Definition at line 369 of file Math.hh.

◆ FindRootsQuadratic()

static constexpr u32 Kinoko::EGG::Mathf::FindRootsQuadratic ( f32 a,
f32 b,
f32 c,
f32 & root1,
f32 & root2 )
inlinestaticconstexpr0x800867C0

Definition at line 734 of file Math.hh.

◆ finv()

static constexpr f32 Kinoko::EGG::Mathf::finv ( f32 x)
inlinestaticnodiscardconstexpr

Fused Newton-Raphson operation.

Definition at line 775 of file Math.hh.

◆ fma()

static constexpr f32 Kinoko::EGG::Mathf::fma ( f32 x,
f32 y,
f32 z )
inlinestaticnodiscardconstexpr

Fused multiply-add operation.

We cannot use std::fma due to the Wii computing at 64-bit precision.

Definition at line 33 of file Math.hh.

◆ fms()

static constexpr f32 Kinoko::EGG::Mathf::fms ( f32 x,
f32 y,
f32 z )
inlinestaticnodiscardconstexpr

Fused multiply-subtract operation.

We cannot use std::fms due to the Wii computing at 64-bit precision.

Definition at line 40 of file Math.hh.

◆ force25Bit()

static constexpr f64 Kinoko::EGG::Mathf::force25Bit ( f64 x)
inlinestaticnodiscardconstexpr

This is used to mimic the Wii's floating-point unit.

This handles the edgecase where double-precision floating-point numbers are passed into single-precision floating-point operands in assembly.

Definition at line 25 of file Math.hh.

◆ fres()

static constexpr f32 Kinoko::EGG::Mathf::fres ( const f32 val)
inlinestaticnodiscardconstexpr

Definition at line 649 of file Math.hh.

◆ frsqrt()

static constexpr f32 Kinoko::EGG::Mathf::frsqrt ( f32 x)
inlinestaticnodiscardconstexpr0x80085040

CREDIT: Hanachan

Definition at line 716 of file Math.hh.

◆ frsqrte()

static constexpr f64 Kinoko::EGG::Mathf::frsqrte ( const f64 val)
inlinestaticnodiscardconstexpr

Definition at line 558 of file Math.hh.

◆ Hermite()

static constexpr f32 Kinoko::EGG::Mathf::Hermite ( f32 p0,
f32 m0,
f32 p1,
f32 m1,
f32 t )
inlinestaticnodiscardconstexpr0x80085070

Evaluates a cubic Hermite curve at a given parameter t.

Computes

\[H(t) = h_0(t)\,p_0 + h_1(t)\,p_1 + h_2(t)\,m_0 + h_3(t)\,m_1\]

where the cubic Hermite basis functions are:

\[h_0(\theta) = 2\theta^3 - 3\theta^2 + 1\]

\[h_1(\theta) = -2\theta^3 + 3\theta^2\]

\[h_2(\theta) = \theta^3 - 2\theta^2 + \theta\]

\[h_3(\theta) = \theta^3 - \theta^2\]

Parameters
p0Start value.
m0Start tangent.
p1End value.
m1End tangent.
tInterpolation parameter in the domain [0, 1]
Returns
Interpolated value at t.

Definition at line 797 of file Math.hh.

◆ sin()

static constexpr f32 Kinoko::EGG::Mathf::sin ( f32 x)
inlinestaticnodiscardconstexpr0x8022F860

Takes in radians

Definition at line 451 of file Math.hh.

◆ SinCosFIdx()

static constexpr std::pair< f32, f32 > Kinoko::EGG::Mathf::SinCosFIdx ( f32 fidx)
inlinestaticnodiscardconstexpr0x800851E0

Definition at line 384 of file Math.hh.

◆ SinFIdx()

static constexpr f32 Kinoko::EGG::Mathf::SinFIdx ( f32 fidx)
inlinestaticnodiscardconstexpr0x80085110

Definition at line 354 of file Math.hh.

◆ sqrt()

static constexpr f32 Kinoko::EGG::Mathf::sqrt ( f32 x)
inlinestaticnodiscardconstexpr0x8022F80C

Definition at line 729 of file Math.hh.

Variable Documentation

◆ EXPONENT_MASK_F64

u64 Kinoko::EGG::Mathf::EXPONENT_MASK_F64 = 0x7ff0000000000000ULL
staticconstexpr

Definition at line 520 of file Math.hh.

◆ EXPONENT_SHIFT_F64

u64 Kinoko::EGG::Mathf::EXPONENT_SHIFT_F64 = 52
staticconstexpr

Definition at line 518 of file Math.hh.

◆ FRES_TABLE

std::array<BaseAndDec32, 32> Kinoko::EGG::Mathf::FRES_TABLE
staticconstexpr

Definition at line 614 of file Math.hh.

◆ MANTISSA_MASK_F64

u64 Kinoko::EGG::Mathf::MANTISSA_MASK_F64 = 0x000fffffffffffffULL
staticconstexpr

Definition at line 519 of file Math.hh.

◆ RSQRTE_TABLE

std::array<BaseAndDec64, 32> Kinoko::EGG::Mathf::RSQRTE_TABLE
staticconstexpr

Definition at line 523 of file Math.hh.

◆ sArcTanTbl

AtanEntry Kinoko::EGG::Mathf::sArcTanTbl[32+1]
staticconstexpr0x80274148

Definition at line 317 of file Math.hh.

◆ SIGN_MASK_F64

u64 Kinoko::EGG::Mathf::SIGN_MASK_F64 = 0x8000000000000000ULL
staticconstexpr

Definition at line 521 of file Math.hh.

◆ sSinCosTbl

SinCosEntry Kinoko::EGG::Mathf::sSinCosTbl[256+1]
staticconstexpr0x80248010

Definition at line 56 of file Math.hh.