diff --git a/config.c b/config.c index 6704da0..036784c 100644 --- a/config.c +++ b/config.c @@ -6,7 +6,7 @@ /* By: yantoine +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/14 01:41:17 by yantoine #+# #+# */ -/* Updated: 2025/02/18 20:44:41 by yantoine ### ########.fr */ +/* Updated: 2025/02/22 20:37:46 by yantoine ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,7 +43,7 @@ t_scene load_config(const char *filename) scene = create_scene(); fd = open(filename, O_RDONLY); - if (!fd) + if (fd <= 0 || !have_extension(filename)) { printf("Erreur : impossible d'ouvrir %s\n", filename); return (scene); diff --git a/have_extension.c b/have_extension.c new file mode 100644 index 0000000..2a51f79 --- /dev/null +++ b/have_extension.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* have_extension.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/22 20:45:59 by yantoine #+# #+# */ +/* Updated: 2025/02/22 21:04:31 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "miniRT.h" + +int have_extension(const char *line) +{ + const int lenght = ft_strlen(line); + + if (lenght < 3) + return (0); + if (ft_strncmp(lenght + line - 3, ".rt", lenght) == 0) + return (1); + printf("erreur: pas d'extension\n"); + return (0); +} diff --git a/main.c b/main.c index 5ca9e74..9090795 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,7 @@ /* By: yantoine +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/17 19:54:03 by yantoine #+# #+# */ -/* Updated: 2025/02/18 17:23:15 by yantoine ### ########.fr */ +/* Updated: 2025/02/22 21:32:40 by yantoine ### ########.fr */ /* */ /* ************************************************************************** */ @@ -51,13 +51,31 @@ static void setup_hooks(t_app *app) mlx_loop_hook(app->mlx, update_frame, app); } +static int check_number(t_scene scene) +{ + if (scene.num_camera > MAX_CAMERA) + return (0); + if (scene.num_planes > MAX_PLANES) + return (0); + if (scene.num_spheres > MAX_SPHERES) + return (0); + if (scene.num_cylinders > MAX_CYLINDERS) + return (0); + if (scene.num_lights > MAX_LIGHTS) + return (0); + if (scene.num_ambient > MAX_AMBIENT) + return (0); + return (1); +} + + int main(int argc, char **argv) { t_app app; ft_bzero(&app, sizeof(t_app)); init_app_config(&app, argc, argv); - if (app.scene.num_camera == 0 || init_mlx_and_image(&app)) + if (!check_number(app.scene) || app.scene.num_camera == 0 || init_mlx_and_image(&app)) return (1); setup_hooks(&app); mlx_loop(app.mlx); diff --git a/miniRT.h b/miniRT.h index e718fe6..744c9eb 100644 --- a/miniRT.h +++ b/miniRT.h @@ -6,7 +6,7 @@ /* By: yantoine +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/13 20:02:36 by yantoine #+# #+# */ -/* Updated: 2025/02/22 18:29:15 by yantoine ### ########.fr */ +/* Updated: 2025/02/22 21:21:03 by yantoine ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,7 +32,7 @@ # define MAX_SPHERES 128 # define MAX_PLANES 128 # define MAX_CYLINDERS 128 -# define MAX_LIGHTS 16 +# define MAX_LIGHTS 1 # define MAX_AMBIENT 1 # define MAX_CAMERA 1 @@ -237,6 +237,7 @@ char **get_tokens_secure(t_scene scene, const int numObject, // Check int check_tokens(char **tokens, int expected); int isdigit_token(char **tokens); +int have_extension(const char *line); void check_if_max(t_scene scene, const int to_test, const int max); // Intersection diff --git a/scene_non_fonctionel/deux_cam.rt b/scene_non_fonctionel/deux_cam.rt new file mode 100644 index 0000000..62038fa --- /dev/null +++ b/scene_non_fonctionel/deux_cam.rt @@ -0,0 +1,11 @@ +A 0 255,255,255 + +C 0,0,0 0,0,-1 70 + +C 0,0,0 0,0,-1 70 + +L 11,40,50 1 255,255,255 + +sp 0,0,-20 10 0,0,100 + +pl 0,-5,0 0,1,0 100,55,0 diff --git a/scene_non_fonctionel/giga_bleu.rt b/scene_non_fonctionel/giga_bleu.rt new file mode 100644 index 0000000..e6bf6e3 --- /dev/null +++ b/scene_non_fonctionel/giga_bleu.rt @@ -0,0 +1,9 @@ +A 0 255,255,25555555555555555555555555555555555555555555555555555555555555555555 + +C 0,0,0 0,0,-1 70 + +L 11,40,50 1 255,255,255 + +sp 0,0,-20 10 0,0,100 + +pl 0,-5,0 0,1,0 100,55,0 diff --git a/scene_non_fonctionel/giga_coordonee.rt b/scene_non_fonctionel/giga_coordonee.rt new file mode 100644 index 0000000..4595329 --- /dev/null +++ b/scene_non_fonctionel/giga_coordonee.rt @@ -0,0 +1,9 @@ +A 0 255,255,255 + +C 4444444444444444444444444,1111111111111111111111111,9999999999999999999999999999 0,0,-1 70 + +L 11,40,50 1 255,255,255 + +sp 0,0,-20 10 0,0,100 + +pl 0,-5,0 0,1,0 100,55,0 diff --git a/scene_non_fonctionel/giga_ratio_ambiant.rt b/scene_non_fonctionel/giga_ratio_ambiant.rt new file mode 100644 index 0000000..1b3d8cd --- /dev/null +++ b/scene_non_fonctionel/giga_ratio_ambiant.rt @@ -0,0 +1,9 @@ +A 999999999999999999999999999999999999999999999999999999999999999999999999999 255,255,255 + +C 0,0,0 0,0,-1 70 + +L 11,40,50 1 255,255,255 + +sp 0,0,-20 10 0,0,100 + +pl 0,-5,0 0,1,0 100,55,0 diff --git a/scene_non_fonctionel/pas_extention b/scene_non_fonctionel/pas_extention new file mode 100644 index 0000000..0945eeb --- /dev/null +++ b/scene_non_fonctionel/pas_extention @@ -0,0 +1,27 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# pas_extention :+: :+: :+: # +# +:+ +:+ +:+ # +# By: yantoine +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2025/02/13 19:27:37 by yantoine #+# #+# # +# Updated: 2025/02/17 23:48:13 by yantoine ### ########.fr # +# # +# **************************************************************************** # + +# Ambient lighting (ratio et couleur) +A 0 255,255,255 + +# Camera : position à (0,0,20) et orientée vers (0,0,-1) avec un FOV de 70° +C 0,0,0 0,0,0 70 + +# Light : source lumineuse forte placée au-dessus de la scène +L 11,40,-30 1 255,255,255 + +sp 0,0,-20 10 0,0,100 + +# Plane : un plan vert servant de sol, passant par (0,-5,0) et avec une normale vers le haut +pl 0,-5,0 0,1,0 100,55,0 + +