From 31691f8023b14b1b4d52fdf01932321c0408db19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Sat, 1 Sep 2018 09:07:49 +0200 Subject: [PATCH] Fix wall heights --- raycastlib.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/raycastlib.h b/raycastlib.h index cbaac83..4695ceb 100644 --- a/raycastlib.h +++ b/raycastlib.h @@ -96,7 +96,7 @@ typedef struct a "type" of given square as an integer (e.g. square height) - between squares that return different numbers there is considered to be a collision. */ -typedef int16_t (*ArrayFunction)(int16_t x, int16_t y); +typedef Unit (*ArrayFunction)(int16_t x, int16_t y); typedef void (*PixelFunction)(PixelInfo info); @@ -512,11 +512,14 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray) dist = dist == 0 ? 1 : dist; // prevent division by zero - int32_t height = perspectiveScale(50,dist,1); + Unit z = + (_camera.resolution.y * + (_arrayFunction(hit.square.x,hit.square.y) - _camera.height) + ) / UNITS_PER_SQUARE; - int16_t z = _arrayFunction(hit.square.x,hit.square.y) * 50; + int32_t height = perspectiveScale(z,dist,1); - Unit offset = perspectiveScale(_camera.height - z,dist,1); + Unit offset = perspectiveScale(_camera.height,dist,1); int32_t start = _camera.resolution.y / 2 + height / 2 + offset;