From 9dc326eaf13b4088528dfc682fcf0737e2f60351 Mon Sep 17 00:00:00 2001 From: Yannis Antoine Date: Wed, 5 Mar 2025 14:26:55 +0100 Subject: [PATCH] mise a la norme --- intersect_objects.c | 8 ++++---- main.c | 10 ++++++---- parsing_cylinder_utils.c | 20 ++++++++++---------- parsing_plane.c | 6 +++--- parsing_sphere.c | 6 +++--- shadows.c | 10 +++++----- 6 files changed, 31 insertions(+), 29 deletions(-) diff --git a/intersect_objects.c b/intersect_objects.c index 4e98b29..6fc449a 100644 --- a/intersect_objects.c +++ b/intersect_objects.c @@ -6,7 +6,7 @@ /* By: yantoine +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/19 16:07:55 by yantoine #+# #+# */ -/* Updated: 2025/02/19 16:47:28 by yantoine ### ########.fr */ +/* Updated: 2025/03/05 14:19:33 by yantoine ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,7 +25,7 @@ static bool intersect_spheres(const t_ray ray, t_hit *hit, t_sphere *spheres, while (i < num_spheres) { t = intersect_sphere(ray, spheres[i], &n); - if (t > 1e-3f && t < hit->t) + if (t > 0.001f && t < hit->t) { hit->t = t; hit->normal = n; @@ -50,7 +50,7 @@ static bool intersect_planes(const t_ray ray, t_hit *hit, t_plane *planes, while (i < num_planes) { t = intersect_plane(ray, planes[i], &n); - if (t > 1e-3f && t < hit->t) + if (t > 0.001f && t < hit->t) { hit->t = t; hit->normal = n; @@ -75,7 +75,7 @@ static bool intersect_cylinders(const t_ray ray, t_hit *hit, while (i < num_cylinders) { t = intersect_cylinder(ray, cylinders[i], &n); - if (t > 1e-3f && t < hit->t) + if (t > 0.001f && t < hit->t) { hit->t = t; hit->normal = n; diff --git a/main.c b/main.c index b5f7337..775addc 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,7 @@ /* By: yantoine +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/17 19:54:03 by yantoine #+# #+# */ -/* Updated: 2025/02/25 14:52:51 by yantoine ### ########.fr */ +/* Updated: 2025/03/05 14:14:09 by yantoine ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,10 +17,12 @@ static int init_app_config(t_app *app, int argc, char **argv) t_scene scene; if (argc > 1) + { scene = load_config(argv[1]); - app->win_width = WIDTH; - app->win_height = HEIGHT; - app->scene = scene; + app->win_width = WIDTH; + app->win_height = HEIGHT; + app->scene = scene; + } return (0); } diff --git a/parsing_cylinder_utils.c b/parsing_cylinder_utils.c index 6996643..3f06d6b 100644 --- a/parsing_cylinder_utils.c +++ b/parsing_cylinder_utils.c @@ -6,7 +6,7 @@ /* By: yantoine +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/17 18:54:45 by yantoine #+# #+# */ -/* Updated: 2025/02/19 16:59:10 by yantoine ### ########.fr */ +/* Updated: 2025/03/05 14:23:21 by yantoine ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,13 +40,13 @@ int init_intersection(t_ray ray, t_cylinder cy, t_calc *calc) void compute_side_intersection(t_cylinder cy, t_calc *calc) { calc->t_side = -1; - if (calc->t0 > 1e-3f) + if (calc->t0 > 0.001f) { calc->y = calc->oc_dot_v + calc->t0 * calc->d_dot_v; if (fabs(calc->y) <= cy.height / 2.0f) calc->t_side = calc->t0; } - if (calc->t_side < 0 && calc->t1 > 1e-3f) + if (calc->t_side < 0 && calc->t1 > 0.001f) { calc->y = calc->oc_dot_v + calc->t1 * calc->d_dot_v; if (fabs(calc->y) <= cy.height / 2.0f) @@ -59,10 +59,10 @@ void compute_side_intersection(t_cylinder cy, t_calc *calc) void compute_cap_intersection(t_ray ray, t_cylinder cy, t_calc *calc) { calc->t_cap = -1; - if (fabs(calc->d_dot_v) > 1e-6f) + if (fabs(calc->d_dot_v) > 0.001f) { calc->t_bot = ((-cy.height / 2.0f) - calc->oc_dot_v) / calc->d_dot_v; - if (calc->t_bot > 1e-3f) + if (calc->t_bot > 0.001f) { calc->p = vec3_add(ray.origin, vec3_scale(calc->d, calc->t_bot)); calc->cp = vec3_sub(calc->p, cy.center); @@ -72,7 +72,7 @@ void compute_cap_intersection(t_ray ray, t_cylinder cy, t_calc *calc) calc->t_cap = calc->t_bot; } calc->t_top = ((cy.height / 2.0f) - calc->oc_dot_v) / calc->d_dot_v; - if (calc->t_top > 1e-3f) + if (calc->t_top > 0.001f) { calc->p = vec3_add(ray.origin, vec3_scale(calc->d, calc->t_top)); calc->cp = vec3_sub(calc->p, cy.center); @@ -89,18 +89,18 @@ void compute_cap_intersection(t_ray ray, t_cylinder cy, t_calc *calc) //proche entre la surface latérale et les capuchons float select_final_intersection(t_calc *calc) { - if (calc->t_side > 1e-3f && calc->t_cap > 1e-3f) + if (calc->t_side > 0.001f && calc->t_cap > 0.001f) { if (calc->t_side < calc->t_cap) calc->t_final = calc->t_side; else calc->t_final = calc->t_cap; } - else if (calc->t_side > 1e-3f) + else if (calc->t_side > 0.001f) calc->t_final = calc->t_side; else calc->t_final = calc->t_cap; - if (calc->t_final > 1e-3f) + if (calc->t_final > 0.001f) return (calc->t_final); return (-1); } @@ -112,7 +112,7 @@ void compute_hit_normal(t_ray ray, t_cylinder cy, t_calc *calc, calc->hit_point = vec3_add(ray.origin, vec3_scale(calc->d, calc->t_final)); calc->cp = vec3_sub(calc->hit_point, cy.center); calc->proj = vec3_dot(calc->cp, calc->v); - if (fabs(calc->proj) < cy.height / 2.0f - 1e-3f) + if (fabs(calc->proj) < cy.height / 2.0f - 0.001f) { calc->n = vec3_sub(calc->cp, vec3_scale(calc->v, calc->proj)); *hitNormal = vec3_normalize(calc->n); diff --git a/parsing_plane.c b/parsing_plane.c index 60e2a99..a9b8734 100644 --- a/parsing_plane.c +++ b/parsing_plane.c @@ -6,7 +6,7 @@ /* By: yantoine +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/15 19:49:41 by yantoine #+# #+# */ -/* Updated: 2025/02/19 16:50:10 by yantoine ### ########.fr */ +/* Updated: 2025/03/05 14:24:37 by yantoine ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,10 +33,10 @@ float intersect_plane(t_ray ray, t_plane p, t_vec3 *hitNormal) float t; denom = vec3_dot(p.normal, ray.dir); - if (fabs(denom) < 1e-6f) + if (fabs(denom) < 0.000001f) return (-1); t = vec3_dot(vec3_sub(p.point, ray.origin), p.normal) / denom; - if (t < 1e-3f) + if (t < 0.001f) return (-1); *hitNormal = p.normal; return (t); diff --git a/parsing_sphere.c b/parsing_sphere.c index e09b5cf..b953c26 100644 --- a/parsing_sphere.c +++ b/parsing_sphere.c @@ -6,7 +6,7 @@ /* By: yantoine +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/15 19:46:16 by yantoine #+# #+# */ -/* Updated: 2025/02/19 16:59:34 by yantoine ### ########.fr */ +/* Updated: 2025/03/05 14:25:32 by yantoine ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,11 +40,11 @@ float intersect_sphere(t_ray ray, t_sphere s, t_vec3 *hitNormal) calc.sqrt_disc = sqrtf(calc.disc); calc.t0 = (-calc.b - calc.sqrt_disc) / (2 * calc.a); calc.t1 = (-calc.b + calc.sqrt_disc) / (2 * calc.a); - if (calc.t0 > 1e-3f) + if (calc.t0 > 0.001f) calc.t = calc.t0; else calc.t = calc.t1; - if (calc.t < 1e-3f) + if (calc.t < 0.001f) return (-1); calc.hit_point = vec3_add(ray.origin, vec3_scale(ray.dir, calc.t)); *hitNormal = vec3_normalize(vec3_sub(calc.hit_point, s.center)); diff --git a/shadows.c b/shadows.c index 8dd5d95..13decfd 100644 --- a/shadows.c +++ b/shadows.c @@ -6,7 +6,7 @@ /* By: yantoine +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/17 18:58:42 by yantoine #+# #+# */ -/* Updated: 2025/02/19 16:50:54 by yantoine ### ########.fr */ +/* Updated: 2025/03/05 14:26:08 by yantoine ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,7 @@ static bool check_shadow_sphere(const t_ray shadow_ray, float max_t, t_scene scene) { - const float epsilon = 1e-3f; + const float epsilon = 0.001f; int i; t_vec3 dummy; float t; @@ -36,7 +36,7 @@ static bool check_shadow_sphere(const t_ray shadow_ray, float max_t, static bool check_shadow_plane(const t_ray shadow_ray, float max_t, t_scene scene) { - const float epsilon = 1e-3f; + const float epsilon = 0.001f; int i; t_vec3 dummy; float t; @@ -56,7 +56,7 @@ static bool check_shadow_plane(const t_ray shadow_ray, float max_t, static bool check_shadow_cylinder(const t_ray shadow_ray, float max_t, t_scene scene) { - const float epsilon = 1e-3f; + const float epsilon = 0.001f; int i; t_vec3 dummy; float t; @@ -75,7 +75,7 @@ static bool check_shadow_cylinder(const t_ray shadow_ray, float max_t, // Fonction principale qui détermine si le point est dans l'ombre bool is_in_shadow(t_vec3 hitPoint, t_vec3 lightPos, t_scene scene) { - const float epsilon = 1e-3f; + const float epsilon = 0.001f; t_vec3 to_light; float max_t; t_vec3 l;