-
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.
Solution not really working nicely with wide angles
- Loading branch information
Joppe Boeve
committed
Jan 18, 2024
1 parent
dea0b0d
commit 750047a
Showing
8 changed files
with
76 additions
and
29 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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: jboeve <[email protected]>+#+ */ | ||
/* +#+ */ | ||
/* Created: 2023/11/01 20:07:37 by jboeve#+##+# */ | ||
/* Updated: 2024/01/18 11:56:06 by jboeve ######## odam.nl */ | ||
/* Updated: 2024/01/18 14:09:20 by jboeve ######## odam.nl */ | ||
/**/ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -126,10 +126,10 @@ typedef union s_rgba | |
|
||
|
||
typedef enum e_side { | ||
SIDE_N, | ||
SIDE_S, | ||
SIDE_E, | ||
SIDE_W, | ||
SIDE_N = 0, | ||
SIDE_S = 1, | ||
SIDE_E = 2, | ||
SIDE_W = 3, | ||
} t_side; | ||
|
||
typedef struct s_ray { | ||
|
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,13 +1,13 @@ | ||
/* ************************************************************************** */ | ||
/**/ | ||
/* :::::::: */ | ||
/* test_utils.h :+::+: */ | ||
/*+:+ */ | ||
/* By: joppe <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2024/01/02 19:56:05 by joppe #+##+# */ | ||
/* Updated: 2024/01/02 23:20:17 by joppe ######## odam.nl */ | ||
/**/ | ||
/* */ | ||
/* :::::::: */ | ||
/* test_utils.h :+: :+: */ | ||
/* +:+ */ | ||
/* By: jboeve <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2024/01/18 13:59:19 by jboeve #+# #+# */ | ||
/* Updated: 2024/01/18 14:10:07 by jboeve ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
||
|
@@ -23,5 +23,5 @@ void print_cell(t_cell_type cell); | |
void print_map(char *map, uint32_t w, uint32_t h); | ||
void print_map_cell(t_cell_type *level, uint32_t w, uint32_t h); | ||
void print_ray(const char *s, const t_ray *r); | ||
|
||
void print_direction(t_side dir); | ||
#endif // !TEST_UTILS_H |
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 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* keys.c :+: :+: :+: */ | ||
/* keys.c :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: yzaim <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/08 15:27:07 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/08 15:27:11 by yzaim ### ########.fr */ | ||
/* Updated: 2024/01/18 12:50:58 by jboeve ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -49,7 +49,6 @@ static void keys_handle_move(t_meta *meta, double delta_time) | |
pressed = true; | ||
trans = vec2d_add(trans, (t_vec2d) {(vec2d_rotate(p->direction, PI / 2).x) * speed, (vec2d_rotate(p->direction, PI / 2).y) * speed}); | ||
} | ||
|
||
if (pressed) | ||
player_move(p, trans); | ||
} | ||
|
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/17 15:55:18 by jboeve ######## odam.nl */ | ||
/* Updated: 2024/01/18 17:10:32 by jboeve ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -43,10 +43,46 @@ 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.x += transform.x; | ||
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; | ||
// } | ||
} | ||
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 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* render_minimap.c :+: :+: :+: */ | ||
/* render_minimap.c :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: yzaim <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/08 15:27:53 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/08 15:27:58 by yzaim ### ########.fr */ | ||
/* Updated: 2024/01/18 12:43:48 by jboeve ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
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 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* test_utils.c :+: :+: :+: */ | ||
/* test_utils.c :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: yzaim <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/08 15:25:38 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/08 15:25:49 by yzaim ### ########.fr */ | ||
/* Updated: 2024/01/18 14:10:17 by jboeve ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -31,6 +31,18 @@ void print_ray(const char *s, const t_ray *r) | |
printf("[%s] | ray_direction [%lf][%lf] | length [%lf] | ray_end [%lf][%lf] | hit_side [%s]\n", s, r->direction.x, r->direction.y, r->length, r->end.x, r->end.y, side_text); | ||
} | ||
|
||
void print_direction(t_side dir) | ||
{ | ||
const char *text[4] = { | ||
[SIDE_N] = "N", | ||
[SIDE_E] = "E", | ||
[SIDE_S] = "S", | ||
[SIDE_W] = "W", | ||
}; | ||
|
||
printf("[%s]\n", text[dir]); | ||
} | ||
|
||
void print_cell(t_cell_type cell) | ||
{ | ||
printf("cell [%s]\n", CELL_NAMES[cell]); | ||
|
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