diff --git a/raycastlib.h b/raycastlib.h index 08728d9..4f7202d 100644 --- a/raycastlib.h +++ b/raycastlib.h @@ -671,6 +671,9 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray) int_maybe32_t wallScreenHeightNoClamp = z2Screen - z1ScreenNoClamp; + wallScreenHeightNoClamp = wallScreenHeightNoClamp != 0 ? + wallScreenHeightNoClamp : 1; + z2Screen = clamp(z2Screen,0,_camResYLimit); int_maybe32_t z2ScreenCeil = _middleRow - perspectiveScale( @@ -679,6 +682,9 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray) int_maybe32_t wallScreenHeightCeilNoClamp = z2ScreenCeil - z1ScreenCeilNoClamp; + wallScreenHeightCeilNoClamp = wallScreenHeightCeilNoClamp != 0 ? + wallScreenHeightCeilNoClamp : 1; + z2ScreenCeil = clamp(z2ScreenCeil,0,_camResYLimit); int_maybe32_t zTop = z1Screen < z2Screen ? z1Screen : z2Screen; @@ -703,6 +709,9 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray) _pixelFunction(p); } + if (z1Screen < y) + y = z1Screen; + // draw ceiling until wall p.isFloor = 0; @@ -719,6 +728,9 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray) } } + if (z1ScreenCeil > y2) + y2 = z1ScreenCeil; + // draw floor wall p.isWall = 1;