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:
Teo-CD 2024-02-04 21:04:07 +00:00
parent 029f753bbf
commit 3492cfa63d

View file

@ -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);
}