blob: 2111fabb15b80e7ef200e064890003b2dda92ad2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
#ifndef JMATRIGONOMETRIC_H
#define JMATRIGONOMETRIC_H
#include "common.h"
#include "utility.h"
template<typename T>
struct TAngleConstant_;
/**
* @ingroup jsystem-jmath
*
*/
template<>
struct TAngleConstant_<f32> {
static f32 RADIAN_DEG090() { return 1.5707964f; }
static f32 RADIAN_DEG180() { return 3.1415927f; }
static f32 RADIAN_DEG360() { return 6.2831855f; }
static f32 RADIAN_TO_DEGREE_FACTOR() { return 180.0f / RADIAN_DEG180(); }
};
/**
* @ingroup jsystem-jmath
*
*/
template<int N, typename T>
struct TSinCosTable {
std::pair<T, T> table[1 << N];
T sinShort(s16 v) const { return table[(u16)v >> (16U - N)].first; }
T cosShort(s16 v) const { return table[(u16)v >> (16U - N)].second; }
inline T sinLap(T v) {
if (v < (T)0.0) {
return -table[(u16)(-(T)(1 << N) * v) & ((1 << N) - 1)].first;
}
return table[(u16)((T)(1 << N) * v) & ((1 << N) - 1)].first;
}
inline T sinDegree(T degree) {
if (degree < (T)0.0) {
return -table[(u16)(-((T)(1 << N) / (T)360.0) * degree) & ((1 << N) - 1)].first;
}
return table[(u16)(((T)(1 << N) / (T)360.0) * degree) & ((1 << N) - 1)].first;
}
inline T cosDegree(T degree) {
if (degree < (T)0.0) {
degree = -degree;
}
return table[(u16)(((T)(1 << N) / (T)360.0) * degree) & ((1 << N) - 1)].second;
}
inline T sinRadian(T radian) {
if (radian < (T)0.0) {
return -table[(u16)(-(T)(1 << N) / TAngleConstant_<T>::RADIAN_DEG360() * radian) & ((1 << N) - 1)].first;
}
return table[(u16)((T)(1 << N) / TAngleConstant_<T>::RADIAN_DEG360() * radian) & ((1 << N) - 1)].first;
}
};
/**
* @ingroup jsystem-jmath
*
*/
struct TAtanTable {
f32 table[1025];
u8 pad[0x1C];
};
/**
* @ingroup jsystem-jmath
*
*/
struct TAsinAcosTable {
f32 table[1025];
u8 pad[0x1C];
f32 acos_(f32 x) {
if (x >= 1.0f) {
return 0.0f;
} else if (x <= -1.0f) {
return TAngleConstant_<f32>::RADIAN_DEG180();
} else if (x < 0.0f) {
return table[(u32)(-x * 1023.5f)] + TAngleConstant_<f32>::RADIAN_DEG090();
} else {
return TAngleConstant_<f32>::RADIAN_DEG090() - table[(u32)(x * 1023.5f)];
}
}
f32 acosDegree(f32 x) {
return acos_(x) * TAngleConstant_<f32>::RADIAN_TO_DEGREE_FACTOR();
}
};
namespace JMath {
extern TSinCosTable<13, f32> sincosTable_;
extern TAtanTable atanTable_;
extern TAsinAcosTable asinAcosTable_;
inline f32 acosDegree(f32 x) {
return asinAcosTable_.acosDegree(x);
}
}; // namespace JMath
inline f32 JMASCosShort(s16 v) {
return JMath::sincosTable_.cosShort(v);
}
inline f32 JMASinShort(s16 v) {
return JMath::sincosTable_.sinShort(v);
}
inline f32 JMASCos(s16 v) {
return JMASCosShort(v);
}
inline f32 JMASSin(s16 v) {
return JMASinShort(v);
}
inline f32 JMASinLap(f32 v) {
return JMath::sincosTable_.sinLap(v);
}
inline f32 JMASinDegree(f32 degree) {
return JMath::sincosTable_.sinDegree(degree);
}
inline f32 JMACosDegree(f32 degree) {
return JMath::sincosTable_.cosDegree(degree);
}
inline f32 JMASinRadian(f32 radian) {
return JMath::sincosTable_.sinRadian(radian);
}
#endif /* JMATRIGONOMETRIC_H */
|