faire la norme

This commit is contained in:
H3XploR
2025-02-17 23:52:47 +01:00
parent 960a2ad8ae
commit c6c13573cb
20 changed files with 539 additions and 440 deletions
+67 -50
View File
@@ -13,64 +13,81 @@
#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) {
int i = 0;
t_vec3 dummy;
float t;
while (i < scene.numSpheres) {
t = intersectSphere(shadowRay, scene.spheres[i], &dummy);
if (t > epsilon && t < maxT)
return true;
i++;
}
return false;
static bool checkShadowSphere(const t_ray shadowRay, float maxT, float epsilon,
t_scene scene)
{
int i;
t_vec3 dummy;
float t;
i = 0;
while (i < scene.numSpheres)
{
t = intersectSphere(shadowRay, scene.spheres[i], &dummy);
if (t > epsilon && t < maxT)
return (true);
i++;
}
return (false);
}
// Vérifie les intersections avec les plans
static bool checkShadowPlane(const t_ray shadowRay, float maxT, float epsilon, t_scene scene) {
int i = 0;
t_vec3 dummy;
float t;
while (i < scene.numPlanes) {
t = intersectPlane(shadowRay, scene.planes[i], &dummy);
if (t > epsilon && t < maxT)
return true;
i++;
}
return false;
static bool checkShadowPlane(const t_ray shadowRay, float maxT, float epsilon,
t_scene scene)
{
int i;
t_vec3 dummy;
float t;
i = 0;
while (i < scene.numPlanes)
{
t = intersectPlane(shadowRay, scene.planes[i], &dummy);
if (t > epsilon && t < maxT)
return (true);
i++;
}
return (false);
}
// Vérifie les intersections avec les cylindres
static bool checkShadowCylinder(const t_ray shadowRay, float maxT, float epsilon, t_scene scene) {
int i = 0;
t_vec3 dummy;
float t;
while (i < scene.numCylinders) {
t = intersectCylinder(shadowRay, scene.cylinders[i], &dummy);
if (t > epsilon && t < maxT)
return true;
i++;
}
return false;
static bool checkShadowCylinder(const t_ray shadowRay, float maxT,
float epsilon, t_scene scene)
{
int i;
t_vec3 dummy;
float t;
i = 0;
while (i < scene.numCylinders)
{
t = intersectCylinder(shadowRay, scene.cylinders[i], &dummy);
if (t > epsilon && t < maxT)
return (true);
i++;
}
return (false);
}
// Fonction principale qui détermine si le point est dans l'ombre
bool isInShadow(t_vec3 hitPoint, t_vec3 lightPos, t_scene scene) {
const float epsilon = 1e-3f;
t_vec3 toLight = vec3_sub(lightPos, hitPoint);
float maxT = vec3_length(toLight);
t_vec3 L = vec3_normalize(toLight);
t_ray shadowRay;
shadowRay.origin = vec3_add(hitPoint, vec3_scale(L, epsilon));
shadowRay.dir = L;
bool isInShadow(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;
if (checkShadowSphere(shadowRay, maxT, epsilon, scene))
return true;
if (checkShadowPlane(shadowRay, maxT, epsilon, scene))
return true;
if (checkShadowCylinder(shadowRay, maxT, epsilon, scene))
return true;
return false;
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))
return (true);
if (checkShadowPlane(shadowRay, maxT, epsilon, scene))
return (true);
if (checkShadowCylinder(shadowRay, maxT, epsilon, scene))
return (true);
return (false);
}