From b0c9d2478770687911c4d8b2c57768eab26c5188 Mon Sep 17 00:00:00 2001 From: trotFunky Date: Sun, 4 Feb 2024 21:04:07 +0000 Subject: [PATCH] World: Add projection correction factor Rays are all sent from the center of the camera plane, which makes rays with a greater angle longer than if they were properly sent perpendicularly from the camera plane. Correct this by projecting the ray to the look direction (which is perpendicular to the camera plane). --- World.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/World.cpp b/World.cpp index a7f7bf1..8f37c24 100644 --- a/World.cpp +++ b/World.cpp @@ -267,7 +267,10 @@ void World::render(sf::RenderWindow& window) } else if (rayAngle > 360) { rayAngle -= 360; } - float obstacleScale = worldToCamera / castRay(player.x, player.y, rayAngle); + float obstacleScale = worldToCamera / ( + castRay(player.x, player.y, rayAngle) * + cosf(deltaAngle*deg_to_rad) + ); /* 2 Is wall height in meters. */ fillColumn(window, i, obstacleScale); }