From d13287996cdab6dc729e7182359a14a5f272bc7e Mon Sep 17 00:00:00 2001 From: Samuel Walker Date: Sat, 31 Aug 2024 09:35:26 -0600 Subject: [PATCH] Finished removing fixed point arithmatic --- src/main.c | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/src/main.c b/src/main.c index 4e8f4de..dc9fafb 100644 --- a/src/main.c +++ b/src/main.c @@ -36,8 +36,15 @@ void castRay(s16 angle){ if(dx != 0) tan = (dy << FRAC_BITS)/dx; s16 aTan = 0; if(tan != 0) aTan = -(1 << (FRAC_BITS*2))/tan; + s16 threshold = (20 << FRAC_BITS); + if(aTan > threshold){ + aTan = threshold; + } + if(aTan < -threshold){ + aTan = -threshold; + } dof = 0; - s16 distH = 500; + s16 distH = 30000; s16 hx = l.pt1.x << FRAC_BITS; s16 hy = l.pt1.y << FRAC_BITS; if(dy == 0){ @@ -78,26 +85,26 @@ void castRay(s16 angle){ } dof = 0; - s16 distV = 500; + s16 distV = 30000; s16 vx = l.pt1.x << FRAC_BITS; s16 vy = l.pt1.y << FRAC_BITS; s16 nTan = -tan; - //s16 threshold = (51 << FRAC_BITS); - //if(nTan > threshold){ - // nTan = threshold; - //} - //if(nTan < -threshold){ - // nTan = -threshold; - //} - if(angle > 90 && r < 270) { + s16 threshold = (20 << FRAC_BITS); + if(nTan > threshold){ + nTan = threshold; + } + if(nTan < -threshold){ + nTan = -threshold; + } + if(angle > 90 && angle < 270) { // Facing Left rx = ((l.pt1.x / 10 * 10)-1) << FRAC_BITS; - ry = ((l.pt1.x) - (rx >> FRAC_BITS)*nTan) + (l.pt1.y << FRAC_BITS); + ry = (((l.pt1.x) - (rx >> FRAC_BITS))*nTan) + (l.pt1.y << FRAC_BITS); xo = -(10 << FRAC_BITS); yo = ((-xo >> FRAC_BITS)*nTan); } - if(angle < 90 || angle > 270) { + if(angle < 90 || angle > 270) { // Facing Right rx = ((l.pt1.x / 10 * 10)+10) << FRAC_BITS; - ry = ((l.pt1.x) - (rx >> FRAC_BITS)*nTan) + (l.pt1.y << FRAC_BITS); + ry = (((l.pt1.x) - (rx >> FRAC_BITS))*nTan) + (l.pt1.y << FRAC_BITS); xo = 10 << FRAC_BITS; yo = -(xo >> FRAC_BITS)*nTan; } @@ -126,13 +133,13 @@ void castRay(s16 angle){ dof += 1; } } - //if(distV < distH){ + if(distV < distH){ l.pt2.x = vx >> FRAC_BITS; l.pt2.y = vy >> FRAC_BITS; - //}else { - //l.pt2.x = hx >> FRAC_BITS; - //l.pt2.y = hy >> FRAC_BITS; - //} + }else { + l.pt2.x = hx >> FRAC_BITS; + l.pt2.y = hy >> FRAC_BITS; + } } @@ -173,7 +180,7 @@ void render(){ BMP_drawLine(&l); for (int i = 0; i < 16; i++){ castRay(angle); - //BMP_drawLine(&l); + BMP_drawLine(&l); } castRay(angle+10); BMP_drawLine(&l);