From: Lukas Jiriste Date: Fri, 22 Nov 2024 19:37:00 +0000 (+0100) Subject: Implement camera to ray function X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=4b5e1e57ffd56faf44699cde657b6600f12c1ac5;p=42%2FminiRT.git Implement camera to ray function --- diff --git a/src/main.c b/src/main.c index a706b99..8e4f55e 100644 --- a/src/main.c +++ b/src/main.c @@ -1,3 +1,4 @@ +#include "vec3.h" #include "miniRT.h" #include #include @@ -79,6 +80,29 @@ void ft_putpx_img(t_img *img, int x, int y, t_color c) return ; } +t_ray get_camera_ray(int x, int y, const t_session *s) +{ + t_ray res; + const float x_max = s->img.width; + const float y_max = s->img.height; + const t_camera *const camera = s->scene.current_camera; + + res.direction = camera->orientation; + res.direction = + vec_add( + res.direction, + vec_real_mul( + vec_add( + vec_real_mul( + camera->up_direction, + y_max / x_max * (y_max - 1 - 2 * y) / (y_max - 1)), + vec_real_mul( + vec_vec_mul(camera->orientation, camera->up_direction), + (x_max - 1 - 2 * x) / (x_max - 1))), + tan(camera->field_of_view / 2))); + return (res); +} + void draw(t_session *s) { int x;