From fb3922a7bac4bc2c0a084375601bc8b2cdd4b197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Fri, 31 Aug 2018 19:01:36 +0200 Subject: [PATCH] Render camera height --- raycastlib.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/raycastlib.h b/raycastlib.h index bb37b17..5d2f96d 100644 --- a/raycastlib.h +++ b/raycastlib.h @@ -500,8 +500,11 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray) dist = dist == 0 ? 1 : dist; // prevent division by zero - int32_t height = (UNITS_PER_SQUARE * 50) / dist; - uint32_t start = _camera.resolution.y / 2 - height / 2; + int32_t height = perspectiveScale(50,dist,1); + + Unit offset = perspectiveScale(_camera.height,dist,1); + + uint32_t start = _camera.resolution.y / 2 - height / 2 + offset; for (uint32_t i = start; i < start + height; ++i) { @@ -510,6 +513,7 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray) p.position.x = x; p.position.y = i; p.isWall = 1; + p.hit = hit; _pixelFunction(p); } @@ -554,6 +558,8 @@ Unit degreesToUnitsAngle(int16_t degrees) Unit perspectiveScale(Unit originalSize, Unit distance, Unit fov) { +return (originalSize * UNITS_PER_SQUARE) / distance; + distance *= fov; distance = distance == 0 ? 1 : distance; // prevent division by zero