|
*out_distance = (-eq.b - t_f_sqrt(discriminant)) / (2 * eq.a); |
|
if (*out_distance > 0) |
|
*out_is_front_face = true; |
|
else |
|
{ |
|
*out_distance = (-eq.b + t_f_sqrt(discriminant)) / (2 * eq.a); |
|
if (*out_distance < 0) |
|
return (false); |
|
*out_is_front_face = false; |
|
} |
|
static t_err front(t_vars l, t_ray ray, t_ray_hit_records_builder *builder) |
|
{ |
|
const t_f distance = (-l.y - l.sqrt_y2_4xz) / (2 * l.x); |
|
const t_map_position point |
|
= t_f3_add(ray.origin, t_f3_mul(ray.direction, distance)); |
|
t_map_normal normal; |
|
t_f coord_x; |
|
t_f coord_y; |
|
|
|
if (distance <= 0) |
|
return (false); |
|
normal = t_ray_primitive_ellipsoid_normal(l, point); |
|
t_ray_primitive_ellipsoid_coord(point, l.self.size, &coord_x, &coord_y); |
|
return ( |
|
t_ray_hit_records_builder_add(builder, (t_ray_hit_record){ |
|
distance, |
|
normal, |
|
t_ray_material_from_color(l.self.material), |
|
true, |
|
coord_x, |
|
coord_y, |
|
}) |
|
); |
|
} |
|
|
|
static t_err back(t_vars l, t_ray ray, t_ray_hit_records_builder *builder) |
|
{ |
|
const t_f distance = (-l.y + l.sqrt_y2_4xz) / (2 * l.x); |
|
const t_map_position point |
|
= t_f3_add(ray.origin, t_f3_mul(ray.direction, distance)); |
|
t_map_normal normal; |
|
t_f coord_x; |
|
t_f coord_y; |
|
|
|
normal = t_ray_primitive_ellipsoid_normal(l, point); |
|
t_ray_primitive_ellipsoid_coord(point, l.self.size, &coord_x, &coord_y); |
|
return ( |
|
t_ray_hit_records_builder_add(builder, (t_ray_hit_record){ |
|
distance, |
|
normal, |
|
t_ray_material_from_color(l.self.material), |
|
false, |
|
coord_x, |
|
coord_y, |
|
}) |
|
); |
|
} |
|
l.n_distance = (-a.y - a.sqrt_y2_4xz) / (2 * a.x); |
|
l.n = t_f3_add(ray.origin, t_f3_mul(ray.direction, l.n_distance)); |
|
l.n_hit = (l.n_distance >= 0 && l.n.z >= 0 && l.n.z <= a.self.size.z); |
|
if (l.n_hit) |
|
{ |
|
l.n_normal = t_ray_primitive_cylinder_side_normal(a, l.n); |
|
l.n_x = t_f_rot(t_f_atan2(l.n.y, l.n.x)); |
|
l.n_y = l.n.z / a.self.size.z; |
|
} |
|
l.f_distance = (-a.y + a.sqrt_y2_4xz) / (2 * a.x); |
|
l.n_distance = (-a.y - a.sqrt_y2_4xz) / (2 * a.x); |
|
l.n = t_f3_add(ray.origin, t_f3_mul(ray.direction, l.n_distance)); |
|
l.n_hit = (l.n_distance >= 0 && l.n.z >= 0 && l.n.z <= a.self.size.z); |
|
if (l.n_hit) |
|
{ |
|
l.n_normal = t_ray_primitive_cone_side_normal(a, l.n); |
|
l.n_x = t_f_rot(t_f_atan2(l.n.y, l.n.x)); |
|
l.n_y = l.n.z / a.self.size.z; |
|
} |
|
l.f_distance = (-a.y + a.sqrt_y2_4xz) / (2 * a.x); |
If eq.a (or l.x, a.x) is negative, near/far is flipped.
miniRT/src/t/ray/nearest/t_ray_nearest_quadric.c
Lines 79 to 88 in a286071
miniRT/src/t/ray/primitive/ellipsoid/t_ray_primitive_ellipsoid_outside.c
Lines 47 to 93 in a286071
miniRT/src/t/ray/primitive/cylinder/t_ray_primitive_cylinder_side.c
Lines 63 to 72 in a286071
miniRT/src/t/ray/primitive/cone/t_ray_primitive_cone_side.c
Lines 66 to 75 in a286071
If
eq.a(orl.x,a.x) is negative, near/far is flipped.