-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP for find the position of the door in the matrix
- Loading branch information
Jean Teissier
authored and
Jean Teissier
committed
Sep 2, 2024
1 parent
c40b6ef
commit 937924d
Showing
5 changed files
with
82 additions
and
13 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: jteissie <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/15 00:19:44 by tsuchen #+# #+# */ | ||
/* Updated: 2024/09/02 14:12:16 by jteissie ### ########.fr */ | ||
/* Updated: 2024/09/02 15:07:28 by jteissie ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -127,6 +127,7 @@ int cleanup(t_data *data); | |
int game_init(t_data *data); | ||
int key_events(int keycode, t_data *data); | ||
void move_check(t_vec *step, t_data *data, int add_or_sub); | ||
int mouse_press(int button, int x, int y, t_data *data); | ||
/* color utils*/ | ||
int create_trgb(int t, int r, int g, int b); | ||
int get_color(int trgb, char index); | ||
|
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: jteissie <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/27 18:40:50 by jteissie #+# #+# */ | ||
/* Updated: 2024/09/02 14:53:27 by jteissie ### ########.fr */ | ||
/* Updated: 2024/09/02 15:07:28 by jteissie ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -54,11 +54,6 @@ static void move_camera(t_data *data, t_rot dir) | |
return ; | ||
} | ||
|
||
// static void interact_door(t_data *data) | ||
// { | ||
// (void)data; | ||
// return ; | ||
// } | ||
|
||
int key_events(int keycode, t_data *data) | ||
{ | ||
|
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* mouse_events.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: jteissie <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/09/02 15:02:38 by jteissie #+# #+# */ | ||
/* Updated: 2024/09/02 15:50:21 by jteissie ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "cub3d.h" | ||
|
||
static double get_door_dist(t_vec *ray, t_data *data) | ||
{ | ||
t_vec ray_pos; | ||
t_vec unit_dist; | ||
t_vec dist_ray; | ||
|
||
ray->door = FALSE; | ||
vec_init(&ray_pos, data->p_pos.x, data->p_pos.y); | ||
unit_dist.x = sqrt(1 + ((ray->y * ray->y) / (ray->x * ray->x))); | ||
unit_dist.y = sqrt(1 + ((ray->x * ray->x) / (ray->y * ray->y))); | ||
rc_ray_init(&dist_ray, &ray_pos, ray, &unit_dist); | ||
while (1) | ||
{ | ||
data->side = rc_dda(&dist_ray, &unit_dist, &ray_pos, ray); | ||
if (data->map[(int)ray_pos.x][(int)ray_pos.y] == '1') | ||
return (1); | ||
else if (data->map[(int)ray_pos.x][(int)ray_pos.y] == 'D') | ||
break ; | ||
} | ||
if (data->side == 1) | ||
return ((dist_ray.y - unit_dist.y) * vec_cos(ray, &data->p_dir)); | ||
else | ||
return ((dist_ray.x - unit_dist.x) * vec_cos(ray, &data->p_dir)); | ||
} | ||
|
||
static void change_door_state(t_data *data, double dist) | ||
{ | ||
|
||
} | ||
|
||
static void interact_door(t_data *data) | ||
{ | ||
t_vec p_ray; | ||
double dist; | ||
|
||
p_ray.x = data->p_dir.x; | ||
p_ray.y = data->p_dir.y; | ||
printf("p_ray.x: %f\n", p_ray.x); | ||
printf("p_ray.y: %f\n", p_ray.y); | ||
dist = get_door_dist(&p_ray, data); | ||
if (dist > 0.5) | ||
{ | ||
printf("Door too far!\n"); | ||
return ; | ||
} | ||
printf("In door range!\n"); | ||
change_door_state(data, dist); | ||
return ; | ||
} | ||
|
||
int mouse_press(int button, int x, int y, t_data *data) | ||
{ | ||
(void)x; | ||
(void)y; | ||
if (button == 1) | ||
interact_door(data); | ||
return (SUCCESS); | ||
} |
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