Fix fisheye effect with cosine

This commit is contained in:
Sheldon Lee 2023-04-30 22:47:45 +01:00
parent 4a9d85ba1c
commit 67c41106ff

View File

@ -27,8 +27,12 @@ void firstperson_update(sf::RenderTarget* renderTarget, Camera* camera)
renderTexture.clear(); renderTexture.clear();
for (unsigned int i = 0; i < camera->resolution; i++) { for (unsigned int i = 0; i < camera->resolution; i++) {
float distance = camera->rays[i].distance; // Get distance of ray intersection in the direction of the camera,
if (distance > 0.f) columnHeight = 0.5f * (float)height/camera->rays[i].distance; // instead of the actual ray distance to avoid fish eye effect.
float angleDiff = camera->rays[i].direction - camera->direction;
float distance = camera->rays[i].distance * cos(angleDiff);
if (distance > 0.f) columnHeight = 0.5f * (float)height/distance;
float centeredHeight = (float)height/2.f - columnHeight/2.f; float centeredHeight = (float)height/2.f - columnHeight/2.f;
float distanceScale = distance/10.f; float distanceScale = distance/10.f;