Finished removing fixed point arithmatic

This commit is contained in:
Samuel Walker 2024-08-31 09:35:26 -06:00
parent f8afea55c2
commit d13287996c

View File

@ -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);