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:
parent
029f753bbf
commit
3492cfa63d
1 changed files with 4 additions and 1 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue