NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
math_triangular.h
1#ifndef NW4R_MATH_TRIANGULAR_H
2#define NW4R_MATH_TRIANGULAR_H
3#include <nw4r/types_nw4r.h>
4
5#include <nw4r/math/math_arithmetic.h>
6#include <nw4r/math/math_constant.h>
7
8/******************************************************************************
9 *
10 * Macros to convert between units
11 *
12 ******************************************************************************/
13// [0, 65535] -> [0.0, 256.0f]
14#define NW4R_MATH_IDX_TO_FIDX(x) ((x) * (1.0f / 256.0f))
15
16// Convert degrees <-> lookup-table index
17#define NW4R_MATH_DEG_TO_FIDX(x) ((x) * (256.0f / 360.0f))
18#define NW4R_MATH_FIDX_TO_DEG(x) ((x) * (360.0f / 256.0f))
19
20// Convert radians <-> lookup-table index
21#define NW4R_MATH_RAD_TO_FIDX(x) ((x) * (128.0f / NW4R_MATH_PI))
22#define NW4R_MATH_FIDX_TO_RAD(x) ((x) * (NW4R_MATH_PI / 128.0f))
23
24// Convert degrees <-> radians
25#define NW4R_MATH_DEG_TO_RAD(x) ((x) * (NW4R_MATH_PI / 180.0f))
26#define NW4R_MATH_RAD_TO_DEG(x) ((x) * (180.0f / NW4R_MATH_PI))
27
28namespace nw4r {
29namespace math {
30
31/******************************************************************************
32 *
33 * Sin functions
34 *
35 ******************************************************************************/
36f32 SinFIdx(f32 fidx);
37
38inline float SinF(float ang) {
39 return SinFIdx(NW4R_MATH_IDX_TO_FIDX(ang));
40}
41inline f32 SinIdx(short idx) {
42 return SinF(U16ToF32(idx));
43}
44inline f32 SinDeg(f32 deg) {
45 return SinFIdx(NW4R_MATH_DEG_TO_FIDX(deg));
46}
47inline f32 SinRad(f32 rad) {
48 return SinFIdx(NW4R_MATH_RAD_TO_FIDX(rad));
49}
50
51/******************************************************************************
52 *
53 * Cosine functions
54 *
55 ******************************************************************************/
56f32 CosFIdx(f32 fidx);
57
58inline float CosF(float ang) {
59 return CosFIdx(NW4R_MATH_IDX_TO_FIDX(ang));
60}
61inline f32 CosIdx(short idx) {
62 return CosF(U16ToF32(idx));
63}
64inline f32 CosDeg(f32 deg) {
65 return CosFIdx(NW4R_MATH_DEG_TO_FIDX(deg));
66}
67inline f32 CosRad(f32 rad) {
68 return CosFIdx(NW4R_MATH_RAD_TO_FIDX(rad));
69}
70
71/******************************************************************************
72 *
73 * Tangent functions
74 *
75 ******************************************************************************/
76inline f32 TanFIdx(f32 fidx) {
77 return std::tanf(NW4R_MATH_FIDX_TO_RAD(fidx));
78}
79inline f32 TanDeg(f32 deg) {
80 return TanFIdx(NW4R_MATH_DEG_TO_FIDX(deg));
81}
82inline f32 TanRad(f32 rad) {
83 return TanFIdx(NW4R_MATH_RAD_TO_FIDX(rad));
84}
85
86/******************************************************************************
87 *
88 * Sin & cosine functions
89 *
90 ******************************************************************************/
91void SinCosFIdx(f32* pSin, f32* pCos, f32 fidx);
92
93inline void SinCosDeg(f32* pSin, f32* pCos, f32 deg) {
94 return SinCosFIdx(pSin, pCos, NW4R_MATH_DEG_TO_FIDX(deg));
95}
96inline void SinCosRad(f32* pSin, f32* pCos, f32 rad) {
97 return SinCosFIdx(pSin, pCos, NW4R_MATH_RAD_TO_FIDX(rad));
98}
99
100/******************************************************************************
101 *
102 * Arc-tangent functions
103 *
104 ******************************************************************************/
105f32 AtanFIdx(f32 x);
106
107inline f32 AtanDeg(f32 x) {
108 return NW4R_MATH_FIDX_TO_DEG(AtanFIdx(x));
109}
110inline f32 AtanRad(f32 x) {
111 return NW4R_MATH_FIDX_TO_RAD(AtanFIdx(x));
112}
113
114/******************************************************************************
115 *
116 * Arc-tangent (2-argument) functions
117 *
118 ******************************************************************************/
119f32 Atan2FIdx(f32 y, f32 x);
120
121inline f32 Atan2Deg(f32 y, f32 x) {
122 return NW4R_MATH_FIDX_TO_DEG(Atan2FIdx(y, x));
123}
124inline f32 Atan2Rad(f32 y, f32 x) {
125 return NW4R_MATH_FIDX_TO_RAD(Atan2FIdx(y, x));
126}
127
128} // namespace math
129} // namespace nw4r
130
131#endif
Math library.