diff --git a/Makefile b/Makefile index fa4a16f..798b6fa 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: tsuchen +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2024/08/15 12:02:08 by tsuchen #+# #+# # -# Updated: 2024/08/27 11:36:32 by tsuchen ### ########.fr # +# Updated: 2024/08/27 13:58:10 by tsuchen ### ########.fr # # # # **************************************************************************** # @@ -22,7 +22,7 @@ SRCS_MAP = map.c SRCS_RC = raycasting.c -SRCS_VEC = vector.c +SRCS_VEC = vector.c vector_2.c PATH_M = srcs/ PATH_PS = srcs/parser/ diff --git a/includes/parser.h b/includes/parser.h index f07b421..9b46280 100644 --- a/includes/parser.h +++ b/includes/parser.h @@ -3,15 +3,16 @@ /* ::: :::::::: */ /* parser.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jteissie +#+ +:+ +#+ */ +/* By: tsuchen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/15 15:00:57 by jteissie #+# #+# */ -/* Updated: 2024/08/16 18:58:41 by jteissie ### ########.fr */ +/* Updated: 2024/08/27 14:00:34 by tsuchen ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef PARSER_H # define PARSER_H + # include "cub3d.h" typedef enum e_bool t_bool; diff --git a/includes/vector.h b/includes/vector.h index 03013fb..61a6d48 100644 --- a/includes/vector.h +++ b/includes/vector.h @@ -6,13 +6,17 @@ /* By: tsuchen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/27 10:56:32 by tsuchen #+# #+# */ -/* Updated: 2024/08/27 11:41:19 by tsuchen ### ########.fr */ +/* Updated: 2024/08/27 13:55:58 by tsuchen ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef VECTOR_H # define VECTOR_H +# include +# include +# include + typedef struct s_vec { double x; @@ -20,7 +24,14 @@ typedef struct s_vec } t_vec; void vec_init(t_vec *vec, double x, double y); +void vec_add(t_vec *vec_a, const t_vec *vec_b); +void vec_sub(t_vec *vec_a, const t_vec *vec_b); +void vec_muls(t_vec *vec, double scalar); +double vec_dot(const t_vec *vec_a, const t_vec *vec_b); +double vec_absv(const t_vec *vec); +double vec_dist(const t_vec *vec_a, const t_vec *vec_b); +void vec_mirror(t_vec *vec); +void vec_transp(t_vec *vec); void vec_rotate(t_vec *vec, double angle); -t_vec vec_dot(t_vec *vec_a, t_vec *vec_b); #endif diff --git a/srcs/vector/vector.c b/srcs/vector/vector.c index e55fbc0..eac9e4e 100644 --- a/srcs/vector/vector.c +++ b/srcs/vector/vector.c @@ -6,7 +6,7 @@ /* By: tsuchen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/27 11:11:34 by tsuchen #+# #+# */ -/* Updated: 2024/08/27 11:14:06 by tsuchen ### ########.fr */ +/* Updated: 2024/08/27 13:32:54 by tsuchen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,3 +17,29 @@ void vec_init(t_vec *vec, double x, double y) vec->x = x; vec->y = y; } + +void vec_add(t_vec *vec_a, const t_vec *vec_b) +{ + vec_a->x = vec_a->x + vec_b->x; + vec_a->y = vec_a->y + vec_b->y; +} + +void vec_sub(t_vec *vec_a, const t_vec *vec_b) +{ + vec_a->x = vec_a->x - vec_b->x; + vec_a->y = vec_b->y - vec_b->y; +} + +void vec_muls(t_vec *vec, double scalar) +{ + vec->x = vec->x * scalar; + vec->y = vec->y * scalar; +} + +double vec_dot(const t_vec *vec_a, const t_vec *vec_b) +{ + double dot; + + dot = (vec_a->x * vec_b->x) + (vec_a->y * vec_b->y); + return (dot); +} diff --git a/srcs/vector/vector_2.c b/srcs/vector/vector_2.c new file mode 100644 index 0000000..93faa96 --- /dev/null +++ b/srcs/vector/vector_2.c @@ -0,0 +1,59 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* vector_2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tsuchen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/08/27 13:33:30 by tsuchen #+# #+# */ +/* Updated: 2024/08/27 13:55:09 by tsuchen ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "vector.h" + +double vec_absv(const t_vec *vec) +{ + double absv; + + absv = sqrt((vec->x * vec->x) + (vec->y * vec->y)); + return (absv); +} + +double vec_dist(const t_vec *vec_a, const t_vec *vec_b) +{ + double dist; + double del_x; + double del_y; + + del_x = vec_b->x - vec_a->x; + del_y = vec_b->y - vec_a->y; + dist = sqrt((del_x * del_x) + (del_y * del_y)); + return (dist); +} + +void vec_mirror(t_vec *vec) +{ + vec->x = vec->x * -1; + vec->y = vec->y * -1; +} + +void vec_transp(t_vec *vec) +{ + double tmp; + + tmp = vec->x; + vec->x = vec->y; + vec->y = tmp; +} + +void vec_rotate(t_vec *vec, double angle) +{ + double new_x; + double new_y; + + new_x = vec->x * cos(angle) - vec->y * sin(angle); + new_y = vec->x * sin(angle) + vec->y * cos(angle); + vec->x = new_x; + vec->y = new_y; +}