diff --git a/parser.c b/parser.c index 31f3e55..2dc5b20 100644 --- a/parser.c +++ b/parser.c @@ -33,6 +33,10 @@ * static function declarations */ static char *read_file(char const * const filename); +static void print_edges(HE_obj *obj); +static void print_vertices(HE_obj *obj); +static void print_faces(HE_obj *obj); +static void print_plain_faces(FACE face, uint8_t fc); /** @@ -52,6 +56,7 @@ HE_face *parse_obj(char const * const filename) const size_t vert_size = sizeof(HE_vert); HE_vert *vertices = malloc(vert_size), *vert_tmp; + HE_obj *obj = malloc(sizeof(HE_obj)); FACE face_v = NULL; /* read the whole file into string */ @@ -122,13 +127,11 @@ HE_face *parse_obj(char const * const filename) str_tmp_ptr = strtok_r(NULL, "\n", &str_ptr_newline); } - printf("vertices:\n"); - for (unsigned int i = 0; i < vc - 1; i++) { - printf("x[%d]: %f\n", i, vertices[i].x); - printf("y[%d]: %f\n", i, vertices[i].y); - printf("z[%d]: %f\n", i, vertices[i].z); - printf("\n"); - } + obj->vertices = vertices; + obj->vc = vc - 1; /* vc exceeds 1 after the loop */ + + print_plain_faces(face_v, fc); + print_vertices(obj); return NULL; } @@ -176,3 +179,39 @@ static char *read_file(char const * const filename) return NULL; } } + +static void print_edges(HE_obj *obj) +{ + +} + +static void print_vertices(HE_obj *obj) +{ + printf("vertices: %d\n", obj->vc); + for (unsigned int i = 0; i < obj->vc; i++) { + printf("x[%d]: %f\n", i, obj->vertices[i].x); + printf("y[%d]: %f\n", i, obj->vertices[i].y); + printf("z[%d]: %f\n", i, obj->vertices[i].z); + printf("\n"); + } +} + +static void print_faces(HE_obj *obj) +{ + +} + +static void print_plain_faces(FACE face, uint8_t fc) +{ + printf("plain faces:\n"); + for (uint8_t i = 0; i < fc - 1; i++) { + uint8_t j = 0; + printf("f:"); + while (face[i][j]) { + printf(" %d", face[i][j]); + j++; + } + printf("\n"); + } + printf("\n"); +} diff --git a/types.h b/types.h index 29415de..1b3c4f1 100644 --- a/types.h +++ b/types.h @@ -20,6 +20,9 @@ #define _DROW_ENGINE_TYPES_H +#include + + /** * Standard file buffer */ @@ -30,6 +33,7 @@ typedef unsigned int** FACE; typedef struct HE_edge HE_edge; typedef struct HE_vert HE_vert; typedef struct HE_face HE_face; +typedef struct HE_obj HE_obj; /** * Represents a half-edge. @@ -78,5 +82,37 @@ struct HE_face { HE_edge *edge; }; +/** + * Represents a collection of HE_edge, HE_vert and HE_face + * which are all attached to one object. This is useful + * for algorithms that need to iterate over one or another. + */ +struct HE_obj { + /** + * Array of edges. + */ + HE_edge *edges; + /** + * Array of vertices. + */ + HE_vert *vertices; + /** + * Array of faces. + */ + HE_face *faces; + /** + * Count of edges. + */ + uint8_t ec; + /** + * Count of vertices. + */ + uint8_t vc; + /** + * Count of faces. + */ + uint8_t fc; +}; + #endif /* _DROW_ENGINE_TYPES_H */