ref: e3549f87038b4880b0c05b25c7129067b542b5c9
parent: 293dbd4e03ab313af57abc17eabae3b0d47f581b
author: Clownacy <Clownacy@users.noreply.github.com>
date: Thu Feb 21 18:24:23 EST 2019
Made Triangle.cpp ASM-accurate It's really starting to look more and more like Pixel really did write in C90... just look at the declarations I have to shove at the start of the functions.
--- a/src/Triangle.cpp
+++ b/src/Triangle.cpp
@@ -8,19 +8,19 @@
void InitTriangleTable()
{
+ int i;
+
//Sine
- for (int i = 0; i < 0x100; ++i )
+ for (i = 0; i < 0x100; ++i)
{
- float v0 = i * 6.2831998 / 256.0;
- gSin[i] = (int)(sinf(v0) * 512.0);
+ gSin[i] = (int)(sin(i * 6.2831998 / 256.0) * 512.0);
}
//Tangent
- for (int i = 0; i < 0x21; ++i )
+ for (i = 0; i < 0x21; ++i)
{
float a = i * 6.2831855 / 256.0;
- float v2 = sinf(a);
- float b = v2 / cosf(a);
+ float b = sinf(a) / cosf(a);
gTan[i] = (int16_t)(b * 8192.0);
}
}
@@ -32,70 +32,89 @@
int GetCos(uint8_t deg)
{
- return gSin[(uint8_t)(deg + 0x40)];
+ deg += 0x40;
+ return gSin[deg];
}
-int GetArktan(int x, int y)
+uint8_t GetArktan(int x, int y)
{
- int xa = -x;
- int ya = -y;
+ x *= -1;
+ y *= -1;
uint8_t a = 0;
-
- if (xa <= 0)
+ int16_t k;
+
+ if (x > 0)
{
- if (ya <= 0)
+ if (y > 0)
{
- if (-xa <= -ya)
+ if (x > y)
{
- while (gTan[a] < (int16_t)(-0x2000 * xa / -ya))
+ k = (y * 0x2000) / x;
+ while (k > gTan[a])
++a;
- a = -0x40 - a;
}
else
{
- while (gTan[a] < (int16_t)(-0x2000 * ya / -xa))
+ k = (x * 0x2000) / y;
+ while (k > gTan[a])
++a;
- a += -0x80;
+ a = 0x40 - a;
}
}
- else if (-xa <= ya)
- {
- while (gTan[a] < (int16_t)(-0x2000 * xa / ya))
- ++a;
- a += 0x40;
- }
else
{
- while (gTan[a] < (int16_t)((ya << 13) / -xa))
- ++a;
- a = -0x80 - a;
+ if (-y < x)
+ {
+ k = (-y * 0x2000) / x;
+ while (k > gTan[a])
+ ++a;
+ a = 0x100 - a;
+ }
+ else
+ {
+ k = (x * 0x2000) / -y;
+ while (k > gTan[a])
+ ++a;
+ a = 0x100 - 0x40 + a;
+ }
}
}
- else if (ya <= 0)
+ else
{
- if (-ya >= xa)
+ if (y > 0)
{
- while (gTan[a] < (int16_t)((xa << 13) / -ya))
- ++a;
- a -= 0x40;
+ if (-x > y)
+ {
+ k = (y * 0x2000) / -x;
+ while (k > gTan[a])
+ ++a;
+ a = 0x80 - a;
+ }
+ else
+ {
+ k = (-x * 0x2000) / y;
+ while (k > gTan[a])
+ ++a;
+ a = 0x40 + a;
+ }
}
else
{
- while (gTan[a] < (int16_t)(-0x2000 * ya / xa))
- ++a;
- a = -a;
+ if (-x > -y)
+ {
+ k = (-y * 0x2000) / -x;
+ while (k > gTan[a])
+ ++a;
+ a = 0x80 + a;
+ }
+ else
+ {
+ k = (-x * 0x2000) / -y;
+ while (k > gTan[a])
+ ++a;
+ a = 0x100 - 0x40 - a;
+ }
}
- }
- else if (xa <= ya)
- {
- while (gTan[a] < (int16_t)((xa << 13) / ya))
- ++a;
- a = 0x40 - a;
- }
- else
- {
- while (gTan[a] < (int16_t)((ya << 13) / xa))
- ++a;
}
return a;
--- a/src/Triangle.h
+++ b/src/Triangle.h
@@ -5,4 +5,4 @@
void InitTriangleTable();
int GetSin(uint8_t deg);
int GetCos(uint8_t deg);
-int GetArktan(int x, int y);
+uint8_t GetArktan(int x, int y);