From 0396180cd8ca5b7361fe5de06baf2d5802109e57 Mon Sep 17 00:00:00 2001 From: ReverseSky Date: Wed, 6 Nov 2024 15:21:24 +0100 Subject: [PATCH] add mouse movement --- algo.c | 22 ++++++++++++++++++++-- algo.h | 8 ++++++-- map.h | 6 ++++-- move.c | 6 +++--- move2.c | 24 ++++++++++++++++++++++++ 5 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 move2.c diff --git a/algo.c b/algo.c index a157ed8..d2f51a7 100644 --- a/algo.c +++ b/algo.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* algo.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ +/* By: greg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/29 15:28:25 by grobledo ### ########.fr */ +/* Updated: 2024/11/06 15:16:02 by greg ### ########.fr */ /* */ /* ************************************************************************** */ @@ -77,6 +77,23 @@ static int loop_hook(void *param) return (0); } +// static int rotate( int dx) +// { +// g_map.player.rot += PI / ROT_SPEED_DIVIDE_PI * dx; +// return (0); +// } + +int mouse_move(int x, int y) +{ + (void)y; + int dx = x - g_player.old_mouse_x; // Calcul de la différence de mouvement + if (dx != 0) { + rotate(dx); + g_player.old_mouse_x = x; // Mise à jour de la position précédente + } + return (0); +} + int main(int argc, char *argv[]) { g_mlx = mlx_init(); @@ -92,6 +109,7 @@ int main(int argc, char *argv[]) mlx_hook(g_win, KeyPress, KeyPressMask, keypress, NULL); mlx_hook(g_win, KeyRelease, KeyReleaseMask, keyrelease, NULL); mlx_hook(g_win, 17, 1L<<17, ft_exit, NULL); + mlx_hook(g_win, 6, 1L<< 6, mouse_move, NULL); mlx_loop_hook(g_mlx, loop_hook, NULL); draw_screen(); mlx_loop(g_mlx); diff --git a/algo.h b/algo.h index 22561c4..02f81db 100644 --- a/algo.h +++ b/algo.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* algo.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ +/* By: greg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */ -/* Updated: 2024/10/29 15:29:30 by grobledo ### ########.fr */ +/* Updated: 2024/11/06 15:18:45 by greg ### ########.fr */ /* */ /* ************************************************************************** */ @@ -87,4 +87,8 @@ void draw_wall(t_tex *tex, t_ray *ray, const int line_height, int x, int y, u_int32_t *img_data); void clean_img(t_tex *tex); + +int rotate(int factor); + +int mouse_move(int x, int y); #endif diff --git a/map.h b/map.h index 86c6a39..55ce662 100644 --- a/map.h +++ b/map.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* map.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 13:59:04 by mcolonna #+# #+# */ -/* Updated: 2024/10/16 17:59:12 by mcolonna ### ########.fr */ +/* Updated: 2024/11/06 14:48:12 by greg ### ########.fr */ /* */ /* ************************************************************************** */ @@ -67,6 +67,8 @@ typedef struct s_player t_point_double pos; // player rotation (rad) double rot; + + int old_mouse_x; } t_player; /// @brief Represents a map. diff --git a/move.c b/move.c index 8511c2f..3a61b59 100644 --- a/move.c +++ b/move.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* move.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: greg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 12:47:34 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 15:06:43 by mcolonna ### ########.fr */ +/* Updated: 2024/11/06 15:17:15 by greg ### ########.fr */ /* */ /* ************************************************************************** */ @@ -59,7 +59,7 @@ static int move_forward(int factor) return (0); } -static int rotate(int factor) +int rotate(int factor) { g_map.player.rot += PI / ROT_SPEED_DIVIDE_PI * factor; return (0); diff --git a/move2.c b/move2.c new file mode 100644 index 0000000..473d1b1 --- /dev/null +++ b/move2.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* move2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: greg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/06 15:18:21 by greg #+# #+# */ +/* Updated: 2024/11/06 15:18:34 by greg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "algo.h" + +int mouse_move(int x, int y) +{ + (void)y; + int dx = x - g_player.old_mouse_x; // Calcul de la différence de mouvement + if (dx != 0) { + rotate(dx); + g_player.old_mouse_x = x; // Mise à jour de la position précédente + } + return (0); +} \ No newline at end of file