From cf569224e01f50088569265379faf9dc1cea732c Mon Sep 17 00:00:00 2001 From: hasufell Date: Sat, 10 May 2014 21:05:08 +0200 Subject: [PATCH] Move some functions from gl_draw to half_edge find_center() and get_normalized_scale_factor() are not really related to drawing in it's own, but are operation related to the HE_* structures --- src/gl_draw.c | 66 ------------------------------------------------- src/half_edge.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++ src/half_edge.h | 2 ++ 3 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/gl_draw.c b/src/gl_draw.c index 6705a56..3eefb6a 100644 --- a/src/gl_draw.c +++ b/src/gl_draw.c @@ -61,74 +61,8 @@ static void draw_obj(uint32_t xrot, uint32_t yrot, uint32_t zrot); static void draw_Planet_1(void); static void draw_Planet_2(void); static void gl_destroy(void); -static HE_vert *find_center(HE_obj const * const obj); -static float get_normalized_scale_factor(HE_obj const * const obj); -/** - * Calculates the factor that can be used to scaled down the object - * to the size of 1. - * - * @param obj the object we want to scale - * @return the corresponding scale factor - */ -static float get_normalized_scale_factor(HE_obj const * const obj) -{ - float max = obj->vertices[0].x + - obj->vertices[0].y + obj->vertices[0].z; - float min = obj->vertices[0].x + - obj->vertices[0].y + obj->vertices[0].z; - - uint32_t i; - - for (i = 0; i < obj->vc; i++) { - if ((obj->vertices[i].x + - obj->vertices[i].y + - obj->vertices[i].z) > max) - max = obj->vertices[i].x + - obj->vertices[i].y + - obj->vertices[i].z; - else if ((obj->vertices[i].x + - obj->vertices[i].y + - obj->vertices[i].z) < min) - min = obj->vertices[i].x + - obj->vertices[i].y + - obj->vertices[i].z; - } - - return 1 / (max - min); -} - -/** - * Find the center of an object and store the coordinates - * in a HE_vert struct. - * - * @param obj the object we want to find the center of - * @return newly allocated HE_vert with empty edge member - * and coordinates which represent the middle of the object - */ -static HE_vert *find_center(HE_obj const * const obj) -{ - float x = 0, - y = 0, - z = 0; - uint32_t i; - HE_vert *newvert = malloc(sizeof(HE_vert)); - - for (i = 0; i < obj->vc; i++) { - x += obj->vertices[i].x; - y += obj->vertices[i].y; - z += obj->vertices[i].z; - } - - newvert->x = x / i; - newvert->y = y / i; - newvert->z = z / i; - newvert->edge = NULL; - - return newvert; -} - /** * Call glVertex3f on all of the vertices of the object, * in appropriate order. diff --git a/src/half_edge.c b/src/half_edge.c index 93bef5b..c6520e9 100644 --- a/src/half_edge.c +++ b/src/half_edge.c @@ -45,6 +45,70 @@ HE_edge **get_all_emanating_edges(HE_vert *vertice) return NULL; } +/** + * Find the center of an object and store the coordinates + * in a HE_vert struct. + * + * @param obj the object we want to find the center of + * @return newly allocated HE_vert with empty edge member + * and coordinates which represent the middle of the object + */ +HE_vert *find_center(HE_obj const * const obj) +{ + float x = 0, + y = 0, + z = 0; + uint32_t i; + HE_vert *newvert = malloc(sizeof(HE_vert)); + + for (i = 0; i < obj->vc; i++) { + x += obj->vertices[i].x; + y += obj->vertices[i].y; + z += obj->vertices[i].z; + } + + newvert->x = x / i; + newvert->y = y / i; + newvert->z = z / i; + newvert->edge = NULL; + + return newvert; +} + +/** + * Calculates the factor that can be used to scaled down the object + * to the size of 1. + * + * @param obj the object we want to scale + * @return the corresponding scale factor + */ +float get_normalized_scale_factor(HE_obj const * const obj) +{ + float max = obj->vertices[0].x + + obj->vertices[0].y + obj->vertices[0].z; + float min = obj->vertices[0].x + + obj->vertices[0].y + obj->vertices[0].z; + + uint32_t i; + + for (i = 0; i < obj->vc; i++) { + if ((obj->vertices[i].x + + obj->vertices[i].y + + obj->vertices[i].z) > max) + max = obj->vertices[i].x + + obj->vertices[i].y + + obj->vertices[i].z; + else if ((obj->vertices[i].x + + obj->vertices[i].y + + obj->vertices[i].z) < min) + min = obj->vertices[i].x + + obj->vertices[i].y + + obj->vertices[i].z; + } + + return 1 / (max - min); +} + /** * Parse an .obj string and return a HE_obj * that represents the whole object. diff --git a/src/half_edge.h b/src/half_edge.h index c64f6d2..0ff9f10 100644 --- a/src/half_edge.h +++ b/src/half_edge.h @@ -124,6 +124,8 @@ struct HE_obj { HE_edge **get_all_emanating_edges(HE_vert *vertice); +HE_vert *find_center(HE_obj const * const obj); +float get_normalized_scale_factor(HE_obj const * const obj); HE_obj *parse_obj(char const * const filename);