diff options
Diffstat (limited to 'src/parse.c')
| -rw-r--r-- | src/parse.c | 55 |
1 files changed, 43 insertions, 12 deletions
diff --git a/src/parse.c b/src/parse.c index 6f632d6..ca3747c 100644 --- a/src/parse.c +++ b/src/parse.c @@ -6,13 +6,13 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/05/09 11:02:00 by charles #+# #+# */ -/* Updated: 2020/05/12 18:38:56 by charles ### ########.fr */ +/* Updated: 2020/05/13 10:15:43 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include "scop.h" -#define SCOP_VEC_DEFAULT_SIZE 64 +#define SCOP_VEC_DEFAULT_SIZE 2048 static void *st_iter_func_decrement_uint(void *void_uint) { @@ -32,8 +32,6 @@ static int st_parse_face(char **indexes_strs, t_ftvec *indices) len = ft_strslen(indexes_strs); first = ft_atoi(indexes_strs[0]); - /* if (ft_vecpush(indices, *(void**)&first) == NULL) */ - /* return (-1); */ i = 1; while (i < len - 1) { @@ -60,6 +58,45 @@ static int st_parse_vertex(char **positions_strs, t_ftvec *vertices) ft_vecpush(vertices, *((void**)&tmp)); tmp = ft_atof(positions_strs[2]); ft_vecpush(vertices, *((void**)&tmp)); + if (positions_strs[3] != NULL) + { + tmp = ft_atof(positions_strs[3]); + ft_vecpush(vertices, *((void**)&tmp)); + } + else + { + tmp = 1.0f; + ft_vecpush(vertices, *((void**)&tmp)); + } + return (0); +} + +static int st_parse_texture_coord(char **coord_strs, t_ftvec *coords) +{ + float tmp; + + tmp = ft_atof(coord_strs[0]); + ft_vecpush(coords, *((void**)&tmp)); + if (coord_strs[1] != NULL) + { + tmp = ft_atof(coord_strs[1]); + ft_vecpush(coords, *((void**)&tmp)); + } + else + { + tmp = 0.0f; + ft_vecpush(coords, *((void**)&tmp)); + } + if (ft_strslen(coord_strs) == 3) + { + tmp = ft_atof(coord_strs[2]); + ft_vecpush(coords, *((void**)&tmp)); + } + else + { + tmp = 0.0f; + ft_vecpush(coords, *((void**)&tmp)); + } return (0); } @@ -68,7 +105,7 @@ static int st_parse_line(char *line, t_ftvec *vertices, t_ftvec *indices) int ret; char **split; - if (*line != 'v' && *line != 'f') + if (!ft_strnequ(line, "v ", 2) && !ft_strnequ(line, "f ", 2)) return (0); if ((split = ft_split(line + 1, ' ')) == NULL) return (-1); @@ -88,21 +125,15 @@ static int st_parse_file(int fd, t_ftvec *vertices, t_ftvec *indices) while ((ret = ft_getline(fd, &line)) == FT_LINE) { - printf("[%s]\n", line); ret = st_parse_line(line, vertices, indices); free(line); if (ret == -1) break ; } - printf(">>%d\n", ret); - printf("[%s]\n", line); if (ret == FT_ERROR) return (-1); if (*line != '\0') - { - free(line); - return (-1); - } + ret = -1; free(line); return (0); } |
