diff --git a/src/Makefile b/src/Makefile index 4a8406e..3203241 100644 --- a/src/Makefile +++ b/src/Makefile @@ -15,8 +15,8 @@ CFLAGS += -O0 -g3 endif TARGET = drow-engine -HEADERS = err.h parser.h types.h print.h filereader.h gl_draw.h -OBJECTS = main.o parser.o print.o filereader.o gl_draw.o +HEADERS = err.h parser.h types.h print.h filereader.h gl_draw.h vec_math.h +OBJECTS = main.o parser.o print.o filereader.o gl_draw.o vec_math.c INCS = -I. CFLAGS += $(shell $(PKG_CONFIG) --cflags gl glu glib-2.0) diff --git a/src/print.c b/src/print.c index 8c5c856..7a80078 100644 --- a/src/print.c +++ b/src/print.c @@ -92,3 +92,19 @@ void print_plain_faces(FACE face, uint32_t fc) } printf("\n"); } + +/** + * Print all coordinates of a vector. + * + * @param the vector we want to print + */ +void print_vector(vector *vec) +{ + printf("vector:\n" + "x %f\n" + "y %f\n" + "z %f\n\n", + vec->x, + vec->y, + vec->z); +} diff --git a/src/print.h b/src/print.h index b23ae7c..bed9ee9 100644 --- a/src/print.h +++ b/src/print.h @@ -27,6 +27,7 @@ void print_edges(HE_obj *obj); void print_vertices(HE_obj *obj); void print_faces(HE_obj *obj); void print_plain_faces(FACE face, uint32_t fc); +void print_vector(vector *vec); #endif /* _DROW_ENGINE_PRINT_H */ diff --git a/src/types.h b/src/types.h index adca994..d61637d 100644 --- a/src/types.h +++ b/src/types.h @@ -30,11 +30,21 @@ typedef uint32_t** FACE; +typedef struct vector vector; 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 vector with x, y, z coordinates. + */ +struct vector { + float x; + float y; + float z; +}; + /** * Represents a half-edge. */ diff --git a/src/vec_math.c b/src/vec_math.c new file mode 100644 index 0000000..afb277d --- /dev/null +++ b/src/vec_math.c @@ -0,0 +1,45 @@ +/* + * 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 . + */ + +#include "err.h" +#include "types.h" + +#include +#include + + +/** + * Calculate the vector product of a and b + * and store it in c. + * + * @param a vector + * @param b vector + * @param c vector [out] + * @return true/false for success/failure + */ +bool vector_product(vector *a, vector *b, vector *c) +{ + if (!a || !b) + return false; + + c->x = a->y * b->z - a->z * b->y; + c->y = a->z * b->x - a->x * b->z; + c->z = a->x * b->y - a->y * b->x; + + return true; +} diff --git a/src/vec_math.h b/src/vec_math.h new file mode 100644 index 0000000..dc51450 --- /dev/null +++ b/src/vec_math.h @@ -0,0 +1,31 @@ +/* + * 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 . + */ + +#ifndef _DROW_ENGINE_VEC_MATH_H +#define _DROW_ENGINE_VEC_MATH_H + + +#include "types.h" + +#include + + +bool vector_product(vector *a, vector *b, vector *c); + + +#endif /* _DROW_ENGINE_VEC_MATH_H */