t_vec3 parse_vector(char *line) { int i; int n; char **split; t_vec3 vec3; i = 0; n = 0; vec3 = (t_vec3) { 0, 0, 0 }; split = ft_strsplit(line, ' '); while (split[i] != NULL && n != 3) { str_digit(split[i]) == 1 ? n++ : 0; n == 1 ? vec3.x = ft_atof(split[i]) : 0; n == 2 ? vec3.y = ft_atof(split[i]) : 0; n == 3 ? vec3.z = ft_atof(split[i]) : 0; ft_strdel(&split[i]); i++; } ft_strdel(&split[i]); free(split); vec3_clamp(&vec3, MIN_POS, MAX_POS); return (vec3); }
static void load_tex(t_object *obj, const char *line) { if (obj->tex_buffer_size >= MAX_TEX) return ; line = ft_goto_next(line, ' '); obj->tex_buffer_data[obj->tex_buffer_size].u = ft_atof(line); line = ft_goto_next(line, ' '); obj->tex_buffer_data[obj->tex_buffer_size].v = ft_atof(line); ++obj->tex_buffer_size; }
void parsing_light(int fd, t_env *rt) { char *line; char **tab; int tmp; tmp = 0; while (get_next_line(fd, &line) > 0 && line[0] != '\0') { tab = split_tab(line); if (!ft_strcmp(tab[0], "pos")) rt->light[rt->i_light].center = new_vector(ft_atof(tab[2]), ft_atof(tab[3]), ft_atof(tab[4])); else if (!ft_strcmp(tab[0], "color")) { check_color(ft_atof(tab[2]), ft_atof(tab[3]), ft_atof(tab[4])); rt->light[rt->i_light].color.r = ft_atof(tab[2]); rt->light[rt->i_light].color.g = ft_atof(tab[3]); rt->light[rt->i_light].color.b = ft_atof(tab[4]); } else if (!ft_strcmp(tab[0], "parallel")) rt->light[rt->i_light].parallel = ft_atoi(tab[2]); tab_free(tab); ft_strdel(&line); } (tmp) ? (ft_strdel(&line)) : (0); rt->i_light++; }
static void load_normal(t_object *obj, const char *line) { if (obj->normal_buffer_size >= MAX_NORMAL) return ; line = ft_goto_next(line, ' '); obj->normal_buffer_data[obj->normal_buffer_size].x = ft_atof(line); line = ft_goto_next(line, ' '); obj->normal_buffer_data[obj->normal_buffer_size].y = ft_atof(line); line = ft_goto_next(line, ' '); obj->normal_buffer_data[obj->normal_buffer_size].z = ft_atof(line); ++obj->normal_buffer_size; }
static void load_vertex(t_object *obj, const char *line) { if (obj->vertex_buffer_size >= MAX_VERTEX) return ; line = ft_goto_next(line, ' '); obj->vertex_buffer_data[obj->vertex_buffer_size].x = ft_atof(line); line = ft_goto_next(line, ' '); obj->vertex_buffer_data[obj->vertex_buffer_size].y = ft_atof(line); line = ft_goto_next(line, ' '); obj->vertex_buffer_data[obj->vertex_buffer_size].z = ft_atof(line); ++obj->vertex_buffer_size; }
t_obj *sphere_data(t_obj *lst, char **tab, char *buf) { if (tab[0] == NULL || tab[1] == NULL || tab[2] == NULL || tab[3] == NULL || tab[4] == NULL || tab[5] == NULL || tab[6] == NULL) file_error("Parser error in scene file near : ", buf); lst->posx = ft_atof(tab[0]); lst->posy = ft_atof(tab[1]); lst->posz = ft_atof(tab[2]); lst->radius = ft_atof(tab[3]); lst->r = ft_atoi(tab[4]); lst->g = ft_atoi(tab[5]); lst->b = ft_atoi(tab[6]); return (lst); }
static double s_calcul(const char *s, size_t *i) { char sub[256]; size_t pos; double ret; if (s[*i] == '+') return (s_calcul(s, s_add_i(s, i))); else if (s[*i] == '-') return (-s_calcul(s, s_add_i(s, i))); else if (s[*i] == '(') { ret = sub_add_mod(s, s_add_i(s, i)); if (s[*i] == ')') s_add_i(s, i); } else { pos = *i; while ((ft_isdigit(s[*i]) || s[*i] == '.') && (sub[*i - pos] = s[*i])) s_add_i(s, i); sub[*i - pos] = '\0'; ret = ft_atof(sub); } return (ret); }
static void check_args(t_env *e, int ac, char **av) { e->check_int = 0; e->i = (e->color + e->stack_display); while (++e->i < ac) { e->j = -1; while (av[e->i][++e->j]) if ((ft_isdigit(av[e->i][e->j]) == 0) && (av[e->i][e->j] != '-')) error(e, 1); e->k = e->i; while (++e->k < ac) { if (ft_strcmp(av[e->k], av[e->i]) == 0) error(e, 1); if ((ft_strcmp(av[e->k], "0") == 0 && ft_strcmp(av[e->i], "-0") == 0) || (ft_strcmp(av[e->k], "-0") == 0 && ft_strcmp(av[e->i], "0") == 0)) error(e, 1); } e->check_int = ft_atof(av[e->i]); if (e->check_int > MAX_INT || e->check_int < MIN_INT) error(e, 1); } }
static char add_v_f(t_object *obj, char **tmp, char *last, int offset) { int res; char l; res = 1; l = *last; *last = tmp[0][0]; if (ft_strlen(tmp[0]) == 1 && tmp[0][0] == 'v') add_elem(&obj->vertex, new_vector3f(ft_atof(tmp[1]), ft_atof(tmp[2]), \ ft_atof(tmp[3]))); else if (tmp[0][0] == 'f') { put_indices(&obj->indices, ft_atoi(tmp[1]) - 1 - offset, ft_atoi(tmp[2]) - 1 - offset, \ ft_atoi(tmp[3]) - 1 - offset); if (ft_tabsize((void **)tmp) == 5) put_indices(&obj->indices, ft_atoi(tmp[3]) - 1 - offset, \ ft_atoi(tmp[4]) - 1 - offset, ft_atoi(tmp[1]) - 1 - offset); } else if (ft_strlen(tmp[0]) > 1 && tmp[0][0] == 'v' && tmp[0][1] == 'n') add_elem(&obj->normals, new_vector3f(ft_atof(tmp[1]), ft_atof(tmp[2]), \ ft_atof(tmp[3]))); else { *last = l; res = 0; } return (res); }
void parsing_camera(int fd, t_env *rt) { char *line; char **tab; int tmp; tmp = 0; while (get_next_line(fd, &line) > 0 && line[0] != '\0') { tmp = 1; tab = split_tab(line); if (!ft_strcmp(tab[0], "pos")) { rt->eye.x = ft_atof(tab[2]); rt->eye.y = ft_atof(tab[3]); rt->eye.z = ft_atof(tab[4]); } else if (!ft_strcmp(tab[0], "angle")) rt->cam_angle = new_vector(ft_atof(tab[2]), ft_atof(tab[3]), ft_atof(tab[4])); tab_free(tab); ft_strdel(&line); } if (tmp) ft_strdel(&line); }
int par_not_known(char *str, t_tok *tok) { int i; char val[64]; i = 0; while (str[i] && ft_strchr(CHARSET, str[i])) i++; tok->str = str; tok->size = i; ft_strncpy(val, str, i); val[i] = '\0'; tok->val = ft_atof(val); return (i ? NO_ERR : ERR_LEX); }
void rt_get_float(char *line, float *tab, size_t size) { int i; int j; char **tmp; if (line && tab) { i = 0; j = 1; tmp = ft_strsplit(line, ' '); while (tmp && tmp[j] && (tab[i] < size)) tab[i++] = ft_atof(tmp[j++]); } }
double get_number(char **tab_int) { double a; int i; a = 0; i = 0; // printf("Waiting for process... \n"); // sleep(4); while (tab_int[i]) { a = a + ft_atof(tab_int[i]); i++; } return (a); }
float polynomial_controller(t_terme *termes) { float exponent; char **splits; exponent = -1; splits = NULL; if (termes) splits = ft_strsplit(termes->b, '^'); if (splits && splits[0] && splits[1]) exponent = ft_atof(splits[1]); else if (splits && splits[0] && ft_strequ(splits[0], "X")) exponent = 1; else if (termes && !termes->b) exponent = 0; return (exponent); }
void hdl_val(t_dtab *token) { unsigned int i; i = 0; while (++i < token->size) { if (((t_tok *)token->data)[i].type == TOK_COEF && ((t_tok *)token->data)[i].str) ((t_tok *)token->data)[i].val = ft_atof(((t_tok *)token->data)[i].str); if (((t_tok *)token->data)[i].type == TOK_COEF && ((t_tok *)token->data)[i - 1].type == TOK_SIG) { if (((t_tok *)token->data)[i - 1].val == 1.0) ((t_tok *)token->data)[i].val *= -1; dtab_remove(token, i - 1); } } }
t_obj *cube_data(t_obj *lst, char **tab, char *buf) { if (tab[0] == NULL || tab[1] == NULL || tab[2] == NULL || tab[3] == NULL || tab[4] == NULL || tab[5] == NULL) file_error("Parser error in scene file near : ", buf); lst->posx = ft_atof(tab[0]); lst->posy = ft_atof(tab[1]); lst->posz = ft_atof(tab[2]); lst->height = ft_atof(tab[3]); lst->width = ft_atof(tab[4]); lst->depth = ft_atof(tab[5]); return (lst); }
int get_ants(t_env *e) { if (get_comments(e) == 0) { if (ft_strisdigit(e->line) != 0) { e->n_ants = ft_atof(e->line); if (e->n_ants < MIN_INT || e->n_ants > MAX_INT) return (-1); if (e->n_ants <= 0) return (-1); } else return (-1); e->n_read++; } else if (get_comments(e) == -1) return (1); return (0); }
t_obj *plane_data(t_obj *lst, char **tab, char *buf) { if (tab[0] == NULL || tab[1] == NULL || tab[2] == NULL || tab[3] == NULL || tab[4] == NULL || tab[5] == NULL || tab[6] == NULL || tab[7] == NULL || tab[8] == NULL) file_error("Parser error in scene file near : ", buf); lst->pos = new_vect(ft_atof(tab[0]), ft_atof(tab[1]), ft_atof(tab[2])); lst->nor = new_vect(ft_atof(tab[3]), ft_atof(tab[4]), ft_atof(tab[5])); norm_vect(lst->nor); lst->r = ft_atoi(tab[6]); lst->g = ft_atoi(tab[7]); lst->b = ft_atoi(tab[8]); return (lst); }
void fill_cam(t_overview *over, char *trim) { char **tab; tab = ft_strsplit(trim, ' '); if (count_tab(tab) < 7) { ft_putendl("Error cam parsing"); exit(0); } over->cam.x = ft_atof(tab[1]); over->cam.y = ft_atof(tab[2]); over->cam.w = ft_atof(tab[3]); over->dir.x = ft_atof(tab[4]); over->dir.y = ft_atof(tab[5]); over->dir.w = ft_atof(tab[6]); }