Move bezier stuff to it's own module
This commit is contained in:
parent
af52bd4085
commit
ea8d08204c
@ -1,8 +1,8 @@
|
||||
include ../common.mk
|
||||
|
||||
TARGET = drow-engine
|
||||
HEADERS = err.h common.h print.h filereader.h gl_draw.h vector.h half_edge.h
|
||||
OBJECTS = print.o filereader.o gl_draw.o vector.o half_edge.o half_edge_AS.o
|
||||
HEADERS = err.h common.h print.h filereader.h gl_draw.h vector.h half_edge.h bezier.h
|
||||
OBJECTS = print.o filereader.o gl_draw.o vector.o half_edge.o half_edge_AS.o bezier.o
|
||||
INCS = -I.
|
||||
|
||||
CFLAGS += $(shell $(PKG_CONFIG) --cflags gl glu glib-2.0)
|
||||
|
70
src/bezier.c
Normal file
70
src/bezier.c
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2011-2014 hasufell
|
||||
*
|
||||
* This file is part of a hasufell project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation version 2 of the License only.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file bezier.c
|
||||
* This file provides operations and informational functions
|
||||
* on the bezier data type which is defined in bezier.h.
|
||||
* @brief operations on bezier curves
|
||||
*/
|
||||
|
||||
#include "bezier.h"
|
||||
#include "vector.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
/**
|
||||
* Calculate a point on the bezier curve according to the
|
||||
* bezier vertices. If section is set to 0.5 then it will
|
||||
* return the vector to the point in the middle of the curve.
|
||||
*
|
||||
* @param obj the object holding the bezier vertices information
|
||||
* @param section the section which will be applied to all
|
||||
* lines between the bezier vertices
|
||||
* @return the vector to the calculated point
|
||||
*/
|
||||
vector *calculate_bezier_point(bez_curv *bez, float section)
|
||||
{
|
||||
vector vec_arr[bez->deg];
|
||||
bez_curv new_bez;
|
||||
|
||||
for (uint32_t i = 0; i < bez->deg; i++) {
|
||||
vector new_vec;
|
||||
|
||||
SUB_VECTORS(&(bez->vec[i + 1]), &(bez->vec[i]), &new_vec);
|
||||
VECTOR_LEN_SCAL_MUL(&new_vec, section, &new_vec);
|
||||
ADD_VECTORS(&new_vec, &(bez->vec[i]), &new_vec);
|
||||
|
||||
vec_arr[i] = new_vec;
|
||||
}
|
||||
|
||||
new_bez.vec = vec_arr;
|
||||
new_bez.deg = bez->deg - 1;
|
||||
|
||||
if (new_bez.deg > 0) {
|
||||
return calculate_bezier_point(&new_bez, section);
|
||||
} else {
|
||||
vector *result_vector = malloc(sizeof(*result_vector));
|
||||
*result_vector = vec_arr[0];
|
||||
return result_vector;
|
||||
}
|
||||
}
|
||||
|
||||
|
55
src/bezier.h
Normal file
55
src/bezier.h
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2011-2014 hasufell
|
||||
*
|
||||
* This file is part of a hasufell project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation version 2 of the License only.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file bezier.h
|
||||
* Header for the external API of bezier.c.
|
||||
* @brief header of bezier.c
|
||||
*/
|
||||
|
||||
#ifndef _DROW_ENGINE_BEZIER_H
|
||||
#define _DROW_ENGINE_BEZIER_H
|
||||
|
||||
|
||||
#include "vector.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
typedef struct bez_curv bez_curv;
|
||||
|
||||
|
||||
/**
|
||||
* Bezier Curve.
|
||||
*/
|
||||
struct bez_curv {
|
||||
/**
|
||||
* Array of vectors.
|
||||
*/
|
||||
vector *vec;
|
||||
/**
|
||||
* Degree of the curve.
|
||||
*/
|
||||
uint32_t deg;
|
||||
};
|
||||
|
||||
|
||||
vector *calculate_bezier_point(bez_curv *bez, float section);
|
||||
|
||||
|
||||
#endif /* _DROW_ENGINE_BEZIER_H */
|
@ -24,6 +24,7 @@
|
||||
* @brief OpenGL drawing
|
||||
*/
|
||||
|
||||
#include "bezier.h"
|
||||
#include "err.h"
|
||||
#include "filereader.h"
|
||||
#include "gl_draw.h"
|
||||
|
@ -285,43 +285,6 @@ bool normalize_object(HE_obj *obj)
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate a point on the bezier curve according to the
|
||||
* bezier vertices. If section is set to 0.5 then it will
|
||||
* return the vector to the point in the middle of the curve.
|
||||
*
|
||||
* @param obj the object holding the bezier vertices information
|
||||
* @param section the section which will be applied to all
|
||||
* lines between the bezier vertices
|
||||
* @return the vector to the calculated point
|
||||
*/
|
||||
vector *calculate_bezier_point(bez_curv *bez, float section)
|
||||
{
|
||||
vector vec_arr[bez->deg];
|
||||
bez_curv new_bez;
|
||||
|
||||
for (uint32_t i = 0; i < bez->deg; i++) {
|
||||
vector new_vec;
|
||||
|
||||
SUB_VECTORS(&(bez->vec[i + 1]), &(bez->vec[i]), &new_vec);
|
||||
VECTOR_LEN_SCAL_MUL(&new_vec, section, &new_vec);
|
||||
ADD_VECTORS(&new_vec, &(bez->vec[i]), &new_vec);
|
||||
|
||||
vec_arr[i] = new_vec;
|
||||
}
|
||||
|
||||
new_bez.vec = vec_arr;
|
||||
new_bez.deg = bez->deg - 1;
|
||||
|
||||
if (new_bez.deg > 0) {
|
||||
return calculate_bezier_point(&new_bez, section);
|
||||
} else {
|
||||
vector *result_vector = malloc(sizeof(*result_vector));
|
||||
*result_vector = vec_arr[0];
|
||||
return result_vector;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Free the inner structures of an object.
|
||||
*
|
||||
|
@ -29,6 +29,7 @@
|
||||
#define _DROW_ENGINE_HE_OPERATIONS_H
|
||||
|
||||
|
||||
#include "bezier.h"
|
||||
#include "vector.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
@ -108,7 +109,6 @@ typedef struct HE_vert_acc HE_vert_acc;
|
||||
typedef struct HE_face HE_face;
|
||||
typedef struct HE_obj HE_obj;
|
||||
typedef struct color color;
|
||||
typedef struct bez_curv bez_curv;
|
||||
|
||||
|
||||
/**
|
||||
@ -303,20 +303,6 @@ struct color {
|
||||
double blue;
|
||||
};
|
||||
|
||||
/**
|
||||
* Bezier Curve.
|
||||
*/
|
||||
struct bez_curv {
|
||||
/**
|
||||
* Array of vectors.
|
||||
*/
|
||||
vector *vec;
|
||||
/**
|
||||
* Degree of the curve.
|
||||
*/
|
||||
uint32_t deg;
|
||||
};
|
||||
|
||||
|
||||
bool face_normal(HE_edge const * const edge,
|
||||
vector *vec);
|
||||
@ -324,7 +310,6 @@ bool vec_normal(HE_vert const * const vert, vector *vec);
|
||||
bool find_center(HE_obj const * const obj, vector *vec);
|
||||
float get_normalized_scale_factor(HE_obj const * const obj);
|
||||
bool normalize_object(HE_obj *obj);
|
||||
vector *calculate_bezier_point(bez_curv *bez, float section);
|
||||
HE_obj *parse_obj(char const * const filename);
|
||||
void delete_object(HE_obj *obj);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user