t_vec objects;
t_vec lights;
t_vec cameras;
- const t_camera *current_camera;
+ size_t current_camera_ind;
+ t_element *current_element;
} t_scene;
typedef struct s_ray
t_scene scene;
} t_session;
-t_color trace_ray(const t_ray *ray, const t_scene *scene);
+typedef struct s_obstruction
+{
+ t_object *object;
+ double distance;
+} t_obstruction;
+
+t_color trace_ray(const t_ray *ray, t_scene *scene);
t_color color_sRGB_to_lin(t_color_sRGB sRGB);
+
+t_obstruction find_nearest_obstruction(const t_ray *ray, t_vec *objects, const t_object *ignored);
+
int parse_args(int argc, char **argv, t_session *s);
int rotate(t_element *element, t_vec3 rot_axis, double angle);
t_ray res;
const float x_max = s->img.width;
const float y_max = s->img.height;
- const t_camera *const camera = s->scene.current_camera;
+ const t_camera *camera;
+ camera = &(((t_element *)ft_vec_caccess(&s->scene.cameras, s->scene.current_camera_ind))->object.camera);
res.start = camera->position;
res.direction = camera->orientation;
res.direction =
t_element *element;
t_camera *camera;
- element = ft_vec_access(&s->scene.cameras, 0);
- camera = &element->object.camera;
+ if (s->scene.current_element)
+ element = s->scene.current_element;
+ else
+ element = ft_vec_access(&s->scene.cameras, s->scene.current_camera_ind);
+ camera = &(((t_element *)ft_vec_access(&s->scene.cameras, s->scene.current_camera_ind))->object.camera);
if (keycode == XK_Escape)
- close_win(s);
+ {
+ if (s->scene.current_element)
+ s->scene.current_element = NULL;
+ else
+ close_win(s);
+ }
else if (keycode == XK_Up)
translate(element, camera->orientation, 0.1);
else if (keycode == XK_Down)
return (0);
}
-int handle_mouse_press(int button, __attribute__((unused)) int x, __attribute__((unused)) int y, t_session *s)
+int handle_mouse_press(int button, int x, int y, t_session *s)
{
- /*
- if (button == Button4)
- else if (button == Button5)
- */
- if (button == Button4 || button == Button5)
- draw(s);
+ t_ray ray;
+
+ if (button == Button1)
+ {
+ ray = get_camera_ray(x, y, s);
+ s->scene.current_element = find_nearest_obstruction(&ray, &s->scene.objects, NULL).object;
+ }
+ else if (button == Button3)
+ s->scene.current_element = NULL;
return (0);
}
/* By: ljiriste <ljiriste@student.42prague.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/28 12:34:20 by ljiriste #+# #+# */
-/* Updated: 2024/12/06 12:18:02 by ljiriste ### ########.fr */
+/* Updated: 2025/01/07 12:57:50 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
if (parse_tree && !parse_tree_to_scene(parse_tree, scene))
if (scene->cameras.size > 0)
{
- scene->current_camera = &((const t_element *)ft_vec_caccess(&scene->cameras, 0))->object.camera;
+ scene->current_camera_ind = 0;
res = 0;
}
ft_parse_tree_free(parse_tree);
int i;
int got_file;
+ s->scene.current_element = NULL;
got_file = 0;
if (argc % 2 == 0)
return (1);
return (get_circumsphere(object).radius * SELF_OBSTRUCTION_MULTIPLIER);
}
-typedef struct s_obstruction
-{
- const t_object *object;
- double distance;
-} t_obstruction;
-
-t_obstruction find_nearest_obstruction(const t_ray *ray, const t_vec *objects,
+t_obstruction find_nearest_obstruction(const t_ray *ray, t_vec *objects,
const t_object *ignored)
{
size_t i;
size_t j;
t_obstruction obstruction_found;
- const t_object *object;
+ t_object *object;
double distance;
double ignored_dist;
t_vec distances;
i = 0;
while (i < objects->size)
{
- object = ft_vec_caccess(objects, i++);
+ object = ft_vec_access(objects, i++);
distances = get_intersection_args(ray, object);
j = 0;
while (j < distances.size)
return ((t_vec3){.x = 0, .y = 0, .z = 0});
}
-t_color get_light_contribution(t_ray normal, const t_object *object, const t_light *light, const t_scene *scene)
+t_color get_light_contribution(t_ray normal, const t_object *object, const t_light *light, t_scene *scene)
{
t_ray new_ray;
t_obstruction obstruction;
}
t_color get_object_color(const t_ray *ray, const t_object *object,
- const t_scene *scene)
+ t_scene *scene)
{
t_color result;
t_ray normal_at_intersect;
return (result);
}
-t_color trace_ray(const t_ray *ray, const t_scene *scene)
+t_color trace_ray(const t_ray *ray, t_scene *scene)
{
const t_object *object_found;