From 7b914e0d5ae658862fa065dc08182cc85b6613e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Wed, 5 Sep 2018 19:49:39 +0200 Subject: [PATCH] Fix drawing bug --- raycastlib.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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;