Add vec_math module
This commit is contained in:
parent
17a52c4b89
commit
9e7ff8dc4f
@ -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)
|
||||
|
16
src/print.c
16
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);
|
||||
}
|
||||
|
@ -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 */
|
||||
|
10
src/types.h
10
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.
|
||||
*/
|
||||
|
45
src/vec_math.c
Normal file
45
src/vec_math.c
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "err.h"
|
||||
#include "types.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
31
src/vec_math.h
Normal file
31
src/vec_math.h
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _DROW_ENGINE_VEC_MATH_H
|
||||
#define _DROW_ENGINE_VEC_MATH_H
|
||||
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
bool vector_product(vector *a, vector *b, vector *c);
|
||||
|
||||
|
||||
#endif /* _DROW_ENGINE_VEC_MATH_H */
|
Loading…
Reference in New Issue
Block a user