update norme
This commit is contained in:
@@ -6,16 +6,17 @@
|
||||
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/17 18:58:42 by yantoine #+# #+# */
|
||||
/* Updated: 2025/02/17 21:44:07 by yantoine ### ########.fr */
|
||||
/* Updated: 2025/02/18 17:48:22 by yantoine ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "miniRT.h"
|
||||
|
||||
// Vérifie les intersections avec les sphères
|
||||
static bool checkShadowSphere(const t_ray shadowRay, float maxT, float epsilon,
|
||||
t_scene scene)
|
||||
static bool check_shadow_sphere(const t_ray shadow_ray, \
|
||||
float max_t, t_scene scene)
|
||||
{
|
||||
const float epsilon = 1e-3f;
|
||||
int i;
|
||||
t_vec3 dummy;
|
||||
float t;
|
||||
@@ -23,8 +24,8 @@ static bool checkShadowSphere(const t_ray shadowRay, float maxT, float epsilon,
|
||||
i = 0;
|
||||
while (i < scene.numSpheres)
|
||||
{
|
||||
t = intersectSphere(shadowRay, scene.spheres[i], &dummy);
|
||||
if (t > epsilon && t < maxT)
|
||||
t = intersectSphere(shadow_ray, scene.spheres[i], &dummy);
|
||||
if (t > epsilon && t < max_t)
|
||||
return (true);
|
||||
i++;
|
||||
}
|
||||
@@ -32,9 +33,10 @@ static bool checkShadowSphere(const t_ray shadowRay, float maxT, float epsilon,
|
||||
}
|
||||
|
||||
// Vérifie les intersections avec les plans
|
||||
static bool checkShadowPlane(const t_ray shadowRay, float maxT, float epsilon,
|
||||
t_scene scene)
|
||||
static bool check_shadow_plane(const t_ray shadow_ray, \
|
||||
float max_t, t_scene scene)
|
||||
{
|
||||
const float epsilon = 1e-3f;
|
||||
int i;
|
||||
t_vec3 dummy;
|
||||
float t;
|
||||
@@ -42,8 +44,8 @@ static bool checkShadowPlane(const t_ray shadowRay, float maxT, float epsilon,
|
||||
i = 0;
|
||||
while (i < scene.numPlanes)
|
||||
{
|
||||
t = intersectPlane(shadowRay, scene.planes[i], &dummy);
|
||||
if (t > epsilon && t < maxT)
|
||||
t = intersectPlane(shadow_ray, scene.planes[i], &dummy);
|
||||
if (t > epsilon && t < max_t)
|
||||
return (true);
|
||||
i++;
|
||||
}
|
||||
@@ -51,9 +53,10 @@ static bool checkShadowPlane(const t_ray shadowRay, float maxT, float epsilon,
|
||||
}
|
||||
|
||||
// Vérifie les intersections avec les cylindres
|
||||
static bool checkShadowCylinder(const t_ray shadowRay, float maxT,
|
||||
float epsilon, t_scene scene)
|
||||
static bool check_shadow_cylinder(const t_ray shadow_ray, \
|
||||
float max_t, t_scene scene)
|
||||
{
|
||||
const float epsilon = 1e-3f;
|
||||
int i;
|
||||
t_vec3 dummy;
|
||||
float t;
|
||||
@@ -61,8 +64,8 @@ static bool checkShadowCylinder(const t_ray shadowRay, float maxT,
|
||||
i = 0;
|
||||
while (i < scene.numCylinders)
|
||||
{
|
||||
t = intersectCylinder(shadowRay, scene.cylinders[i], &dummy);
|
||||
if (t > epsilon && t < maxT)
|
||||
t = intersectCylinder(shadow_ray, scene.cylinders[i], &dummy);
|
||||
if (t > epsilon && t < max_t)
|
||||
return (true);
|
||||
i++;
|
||||
}
|
||||
@@ -70,24 +73,24 @@ static bool checkShadowCylinder(const t_ray shadowRay, float maxT,
|
||||
}
|
||||
|
||||
// Fonction principale qui détermine si le point est dans l'ombre
|
||||
bool isInShadow(t_vec3 hitPoint, t_vec3 lightPos, t_scene scene)
|
||||
bool is_in_shadow(t_vec3 hitPoint, t_vec3 lightPos, t_scene scene)
|
||||
{
|
||||
const float epsilon = 1e-3f;
|
||||
t_vec3 toLight;
|
||||
float maxT;
|
||||
t_vec3 L;
|
||||
t_ray shadowRay;
|
||||
t_vec3 to_light;
|
||||
float max_t;
|
||||
t_vec3 l;
|
||||
t_ray shadow_ray;
|
||||
|
||||
toLight = vec3_sub(lightPos, hitPoint);
|
||||
maxT = vec3_length(toLight);
|
||||
L = vec3_normalize(toLight);
|
||||
shadowRay.origin = vec3_add(hitPoint, vec3_scale(L, epsilon));
|
||||
shadowRay.dir = L;
|
||||
if (checkShadowSphere(shadowRay, maxT, epsilon, scene))
|
||||
to_light = vec3_sub(lightPos, hitPoint);
|
||||
max_t = vec3_length(to_light);
|
||||
l = vec3_normalize(to_light);
|
||||
shadow_ray.origin = vec3_add(hitPoint, vec3_scale(l, epsilon));
|
||||
shadow_ray.dir = l;
|
||||
if (check_shadow_sphere(shadow_ray, max_t, scene))
|
||||
return (true);
|
||||
if (checkShadowPlane(shadowRay, maxT, epsilon, scene))
|
||||
if (check_shadow_plane(shadow_ray, max_t, scene))
|
||||
return (true);
|
||||
if (checkShadowCylinder(shadowRay, maxT, epsilon, scene))
|
||||
if (check_shadow_cylinder(shadow_ray, max_t, scene))
|
||||
return (true);
|
||||
return (false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user