Allow to draw bezier curve (only the points)

This commit is contained in:
hasufell 2014-05-31 18:43:05 +02:00
parent cbbffc247b
commit 1a107b455b
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020
3 changed files with 42 additions and 1 deletions

View File

@ -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();
}

View File

@ -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;
}

View File

@ -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);