blob: 684db81e741fcf6483d22e249b47bec98e662bb2 (
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
#include "global.h"
#include "main.h"
#include "fx.h"
extern s16 FX_AtanTable_[];
u16 FX_Atan(s32 x){
if (x >= 0)
{
if (x > 0x1000)
{
x = FX_Inv(x);
s16 y = FX_AtanTable_[x >> 5];
return 0x4000 - y;
}
else if (x < 0x1000)
{
return FX_AtanTable_[x >> 5];
}
else
{
return 0x2000;
}
}
else
{
if (x < -0x1000)
{
x = FX_Inv(-x);
s16 y = FX_AtanTable_[x >> 5];
return y - 0x4000;
}
else if (x > -0x1000)
{
return -FX_AtanTable_[-x >> 5];
}
else
{
return -0x2000;
}
}
}
u16 FX_Atan2(s32 x, s32 y){
s32 result;
u32 positive, bias, denominator, numerator;
if (x > 0)
{
if (y > 0)
{
if (y > x)
{
numerator = x;
denominator = y;
bias = 0;
positive = TRUE;
}
else if (y < x)
{
numerator = y;
denominator = x;
bias = 0x4000;
positive = FALSE;
}
else
{
return 0x2000;
}
}
else if (y < 0)
{
y = -y;
if (y < x)
{
numerator = y;
denominator = x;
bias = 0x4000;
positive = TRUE;
}
else if (y > x)
{
numerator = x;
denominator = y;
bias = 0x8000;
positive = FALSE;
}
else
{
return 0x6000;
}
}
else
{
return 0x4000;
}
}
else if (x < 0)
{
x = -x;
if (y < 0)
{
y = -y;
if (y > x)
{
numerator = x;
denominator = y;
bias = -0x8000;
positive = TRUE;
}
else if (y < x)
{
numerator = y;
denominator = x;
bias = -0x4000;
positive = FALSE;
}
else
{
return 0xA000;
}
}
else if (y > 0)
{
if (y < x)
{
numerator = y;
denominator = x;
bias = -0x4000;
positive = TRUE;
}
else if (y > x)
{
numerator = x;
denominator = y;
bias = 0x0;
positive = FALSE;
}
else
{
return 0xE000;
}
}
else
{
return 0xC000;
}
}
else
{
if (y >= 0)
return 0x0;
else
return 0x8000;
}
if (denominator == 0x0)
return 0x0;
if (positive)
return bias + FX_AtanTable_[FX_Div(numerator, denominator) >> 5];
else
return bias - FX_AtanTable_[FX_Div(numerator, denominator) >> 5];
}
|