From 900504971b0cfc5083367c1b8e15e018e26af3b3 Mon Sep 17 00:00:00 2001 From: Sheldon Lee Date: Thu, 20 Apr 2023 02:19:54 +0100 Subject: [PATCH] Make ray generation sane --- camera.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/camera.cpp b/camera.cpp index c52904a..8f02e33 100644 --- a/camera.cpp +++ b/camera.cpp @@ -1,4 +1,5 @@ #include "camera.h" +#include #include "maths.h" #include "level.h" @@ -54,22 +55,12 @@ void camera_destroy(Camera *camera) static void castRays(Camera* camera) { - float rayDirection = 0; float rayDirectionStep = camera->fov / (float)camera->resolution; - bool isOddResolution = (camera->resolution % 2); - float rayDirectionOffset = isOddResolution? 0 : rayDirectionStep / 2.f; - + float rayDirection = camera->direction - camera->fov/2.f + rayDirectionStep/2.f; for (unsigned int i = 0; i < camera->resolution; i++) { - if (isOddResolution && i == 0) - rayDirection = camera->direction; - else if (i % 2) - rayDirection = camera->direction - rayDirectionOffset; - else - rayDirection = camera->direction + rayDirectionOffset; - camera->rays[i].direction = rayDirection; camera->rays[i].distance = level_rayCastDistance(camera->pos, rayDirection); - if ((i + isOddResolution) % 2) rayDirectionOffset += rayDirectionStep; + rayDirection += rayDirectionStep; } }