diff --git a/Makefile b/Makefile index fb11456..8f05cea 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ RUN_CMD := ./$(NAME) test_maps/valid_tex.cub # CFLAGS += -Wall -Wextra -Werror # CFLAGS += -Wall -Wextra -CFLAGS += -g -fsanitize=address +# CFLAGS += -g -fsanitize=address # CFLAGS += -g # CFLAGS += -Ofast -flto -march=native diff --git a/include/vector.h b/include/vector.h index d7e9269..a1cbd08 100644 --- a/include/vector.h +++ b/include/vector.h @@ -1,12 +1,12 @@ /* ************************************************************************** */ /**/ /* :::::::: */ -/* vector.h :+::+: */ +/* vector.h :+: :+: */ /*+:+ */ /* By: joppe +#+ */ /* +#+ */ /* Created: 2024/01/02 19:07:15 by joppe #+##+# */ -/* Updated: 2024/01/03 18:35:23 by joppe ######## odam.nl */ +/* Updated: 2024/01/19 23:36:47 by joppe ######## odam.nl */ /**/ /* ************************************************************************** */ @@ -35,6 +35,7 @@ typedef struct s_vec2u { t_vec2d vec2d_add(t_vec2d v1, t_vec2d v2); t_vec2d vec2d_sub(t_vec2d v1, t_vec2d v2); t_vec2d vec2d_scalar_product(t_vec2d vec, double scalar); +double vec2d_dot_product(t_vec2d v1, t_vec2d v2); t_vec2d vec2d_mul(t_vec2d v1, t_vec2d v2); t_vec2d vec2d_rotate(t_vec2d old, double radiant); t_vec2d vec2d_normalize(t_vec2d vec); diff --git a/src/game/player.c b/src/game/player.c index 22cca78..284c35a 100644 --- a/src/game/player.c +++ b/src/game/player.c @@ -6,7 +6,7 @@ /* By: yzaim +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/08 15:27:23 by yzaim #+# #+# */ -/* Updated: 2024/01/18 17:10:32 by jboeve ######## odam.nl */ +/* Updated: 2024/01/20 00:22:42 by joppe ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -32,58 +32,39 @@ bool bound_check(void *param, uint32_t x, uint32_t y) } } -void player_move(t_player *p, t_vec2d transform) +void print_angle(t_player *p) { - t_vec2d new_position; + // NORTH = 0 + const float angle = (atan2(p->direction.x, p->direction.y) / PI * 180 + 180); - new_position.x = (p->position.x + (transform.x)); - new_position.y = (p->position.y + (transform.y)); + if (angle > 45.0 && angle < 135.0) + { + printf("N\n"); + } + else if (angle > 135.0 && angle < 225.0) + { + printf("E\n"); + } + else if (angle > 225.0 && angle < 315.0) + { + printf("S\n"); + } + else if (angle > 315.0 || angle < 45.0) + { + printf("W\n"); + } +} - // TODO Fix. +void player_move(t_player *p, t_vec2d transform) +{ t_ray r = raycaster_cast(p->position, vec2d_normalize(transform), bound_check, p->meta); - // print_ray("bound_ray", &r); - - const double margin = 0.005; - float angle = (atan2(p->direction.x, p->direction.y) / PI * 180 + 180); - printf("angle [%f]\n", angle); if (r.length > .5) { p->position.y += transform.y; p->position.x += transform.x; } - else if (r.length > .1) - { - printf("angle [%f]\n", angle); - - double res = 0.0; - - // Colission with a wall the y-axis - if ((angle > 0 && angle < 45) || (angle > 315)) - { - printf("Gliding N\n"); - res = transform.x * -p->direction.y; - r = raycaster_cast(p->position, (t_vec2d) {res, 0.0}, bound_check, p->meta); - if (r.length > .1) - p->position.x += res; - } - else if (angle > 90 && angle < 270) - { - printf("Gliding S\n"); - res = transform.x * p->direction.y; - r = raycaster_cast(p->position, (t_vec2d) {res, 0.0}, bound_check, p->meta); - if (r.length > .1) - p->position.x += res; - } - - - // if (angle == 1 || angle == 2) - // { - // double res = transform.y * -p->direction.x; - // r = raycaster_cast(p->position, (t_vec2d) {0.0, res}, bound_check, p->meta); - // p->position.y += res; - // } - } + print_angle(p); player_raycast(p); } @@ -92,6 +73,7 @@ void player_turn(t_player *p, float radiant) { p->direction = vec2d_rotate(p->direction, radiant); p->cam_plane = vec2d_rotate(p->cam_plane, radiant); + print_angle(p); player_raycast(p); } diff --git a/src/vector/vec2d.c b/src/vector/vec2d.c index a3c90aa..46e2c44 100644 --- a/src/vector/vec2d.c +++ b/src/vector/vec2d.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* :::::::: */ -/* vec2d.c :+: :+: */ +/* vec2d.c :+: :+: */ /* +:+ */ /* By: yzaim +#+ */ /* +#+ */ /* Created: 2024/01/08 16:09:26 by yzaim #+# #+# */ -/* Updated: 2024/01/08 16:09:27 by yzaim ######## odam.nl */ +/* Updated: 2024/01/19 23:37:30 by joppe ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -31,6 +31,12 @@ t_vec2d vec2d_scalar_product(t_vec2d vec, double scalar) return ((t_vec2d){vec.x * scalar, vec.y * scalar}); } +double vec2d_dot_product(t_vec2d v1, t_vec2d v2) +{ + return ((v1.x * v2.x) + (v1.y * v2.y)); +} + + t_vec2d vec2d_mul(t_vec2d v1, t_vec2d v2) { return ((t_vec2d){v1.x * v2.x, v1.y * v2.y}); diff --git a/test_maps/valid_tex.cub b/test_maps/valid_tex.cub index e1ae7f1..823e33f 100644 --- a/test_maps/valid_tex.cub +++ b/test_maps/valid_tex.cub @@ -6,12 +6,12 @@ F 255,255,255 C 12, 12, 12 11111111111111 -1000010001 -1000010001 -1000110001 -1000100001 -1000100001 +1000000001 +1000N00001 +1000000001 +1000000001 +1000000001 100000000111 100000000001 -1000000N011 +10000000011 1111111111