1
0
Fork 0

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).
This commit is contained in:
trotFunky 2024-02-04 21:04:07 +00:00
parent 10d0dee35d
commit b0c9d24787

View file

@ -267,7 +267,10 @@ void World::render(sf::RenderWindow& window)
} else if (rayAngle > 360) { } else if (rayAngle > 360) {
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. */ /* 2 Is wall height in meters. */
fillColumn(window, i, obstacleScale); fillColumn(window, i, obstacleScale);
} }