-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
joppe
committed
Jan 19, 2024
1 parent
750047a
commit 34688bd
Showing
5 changed files
with
43 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ | ||
/**/ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -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); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -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); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -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}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters