Skip to content

Commit

Permalink
More experimentation
Browse files Browse the repository at this point in the history
  • Loading branch information
joppe committed Jan 19, 2024
1 parent 750047a commit 34688bd
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 54 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions include/vector.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* ************************************************************************** */
/**/
/* :::::::: */
/* vector.h :+::+: */
/* vector.h :+: :+: */
/*+:+ */
/* By: joppe <[email protected]> +#+ */
/* +#+ */
/* 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 */
/**/
/* ************************************************************************** */

Expand Down Expand Up @@ -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);
Expand Down
68 changes: 25 additions & 43 deletions src/game/player.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: yzaim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down
10 changes: 8 additions & 2 deletions src/vector/vec2d.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* vec2d.c :+: :+: */
/* vec2d.c :+: :+: */
/* +:+ */
/* By: yzaim <[email protected]> +#+ */
/* +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand All @@ -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});
Expand Down
12 changes: 6 additions & 6 deletions test_maps/valid_tex.cub
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 34688bd

Please sign in to comment.