From 6c8351f1454f7374c5dc76177f180a2eb68be98b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Tue, 11 Sep 2018 12:46:47 +0200 Subject: [PATCH] Fix texturing --- raycastlib.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/raycastlib.h b/raycastlib.h index 7cdc813..8e525a3 100644 --- a/raycastlib.h +++ b/raycastlib.h @@ -753,10 +753,9 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray) int_maybe32_t z2Screen = _middleRow - perspectiveScale( (worldZ2 * _camera.resolution.y) / UNITS_PER_SQUARE,dist); - int_maybe32_t wallScreenHeightNoClamp = z2Screen - z1ScreenNoClamp; - - wallScreenHeightNoClamp = wallScreenHeightNoClamp != 0 ? - wallScreenHeightNoClamp : 1; + int_maybe32_t wallScreenHeightNoClamp = z1ScreenNoClamp - z2Screen + 1; + wallScreenHeightNoClamp = wallScreenHeightNoClamp == 0 ? 1 : + wallScreenHeightNoClamp; z2Screen = clamp(z2Screen,0,_camResYLimit); z2Screen = z2Screen > y2 ? z2Screen : y2; @@ -856,7 +855,7 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray) p.hit = hit; if (_computeTextureCoords) - p.textureCoordY = UNITS_PER_SQUARE - 1 -((i - z1ScreenNoClamp) * + p.textureCoordY = UNITS_PER_SQUARE - 1 - ((z1ScreenNoClamp - i) * UNITS_PER_SQUARE) / wallScreenHeightNoClamp; _pixelFunction(p);