Add a way to select lights for manipulation
authorLukas Jiriste <ljiriste@student.42prague.com>
Wed, 8 Jan 2025 14:16:07 +0000 (15:16 +0100)
committerLukas Jiriste <ljiriste@student.42prague.com>
Wed, 8 Jan 2025 14:16:07 +0000 (15:16 +0100)
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
src/main.c
src/parsing.c

index 00ec132b13e56e36c5f60ae391dbff60b50db953..1d05bef6fe5ba01acbbf7a529a61c2cd9f1857f9 100644 (file)
@@ -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;
index 40dc02af434b3ae0cd5a7910ff856f143de511f2..2b27cb84191b758be04ced6a18ba6a01e503c2e5 100644 (file)
@@ -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);
 }
index bde935a2b6c4ff336214bb3cd32ca9070931e3e9..38c2a888a167221fd86924cfb3a0226728c7307f 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   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);