t_obj *inter(t_scene *s, t_vector3f ray_d, t_vector3f ray_o, t_vector3f *i) { float t; float t2; t_objl *tmpl; t_obj *obj; t_vector3f tmp[2]; tmpl = s->objl; t = -1; obj = NULL; while (tmpl) { add_cam(&tmpl->obj, ray_d, ray_o); tmp[0] = tmpl->obj->cam->pos; tmp[1] = tmpl->obj->cam->ray; t2 = s->tab_type[tmpl->obj->type](tmp[0], *tmpl->obj, tmp[1]); if (t2 > 0 && (t2 < t || t == -1)) { t = t2; obj = tmpl->obj; } tmpl = tmpl->next; } return (get_inter(obj, t, i, ray_o)); }
void int_quad(t_inter *pt, void *e, t_ray ray, t_light *light) { t_quad quad; double t; t_vec inter; quad = *((t_quad *)e); t = get_dist(ray, quad); if (t < 0) return ; if (pt->dist == NULL || *(pt->dist) > t) { if (pt->dist == NULL) pt->dist = malloc(sizeof(double)); free_info(pt); *(pt->dist) = t; inter = get_inter(ray, t); pt->normal = get_normal_quad(inter, quad); if (scalar_prod(pt->normal, ray.dir) > 0) pt->normal = mult_scalar(pt->normal, -1); pt->refl = get_refl(ray, pt->normal); pt->color = quad.color; pt->inter = inter; get_info(pt, light, inter); } }