From 1a107b455b485e173ac418921e5d3586429c0eba Mon Sep 17 00:00:00 2001 From: hasufell Date: Sat, 31 May 2014 18:43:05 +0200 Subject: [PATCH] Allow to draw bezier curve (only the points) --- src/gl_draw.c | 31 ++++++++++++++++++++++++++++++- src/half_edge.c | 9 +++++++++ src/half_edge_AS.c | 3 +++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/gl_draw.c b/src/gl_draw.c index c5d3788..1570cbe 100644 --- a/src/gl_draw.c +++ b/src/gl_draw.c @@ -66,6 +66,7 @@ bool shademodel = true; /* * static function declaration */ +static void draw_bez(HE_obj const * const obj); static void draw_obj(int32_t const myxrot, int32_t const myyrot, int32_t const myzrot); @@ -188,6 +189,31 @@ static void draw_vertices(HE_obj const * const obj, glPopMatrix(); } +static void draw_bez(HE_obj const * const obj) +{ + uint32_t i = 0; + static float line_width = 2; + + glPushMatrix(); + + glLineWidth(line_width); + glColor3f(1.0, 0.0, 0.0); + + + while (i < obj->bzc) { + glBegin(GL_LINE_STRIP); + for (uint32_t j = 0; j <= obj->bez_curves[i].deg; j++) { + glVertex3f(obj->bez_curves[i].vec[j].x, + obj->bez_curves[i].vec[j].y, + obj->bez_curves[i].vec[j].z); + } + glEnd(); + i++; + } + + glPopMatrix(); +} + /** * Draws an object. @@ -234,7 +260,10 @@ static void draw_obj(int32_t const myxrot, if (show_normals) draw_normals(obj, 0); - draw_vertices(obj, false); + if (obj->ec != 0) + draw_vertices(obj, false); + + draw_bez(obj); glPopMatrix(); } diff --git a/src/half_edge.c b/src/half_edge.c index 79534d9..e477c5c 100644 --- a/src/half_edge.c +++ b/src/half_edge.c @@ -273,6 +273,15 @@ bool normalize_object(HE_obj *obj) obj->vertices[i].vec->z = obj->vertices[i].vec->z * scale_factor; } + for (uint32_t i = 0; i < obj->bzc; i++) { + for (uint32_t j = 0; j <= obj->bez_curves[i].deg; j++) { + obj->bez_curves[i].vec[j].x *= scale_factor; + obj->bez_curves[i].vec[j].y *= scale_factor; + obj->bez_curves[i].vec[j].z *= scale_factor; + } + i++; + } + return true; } diff --git a/src/half_edge_AS.c b/src/half_edge_AS.c index 7fb7e49..c21b2b6 100644 --- a/src/half_edge_AS.c +++ b/src/half_edge_AS.c @@ -535,6 +535,9 @@ HE_obj *parse_obj(char const * const obj_string) */ static void delete_accel_struct(HE_obj *he_obj) { + if (he_obj->ec == 0) + return; /* probably only a bezier curve */ + for (uint32_t i = 0; i < he_obj->vc; i++) { free(he_obj->vertices[i].acc->dummys); free(he_obj->vertices[i].acc->edge_array);