pudate miniRT.h nomr

This commit is contained in:
H3XploR
2025-02-19 16:53:36 +01:00
parent 4a67c6f905
commit d32c5bd01c
12 changed files with 134 additions and 120 deletions
+32 -32
View File
@@ -6,23 +6,23 @@
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/19 16:07:55 by yantoine #+# #+# */
/* Updated: 2025/02/19 16:16:52 by yantoine ### ########.fr */
/* Updated: 2025/02/19 16:47:28 by yantoine ### ########.fr */
/* */
/* ************************************************************************** */
#include "miniRT.h"
static bool intersect_spheres(const t_ray ray, t_hit *hit, t_sphere *spheres,
int numSpheres)
int num_spheres)
{
int i;
bool hitAny;
t_vec3 n;
bool hit_any;
t_vec3 n;
float t;
i = 0;
hitAny = false;
while (i < numSpheres)
hit_any = false;
while (i < num_spheres)
{
t = intersect_sphere(ray, spheres[i], &n);
if (t > 1e-3f && t < hit->t)
@@ -30,24 +30,24 @@ static bool intersect_spheres(const t_ray ray, t_hit *hit, t_sphere *spheres,
hit->t = t;
hit->normal = n;
hit->color = spheres[i].color;
hitAny = true;
hit_any = true;
}
i++;
}
return (hitAny);
return (hit_any);
}
static bool intersect_planes(const t_ray ray, t_hit *hit, t_plane *planes,
int numPlanes)
int num_planes)
{
int i;
bool hitAny;
t_vec3 n;
bool hit_any;
t_vec3 n;
float t;
i = 0;
hitAny = false;
while (i < numPlanes)
hit_any = false;
while (i < num_planes)
{
t = intersect_plane(ray, planes[i], &n);
if (t > 1e-3f && t < hit->t)
@@ -55,24 +55,24 @@ static bool intersect_planes(const t_ray ray, t_hit *hit, t_plane *planes,
hit->t = t;
hit->normal = n;
hit->color = planes[i].color;
hitAny = true;
hit_any = true;
}
i++;
}
return (hitAny);
return (hit_any);
}
static bool intersect_cylinders(const t_ray ray, t_hit *hit,
t_cylinder *cylinders, int numCylinders)
t_cylinder *cylinders, int num_cylinders)
{
int i;
bool hitAny;
t_vec3 n;
bool hit_any;
t_vec3 n;
float t;
i = 0;
hitAny = false;
while (i < numCylinders)
hit_any = false;
while (i < num_cylinders)
{
t = intersect_cylinder(ray, cylinders[i], &n);
if (t > 1e-3f && t < hit->t)
@@ -80,33 +80,33 @@ static bool intersect_cylinders(const t_ray ray, t_hit *hit,
hit->t = t;
hit->normal = n;
hit->color = cylinders[i].color;
hitAny = true;
hit_any = true;
}
i++;
}
return (hitAny);
return (hit_any);
}
bool intersect_objects(float *tMin, t_vec3 *hitNormal, t_vec3 *objColor,
t_scene scene)
{
t_hit hit;
bool hitFound;
bool hit_found;
hitFound = false;
hit_found = false;
hit.t = *tMin;
if (intersect_spheres(scene.ray, &hit, scene.spheres, scene.numSpheres))
hitFound = true;
if (intersect_planes(scene.ray, &hit, scene.planes, scene.numPlanes))
hitFound = true;
if (intersect_spheres(scene.ray, &hit, scene.spheres, scene.num_spheres))
hit_found = true;
if (intersect_planes(scene.ray, &hit, scene.planes, scene.num_planes))
hit_found = true;
if (intersect_cylinders(scene.ray, &hit, scene.cylinders,
scene.numCylinders))
hitFound = true;
if (hitFound)
scene.num_cylinders))
hit_found = true;
if (hit_found)
{
*tMin = hit.t;
*hitNormal = hit.normal;
*objColor = hit.color;
}
return (hitFound);
return (hit_found);
}