Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
get_angle.inc.c
Go to the documentation of this file.
1/*
2 * The angle of (x, y), 0x100 a turn, from the stage's table of tangents
3 * angleTangents
4 */
6 s32 result = 0;
7 s32 ratio = 0;
8 s32 base;
9 s32 i;
10
11 if (x <= 0 && y >= 0) {
12 base = 0;
13 } else if (x >= 0 && y >= 0) {
14 base = 0x40;
15 } else if (x >= 0 && y <= 0) {
16 base = 0x80;
17 } else if (x <= 0 && y <= 0) {
18 base = 0xC0;
19 } else {
20 base = 0;
21 }
22 if (x < 0) {
23 x = -x;
24 }
25 if (y < 0) {
26 y = -y;
27 }
28 if (x == y) {
29 return base | 0x20;
30 }
31 if (y < x) {
32 ratio = y * 0xFFFF / x;
33 } else if (x < y) {
34 ratio = x * 0xFFFF / y;
35 }
36 for (i = 0; i <= 0x20; i++) {
37 if (angleTangents[i] <= ratio && ratio <= angleTangents[i + 1]) {
38 switch (base) {
39 case 0:
40 case 0x80:
41 if (y < x) {
42 result = i;
43 } else if (x < y) {
44 result = 0x40 - i;
45 }
46 return result + base;
47 case 0x40:
48 case 0xC0:
49 if (y < x) {
50 result = 0x40 - i;
51 } else if (x < y) {
52 result = i;
53 }
54 return result + base;
55 }
56 }
57 }
58 return 0xFF;
59}
signed int s32
Definition common.h:11
s32 getAngle(s32 x, s32 y)
The angle of (x, y), 0x100 a turn, from the stage's table of tangents angleTangents.
u16 angleTangents[]
Definition wstag460.c:564