From b9bb66cc95a7fdb1325104b0ad4aaed78aa9dd2b Mon Sep 17 00:00:00 2001 From: Lukas Jiriste Date: Wed, 8 Jan 2025 15:16:07 +0100 Subject: [PATCH] Add a way to select lights for manipulation The 'l' and 'k' keys are used to cycle through lights. When no light is selected, either of the keys selects the last one selected. --- inc/miniRT.h | 1 + src/main.c | 14 +++++++++++++- src/parsing.c | 3 ++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/inc/miniRT.h b/inc/miniRT.h index 00ec132..1d05bef 100644 --- a/inc/miniRT.h +++ b/inc/miniRT.h @@ -99,6 +99,7 @@ typedef struct s_scene t_vec lights; t_vec cameras; size_t current_camera_ind; + size_t current_light_ind; t_element *current_element; int relative_directions; } t_scene; diff --git a/src/main.c b/src/main.c index 40dc02a..2b27cb8 100644 --- a/src/main.c +++ b/src/main.c @@ -209,7 +209,19 @@ int handle_key_press(int keycode, t_session *s) change_height(element, -RESIZE_STEP); else if (keycode == XK_o) s->scene.relative_directions = !s->scene.relative_directions; - if (keycode != XK_Escape && keycode != XK_A) + else if (keycode == XK_l && s->scene.lights.size > 0) + { + if (s->scene.current_element && s->scene.current_element->type == LIGHT) + s->scene.current_light_ind = (s->scene.current_light_ind + 1) % s->scene.lights.size; + s->scene.current_element = ft_vec_access(&s->scene.lights, s->scene.current_light_ind); + } + else if (keycode == XK_k && s->scene.lights.size > 0) + { + if (s->scene.current_element && s->scene.current_element->type == LIGHT) + s->scene.current_light_ind = (s->scene.current_light_ind + s->scene.lights.size - 1) % s->scene.lights.size; + s->scene.current_element = ft_vec_access(&s->scene.lights, s->scene.current_light_ind); + } + if (keycode != XK_Escape && keycode != XK_o && keycode != XK_l && keycode != XK_k) draw(s); return (0); } diff --git a/src/parsing.c b/src/parsing.c index bde935a..38c2a88 100644 --- a/src/parsing.c +++ b/src/parsing.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/28 12:34:20 by ljiriste #+# #+# */ -/* Updated: 2025/01/08 13:07:58 by ljiriste ### ########.fr */ +/* Updated: 2025/01/08 14:53:13 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -388,6 +388,7 @@ int parse_args(int argc, char **argv, t_session *s) s->scene.current_element = NULL; s->scene.relative_directions = 1; + s->scene.current_light_ind = 0; got_file = 0; if (argc % 2 == 0) return (1); -- 2.30.2