int ft_intersection(t_obj *obj, t_3d p_beg, t_3d v_ray) { static int init = 0; static t_inter tab_inter[4]; float coef; t_3d tmp; coef = -1; obj->distance = -1; if (init == 0) { ft_init_tab(tab_inter); init = 1; } coef = tab_inter[(int)obj->type].inter(obj, p_beg, v_ray); if (coef == -1) return (0); else { ft_init3d(&obj->p_inter, p_beg.x + v_ray.x * coef, p_beg.y + v_ray.y * coef, p_beg.z + v_ray.z * coef); ft_init3d(&tmp, obj->p_inter.x - p_beg.x, obj->p_inter.y - p_beg.y, obj->p_inter.z - p_beg.z); obj->distance = ft_norme(&tmp); } return (1); }
void lsort(t_env *e) { t_node *tmp; tmp = e->a->begin; if (tmp->data > tmp->next->data && tmp->next->data > tmp->next->next->data) ft_norme(e); else if (tmp->data > tmp->next->data && tmp->next->data < tmp->next->next->data && tmp->data < tmp->next->next->data) swap(e, 'a'); else if (tmp->data < tmp->next->data && tmp->next->data > tmp->next->next->data && tmp->data < tmp->next->next->data) { swap(e, 'a'); rotate(e, 'a'); } else if (tmp->data < tmp->next->data && tmp->next->data > tmp->next->next->data && tmp->data > tmp->next->next->data) reverse_rotate(e, 'a'); else if (tmp->data > tmp->next->data && tmp->next->data < tmp->next->next->data && tmp->data > tmp->next->next->data) rotate(e, 'a'); }
void normal_build_func(void *data) { DIR *dirp; struct dirent *info; t_data *fdata; t_tree *tmp; info = NULL; fdata = NULL; if ((print_head_or_dir(data) == 0)) return ; if (!(dirp = opendir((const char *)DATA->path))) return (perror(ft_strjoin("ft_ls: ", DATA->name))); while ((info = readdir(dirp)) != NULL) { if ((info->d_name)[0] != '.') { if (!(fdata = full_data(info, (t_data *)data))) return ; tmp = ft_create_node_tree((void *)fdata); DATA->tree = ft_addnode(DATA->tree, tmp, NULL, DATA->cmp); } } (void)closedir(dirp); ft_norme(data, 1); }
float ft_shadow(t_scene *scene, t_3d p_beg, t_3d v_ray, t_obj *obj) { t_ray ray; ray.o = obj; ray.p_beg = p_beg; ray.v_ray = v_ray; ray.obj = scene->object; ray.obj_hit = NULL; ray.ret = 0; ray.intersection = scene->intersection; ft_list_inter(&ray); ft_get_obj_hit(&ray, scene->object); if (ray.obj_hit != NULL && ray.obj_hit->distance < ft_norme(&v_ray)) { if (scene->transparency == 0 || ray.obj_hit->transparency == 0) return (0.); else return ((ray.obj_hit->transparency / 100.) * ft_shadow(scene, ray.obj_hit->p_inter, v_ray, ray.obj_hit)); } return (1); }