From 33b3b06c075fb8f887472c75e3301027c163d719 Mon Sep 17 00:00:00 2001 From: Gregory Robledo Date: Tue, 29 Oct 2024 15:04:36 +0100 Subject: [PATCH 1/3] added cross click --- algo.c | 5 ++--- input.c | 9 +++++++-- input.h | 6 +++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/algo.c b/algo.c index 52271f0..2d2eef2 100644 --- a/algo.c +++ b/algo.c @@ -6,7 +6,7 @@ /* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/29 14:23:34 by grobledo ### ########.fr */ +/* Updated: 2024/10/29 14:33:28 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -77,8 +77,6 @@ static int loop_hook(void *param) return (0); } - - int main(int argc, char *argv[]) { g_mlx = mlx_init(); @@ -93,6 +91,7 @@ int main(int argc, char *argv[]) g_win = mlx_new_window(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT, "cub3d"); 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_loop_hook(g_mlx, loop_hook, NULL); draw_screen(); mlx_loop(g_mlx); diff --git a/input.c b/input.c index 45168e0..d3c2358 100644 --- a/input.c +++ b/input.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* input.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/17 14:43:36 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 16:05:50 by mcolonna ### ########.fr */ +/* Updated: 2024/10/29 14:32:46 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -50,3 +50,8 @@ void input_init(void) g_input_actions.right = false; g_input_actions.quit = false; } +int ft_exit(void) +{ + g_input_actions.quit = true; + return(0); +} \ No newline at end of file diff --git a/input.h b/input.h index becd5a1..51f67d8 100644 --- a/input.h +++ b/input.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* input.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/17 14:43:09 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 14:59:41 by mcolonna ### ########.fr */ +/* Updated: 2024/10/29 14:33:04 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,5 +31,5 @@ extern t_input_actions g_input_actions; int keypress(int keycode); int keyrelease(int keycode); void input_init(void); - +int ft_exit(void); #endif From d193b99c568f0bf56b8b4361956546d3ebea5101 Mon Sep 17 00:00:00 2001 From: Gregory Robledo Date: Tue, 29 Oct 2024 15:31:18 +0100 Subject: [PATCH 2/3] fixed leak --- algo.c | 4 ++-- algo.h | 5 +++-- utils.c | 17 +++++++++++++++-- utils.h | 4 ++-- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/algo.c b/algo.c index 2d2eef2..a157ed8 100644 --- a/algo.c +++ b/algo.c @@ -6,7 +6,7 @@ /* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/29 14:33:28 by grobledo ### ########.fr */ +/* Updated: 2024/10/29 15:28:25 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,6 @@ void *g_mlx = NULL; void *g_win = NULL; t_map g_map; t_player g_player; -// t_tex g_tex; // TODO manage image format error better @@ -57,6 +56,7 @@ void draw_screen(void) render(img_data, &tex); mlx_put_image_to_window(g_mlx, g_win, img_ptr, 0, 0); mlx_destroy_image(g_mlx, img_ptr); + clean_img(&tex); } static void loop(void) diff --git a/algo.h b/algo.h index 32839ac..22561c4 100644 --- a/algo.h +++ b/algo.h @@ -6,7 +6,7 @@ /* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */ -/* Updated: 2024/10/24 14:27:27 by grobledo ### ########.fr */ +/* Updated: 2024/10/29 15:29:30 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -67,7 +67,6 @@ extern void *g_mlx; extern void *g_win; extern t_player g_player; extern t_map g_map; -// extern t_tex g_tex; /// @brief Write an error message on stderr. /// @@ -86,4 +85,6 @@ void ft_init_texture(const double perpwalldist, t_ray *ray, t_tex *tex); 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); #endif diff --git a/utils.c b/utils.c index e265cdf..fd4555e 100644 --- a/utils.c +++ b/utils.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 12:38:40 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 16:36:14 by mcolonna ### ########.fr */ +/* Updated: 2024/10/29 15:28:56 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -69,3 +69,16 @@ void timedloop(void (*f)(void)) f(); ticks++; } + +void clean_img(t_tex *tex) +{ + int i; + + i = 0; + while (i <= 3) + { + if (tex->textures[i]) + mlx_destroy_image(g_mlx, tex->textures[i]); + i++; + } +} \ No newline at end of file diff --git a/utils.h b/utils.h index 93a619d..bb83116 100644 --- a/utils.h +++ b/utils.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* utils.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 16:56:47 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 14:41:09 by mcolonna ### ########.fr */ +/* Updated: 2024/10/29 15:27:17 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ From 0396180cd8ca5b7361fe5de06baf2d5802109e57 Mon Sep 17 00:00:00 2001 From: ReverseSky Date: Wed, 6 Nov 2024 15:21:24 +0100 Subject: [PATCH 3/3] 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