Implement various print functions, add HE_obj struct
This commit is contained in:
parent
1a2c9767ab
commit
4b04a66cf8
53
parser.c
53
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");
|
||||
}
|
||||
|
36
types.h
36
types.h
@ -20,6 +20,9 @@
|
||||
#define _DROW_ENGINE_TYPES_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
/**
|
||||
* 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 */
|
||||
|
Loading…
Reference in New Issue
Block a user