mise a la norme

This commit is contained in:
Yannis Antoine
2025-03-05 14:26:55 +01:00
parent 6d3aa4ade8
commit 9dc326eaf1
6 changed files with 31 additions and 29 deletions
+4 -4
View File
@@ -6,7 +6,7 @@
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
+3 -1
View File
@@ -6,7 +6,7 @@
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
}
return (0);
}
+10 -10
View File
@@ -6,7 +6,7 @@
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
+3 -3
View File
@@ -6,7 +6,7 @@
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
+3 -3
View File
@@ -6,7 +6,7 @@
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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));
+5 -5
View File
@@ -6,7 +6,7 @@
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;