float *ft_lambert(t_th *mlx, t_obj *tmp, t_obj *light, float *tab) { t_vec pos; t_vec dist; float d; pos = (t_vec){mlx->cam_pos.x + mlx->t * mlx->ray_dir.x, mlx->cam_pos.y + mlx->t * mlx->ray_dir.y, mlx->cam_pos.z + mlx->t * mlx->ray_dir.z}; mlx->norm = ft_norm(mlx, tmp, pos); while (light != NULL) { LAMBERT = 0.15; dist = ft_vectorsub(&light->pos, &pos); d = ft_clamp((1.0 / sqrtf(sqrtf(ft_vectordot(&dist, &dist)))), 0., 1.); ft_vectornorm(&dist); if (ft_shadow(mlx, tmp, light, pos) == 0) LAMBERT += ft_clamp(ft_vectordot(&dist, &mlx->norm), 0.0, 1.0); tab = ft_endlight(tmp, light, tab, d); tab[0] += (COND2) ? ft_spec(mlx, dist, d, tab[3]) : 0.0; tab[1] += (COND2) ? ft_spec(mlx, dist, d, tab[3]) : 0.0; tab[2] += (COND2) ? ft_spec(mlx, dist, d, tab[3]) : 0.0; light = light->next; } mlx->refpos = (t_vec){mlx->ray_dir.x, mlx->ray_dir.y, mlx->ray_dir.z}; return ((PREF2) ? tab : ft_reflect(mlx, tmp, &pos, tab)); }
int get_next_line(int const fd, char **line) { int ret; char *temp; static char *save; char *buff; buff = ft_strnew(BUFF_SIZE + 1); save = (save == NULL) ? ft_strnew(1) : save; if (buff == NULL || BUFF_SIZE <= 0 || line == NULL) return (-1); ret = 42; while ((ft_strchr(save, '\n') == NULL) && ret > 0) { if ((ret = read(fd, buff, BUFF_SIZE)) == -1) return (-1); buff[ret] = '\0'; temp = save; save = ft_strjoin(save, buff); ft_strdel(&temp); } ft_norm(&buff, line, &save, ret); if (ret == 0 && *line[0] == '\0') return (0); save = ft_stock(save); return (1); }
static t_obj *ft_ref_init(t_th *mlx, t_obj *tmp, t_vec *pos) { t_obj *tmp2; mlx->t = 8000.0; mlx->ref = ft_vectorscale(&mlx->norm, (2 * ft_vectordot(&mlx->refpos, &mlx->norm))); mlx->ref = ft_vectorsub(&mlx->refpos, &mlx->ref); ft_vectornorm(&mlx->ref); tmp2 = ft_ref_inter(mlx, mlx->obj, tmp, *pos); if (!tmp2) return (NULL); *pos = (t_vec){pos->x + mlx->t * mlx->ref.x, pos->y + mlx->t * mlx->ref.y, pos->z + mlx->t * mlx->ref.z}; mlx->refpos = (t_vec){mlx->ref.x, mlx->ref.y, mlx->ref.z}; mlx->norm = ft_norm(mlx, tmp2, *pos); return (tmp2); }
void ft_inis_5_1(t_env *e) { if (!(e->obj = malloc(sizeof(t_obj)))) ft_error("error : malloc failed"); e->obj->n = 's'; e->obj->ox = WIN_X / 2; e->obj->oy = WIN_Y / 2 - 200; e->obj->oz = 1200; e->obj->dx = 0; e->obj->dy = 0; e->obj->dz = 0; ft_norm(&e->obj->dx, &e->obj->dy, &e->obj->dz); e->obj->sz = 300; e->obj->r = 255; e->obj->g = 0; e->obj->b = 0; e->obj->next = NULL; ft_inis_5_2(e); }
void ft_inis_5_3(t_obj *obj2) { t_obj *obj3; if (!(obj3 = malloc(sizeof(t_obj)))) ft_error("error : malloc failed"); obj2->next = obj3; obj3->n = 'p'; obj3->ox = 0; obj3->oy = 100; obj3->oz = 5000; obj3->dx = 0; obj3->dy = 0; obj3->dz = 1; ft_norm(&obj3->dx, &obj3->dy, &obj3->dz); obj3->sz = 0; obj3->r = 105; obj3->g = 105; obj3->b = 105; obj3->next = NULL; ft_inis_5_4(obj3); }
void ft_inis_5_2(t_env *e) { t_obj *obj2; if (!(obj2 = malloc(sizeof(t_obj)))) ft_error("error : malloc failed"); e->obj->next = obj2; obj2->n = 'y'; obj2->ox = 1800; obj2->oy = 240; obj2->oz = 1900; obj2->dx = 0; obj2->dy = 1; obj2->dz = 0; ft_norm(&obj2->dx, &obj2->dy, &obj2->dz); obj2->sz = 200; obj2->r = 0; obj2->g = 255; obj2->b = 0; obj2->next = NULL; ft_inis_5_3(obj2); }
void ft_inis_5_4(t_obj *obj3) { t_obj *obj4; if (!(obj4 = malloc(sizeof(t_obj)))) ft_error("error : malloc failed"); obj3->next = obj4; obj4->n = 'c'; obj4->ox = 200; obj4->oy = 340; obj4->oz = 2000; obj4->dx = 1; obj4->dy = 1; obj4->dz = 0; ft_norm(&obj4->dx, &obj4->dy, &obj4->dz); obj4->sz = 0.3; obj4->szcos = cos(obj4->sz) * cos(obj4->sz); obj4->szsin = sin(obj4->sz * obj4->sz); obj4->r = 255; obj4->g = 165; obj4->b = 0; obj4->next = NULL; ft_inis_5_5(obj4); }