voir le parsing

This commit is contained in:
H3XploR
2025-02-17 23:12:16 +01:00
parent e36cfb5fde
commit 490c585c48
7 changed files with 67 additions and 72 deletions
+3 -3
View File
@@ -6,16 +6,16 @@
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/17 19:30:45 by yantoine #+# #+# */
/* Updated: 2025/02/17 21:55:36 by yantoine ### ########.fr */
/* Updated: 2025/02/17 22:55:22 by yantoine ### ########.fr */
/* */
/* ************************************************************************** */
#include "miniRT.h"
int update_frame(t_app *app, t_scene scene)
int update_frame(t_app *app)
{
update_camera(app);
render_scene(app, scene);
render_scene(app);
mlx_put_image_to_window(app->mlx, app->win, app->img, 0, 0);
return (0);
}
+9 -6
View File
@@ -6,7 +6,7 @@
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/17 19:54:03 by yantoine #+# #+# */
/* Updated: 2025/02/17 22:09:13 by yantoine ### ########.fr */
/* Updated: 2025/02/17 23:10:31 by yantoine ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,12 +14,14 @@
static int init_app_config(t_app *app, int argc, char **argv)
{
t_scene scene;
if (argc > 1)
load_config(argv[1]);
scene = load_config(argv[1]);
app->win_width = WIDTH;
app->win_height = HEIGHT;
app->move_speed = 0.5f;
app->rot_speed = 0.03f;
app->scene.camera.move_speed = 0.5f;
app->scene.camera.rot_speed = 0.03f;
app->mouse_sens = 0.002f;
app->key_w = 0;
app->key_s = 0;
@@ -29,6 +31,7 @@ static int init_app_config(t_app *app, int argc, char **argv)
app->key_right = 0;
app->key_up = 0;
app->key_down = 0;
app->scene = scene;
return (0);
}
@@ -40,8 +43,8 @@ static int init_mlx_and_image(t_app *app)
ft_putstr_fd("Erreur mlx_init\n", 2);
return (1);
}
app->win = mlx_new_window(app->mlx, app->win_width * 2,
app->win_height * 2, "Raytracer interactif");
app->win = mlx_new_window(app->mlx, app->win_width,
app->win_height, "Raytracer interactif");
if (!app->win)
{
ft_putstr_fd("Erreur mlx_new_window\n", 2);
+10 -14
View File
@@ -6,7 +6,7 @@
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/13 20:02:36 by yantoine #+# #+# */
/* Updated: 2025/02/17 21:55:55 by yantoine ### ########.fr */
/* Updated: 2025/02/17 23:10:49 by yantoine ### ########.fr */
/* */
/* ************************************************************************** */
@@ -25,8 +25,8 @@
# include "mlx.h"
// ----- Taille ecran ----
# define WIDTH 320
# define HEIGHT 240
# define WIDTH 640
# define HEIGHT 480
// ----- Tableaux de la scène -----
# define MAX_SPHERES 128
@@ -92,6 +92,10 @@ typedef struct s_camera
{
t_vec3 camPos;
t_vec3 camDir;
t_vec3 right;
t_vec3 up;
float move_speed;
float rot_speed;
float fov;
float yaw;// vue de gauche a droite
float pitch; // vue de haut en bas en radians
@@ -136,16 +140,8 @@ typedef struct s_app
int key_right;
int key_up;
int key_down;
float move_speed;
float rot_speed;
float mouse_sens;
t_vec3 cam_pos;
t_vec3 cam_dir;
t_vec3 right;
t_vec3 cam_up;
float fov;
float yaw;
float pitch;
t_scene scene;
} t_app;
@@ -237,8 +233,8 @@ int mouse_move(int x, int y, t_app *app);
// Render
void update_camera(t_app *app);
void render_scene(t_app *app, t_scene scene);
int update_frame(t_app *app, t_scene scene);
void render_scene(t_app *app);
int update_frame(t_app *app);
// Array
int ft_arraylen(char **array);
+3 -3
View File
@@ -6,7 +6,7 @@
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/17 19:22:27 by yantoine #+# #+# */
/* Updated: 2025/02/17 19:23:41 by yantoine ### ########.fr */
/* Updated: 2025/02/17 22:55:44 by yantoine ### ########.fr */
/* */
/* ************************************************************************** */
@@ -71,8 +71,8 @@ int mouse_move(int x, int y, t_app *app)
}
dx = x - last_x;
dy = y - last_y;
app->yaw += dx * app->mouse_sens;
app->pitch -= dy * app->mouse_sens;
app->scene.camera.yaw += dx * app->mouse_sens;
app->scene.camera.pitch -= dy * app->mouse_sens;
last_x = x;
last_y = y;
return (0);
+10 -10
View File
@@ -6,13 +6,13 @@
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/17 19:24:30 by yantoine #+# #+# */
/* Updated: 2025/02/17 21:54:39 by yantoine ### ########.fr */
/* Updated: 2025/02/17 23:08:52 by yantoine ### ########.fr */
/* */
/* ************************************************************************** */
#include "miniRT.h"
static void render_pixel(t_app *app, int x, int y, t_scene scene)
static void render_pixel(t_app *app, int x, int y)
{
t_calc calc;
unsigned char r;
@@ -22,23 +22,23 @@ static void render_pixel(t_app *app, int x, int y, t_scene scene)
calc.ndc_x = (x + 0.5f) / app->win_width;
calc.ndc_y = (y + 0.5f) / app->win_height;
calc.aspect = (float)app->win_width / app->win_height;
calc.scale = tanf((app->fov * 0.5f) * (M_PI / 180.0f));
calc.scale = tanf((app->scene.camera.fov * 0.5f) * (M_PI / 180.0f));
calc.screen_x = (2 * calc.ndc_x - 1) * calc.aspect * calc.scale;
calc.screen_y = (1 - 2 * calc.ndc_y) * calc.scale;
calc.ray_dir = vec3_add(app->cam_dir,
vec3_add(vec3_scale(app->right, calc.screen_x),
vec3_scale(app->cam_up, calc.screen_y)));
calc.ray_dir = vec3_add(app->scene.camera.camDir,
vec3_add(vec3_scale(app->scene.camera.right, calc.screen_x),
vec3_scale(app->scene.camera.up, calc.screen_y)));
calc.ray_dir = vec3_normalize(calc.ray_dir);
calc.ray.origin = app->cam_pos;
calc.ray.origin = app->scene.camera.camPos;
calc.ray.dir = calc.ray_dir;
calc.color = trace(calc.ray, scene);
calc.color = trace(calc.ray, app->scene);
r = (unsigned char)(fminf(calc.color.x, 1.0f) * 255);
g = (unsigned char)(fminf(calc.color.y, 1.0f) * 255);
b = (unsigned char)(fminf(calc.color.z, 1.0f) * 255);
app->pixels[y * app->win_width + x] = (255 << 24) | (r << 16) | (g << 8) | b;
}
void render_scene(t_app *app, t_scene scene)
void render_scene(t_app *app)
{
int y;
int x;
@@ -49,7 +49,7 @@ void render_scene(t_app *app, t_scene scene)
x = 0;
while (x < app->win_width)
{
render_pixel(app, x, y, scene);
render_pixel(app, x, y);
x++;
}
y++;
+8 -12
View File
@@ -287,9 +287,6 @@ c miniRT.h /^ float c;$/;" m struct:s_calc typeref:typename:float
calcLighting trace.c /^t_vec3 calcLighting(t_vec3 hitPoint, t_vec3 hitNormal, t_vec3 objColor, t_scene scene) {$/;" f typeref:typename:t_vec3
camDir miniRT.h /^ t_vec3 camDir;$/;" m struct:s_camera typeref:typename:t_vec3
camPos miniRT.h /^ t_vec3 camPos;$/;" m struct:s_camera typeref:typename:t_vec3
cam_dir miniRT.h /^ t_vec3 cam_dir;$/;" m struct:s_app typeref:typename:t_vec3
cam_pos miniRT.h /^ t_vec3 cam_pos;$/;" m struct:s_app typeref:typename:t_vec3
cam_up miniRT.h /^ t_vec3 cam_up;$/;" m struct:s_app typeref:typename:t_vec3
camera miniRT.h /^ t_camera camera;$/;" m struct:s_scene typeref:typename:t_camera
center miniRT.h /^ t_vec3 center;$/;" m struct:s_cylinder typeref:typename:t_vec3
center miniRT.h /^ t_vec3 center;$/;" m struct:s_sphere typeref:typename:t_vec3
@@ -358,7 +355,6 @@ fd_if_exit miniRT.h /^ int fd_if_exit;$/;" m struct:s_scene typeref:typename:in
format libft/printf_fd.c /^static int format(const char *str, t_info *info, va_list *args)$/;" f typeref:typename:int file:
format minilibx-linux/mlx_int.h /^ int format;$/;" m struct:s_img typeref:typename:int
fov miniRT.h /^ float fov;$/;" m struct:s_camera typeref:typename:float
fov miniRT.h /^ float fov;$/;" m struct:s_app typeref:typename:float
free_array libft/ft_split.c /^static void free_array(char **s1)$/;" f typeref:typename:void file:
ft_arraylen array.c /^int ft_arraylen(char **array)$/;" f typeref:typename:int
ft_atof ft_atof.c /^float ft_atof(char *str)$/;" f typeref:typename:float
@@ -554,7 +550,7 @@ mouse_sens miniRT.h /^ float mouse_sens;$/;" m struct:s_app typeref:typename:flo
mouse_win1 minilibx-linux/test/main.c /^int mouse_win1(int button,int x,int y, void *p)$/;" f typeref:typename:int
mouse_win2 minilibx-linux/test/main.c /^int mouse_win2(int button,int x,int y, void *p)$/;" f typeref:typename:int
mouse_win3 minilibx-linux/test/main.c /^int mouse_win3(int x,int y, void *p)$/;" f typeref:typename:int
move_speed miniRT.h /^ float move_speed;$/;" m struct:s_app typeref:typename:float
move_speed miniRT.h /^ float move_speed;$/;" m struct:s_camera typeref:typename:float
n miniRT.h /^ t_vec3 n;$/;" m struct:s_calc typeref:typename:t_vec3
name minilibx-linux/mlx_int.h /^ char *name;$/;" m struct:s_col_name typeref:typename:char *
name minilibx-linux/mlx_int.h /^ int name;$/;" m struct:s_xpm_col typeref:typename:int
@@ -587,7 +583,6 @@ parsing_plane parsing_plane.c /^t_scene parsing_plane(t_scene scene)$/;" f typer
parsing_sphere parsing_sphere.c /^t_scene parsing_sphere(t_scene scene)$/;" f typeref:typename:t_scene
partie_entiere libft/ft_strtod.c /^static int partie_entiere(double *entier, char *string, int i, double *sign)$/;" f typeref:typename:int file:
pitch miniRT.h /^ float pitch; \/\/ vue de haut en bas en radians$/;" m struct:s_camera typeref:typename:float
pitch miniRT.h /^ float pitch;$/;" m struct:s_app typeref:typename:float
pix minilibx-linux/mlx_int.h /^ Pixmap pix;$/;" m struct:s_img typeref:typename:Pixmap
pixels miniRT.h /^ int *pixels;$/;" m struct:s_app typeref:typename:int *
planes miniRT.h /^ t_plane planes[MAX_PLANES];$/;" m struct:s_scene typeref:typename:t_plane[]
@@ -610,11 +605,11 @@ re libft/Makefile /^re: fclean all$/;" t
re makefile /^re: fclean all$/;" t
re minilibx-linux/Makefile /^re : clean all$/;" t
re minilibx-linux/test/Makefile.mk /^re: clean all$/;" t
render_pixel render.c /^static void render_pixel(t_app *app, int x, int y, t_scene scene)$/;" f typeref:typename:void file:
render_scene render.c /^void render_scene(t_app *app, t_scene scene)$/;" f typeref:typename:void
right miniRT.h /^ t_vec3 right;$/;" m struct:s_app typeref:typename:t_vec3
render_pixel render.c /^static void render_pixel(t_app *app, int x, int y)$/;" f typeref:typename:void file:
render_scene render.c /^void render_scene(t_app *app)$/;" f typeref:typename:void
right miniRT.h /^ t_vec3 right;$/;" m struct:s_camera typeref:typename:t_vec3
root minilibx-linux/mlx_int.h /^ Window root;$/;" m struct:s_xvar typeref:typename:Window
rot_speed miniRT.h /^ float rot_speed;$/;" m struct:s_app typeref:typename:float
rot_speed miniRT.h /^ float rot_speed;$/;" m struct:s_camera typeref:typename:float
s_ambient miniRT.h /^typedef struct s_ambient$/;" s
s_app miniRT.h /^typedef struct s_app$/;" s
s_calc miniRT.h /^typedef struct s_calc$/;" s
@@ -635,6 +630,7 @@ s_xpm_col minilibx-linux/mlx_int.h /^typedef struct s_xpm_col$/;" s
s_xvar minilibx-linux/mlx_int.h /^typedef struct s_xvar$/;" s
saved_mode minilibx-linux/mlx_ext_randr.c /^RRMode saved_mode = 0;$/;" v typeref:typename:RRMode
scale miniRT.h /^ float scale;$/;" m struct:s_calc typeref:typename:float
scene miniRT.h /^ t_scene scene;$/;" m struct:s_app typeref:typename:t_scene
screen minilibx-linux/mlx_int.h /^ int screen;$/;" m struct:s_xvar typeref:typename:int
screen_x miniRT.h /^ float screen_x;$/;" m struct:s_calc typeref:typename:float
screen_y miniRT.h /^ float screen_y;$/;" m struct:s_calc typeref:typename:float
@@ -687,10 +683,11 @@ token_if_exit miniRT.h /^ char **token_if_exit;$/;" m struct:s_scene typeref:t
trace trace.c /^t_vec3 trace(t_ray ray, t_scene scene) {$/;" f typeref:typename:t_vec3
treat_int libft/printf_fd.c /^static int treat_int(int n, char *str, int numdig, t_info *info)$/;" f typeref:typename:int file:
type minilibx-linux/mlx_int.h /^ int type;$/;" m struct:s_img typeref:typename:int
up miniRT.h /^ t_vec3 up;$/;" m struct:s_camera typeref:typename:t_vec3
update_camera update_camera.c /^void update_camera(t_app *app)$/;" f typeref:typename:void
update_camera_movement update_camera.c /^static void update_camera_movement(t_app *app)$/;" f typeref:typename:void file:
update_camera_rotation update_camera.c /^static void update_camera_rotation(t_app *app)$/;" f typeref:typename:void file:
update_frame frame.c /^int update_frame(t_app *app, t_scene scene)$/;" f typeref:typename:int
update_frame frame.c /^int update_frame(t_app *app)$/;" f typeref:typename:int
use_xshm minilibx-linux/mlx_int.h /^ int use_xshm;$/;" m struct:s_xvar typeref:typename:int
v miniRT.h /^ t_vec3 v;$/;" m struct:s_calc typeref:typename:t_vec3
vec3_add calcul_de_vecteur.c /^t_vec3 vec3_add(t_vec3 a, t_vec3 b)$/;" f typeref:typename:t_vec3
@@ -722,5 +719,4 @@ xpm1_y minilibx-linux/test/main.c /^int xpm1_y;$/;" v typeref:typename:int
y miniRT.h /^ float y;$/;" m struct:s_vec3 typeref:typename:float
y miniRT.h /^ float y;$/;" m struct:s_calc typeref:typename:float
yaw miniRT.h /^ float yaw;\/\/ vue de gauche a droite$/;" m struct:s_camera typeref:typename:float
yaw miniRT.h /^ float yaw;$/;" m struct:s_app typeref:typename:float
z miniRT.h /^ float z;$/;" m struct:s_vec3 typeref:typename:float
+24 -24
View File
@@ -6,7 +6,7 @@
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/17 19:27:23 by yantoine #+# #+# */
/* Updated: 2025/02/17 19:30:13 by yantoine ### ########.fr */
/* Updated: 2025/02/17 23:07:57 by yantoine ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,40 +15,40 @@
static void update_camera_rotation(t_app *app)
{
if (app->key_left)
app->yaw -= app->rot_speed;
app->scene.camera.yaw -= app->scene.camera.rot_speed;
if (app->key_right)
app->yaw += app->rot_speed;
app->scene.camera.yaw += app->scene.camera.rot_speed;
if (app->key_up)
app->pitch += app->rot_speed;
app->scene.camera.pitch += app->scene.camera.rot_speed;
if (app->key_down)
app->pitch -= app->rot_speed;
if (app->pitch > 1.57f - 0.01f)
app->pitch = 1.57f - 0.01f;
if (app->pitch < -1.57f + 0.01f)
app->pitch = -1.57f + 0.01f;
app->cam_dir.x = cosf(app->pitch) * sinf(app->yaw);
app->cam_dir.y = sinf(app->pitch);
app->cam_dir.z = -cosf(app->pitch) * cosf(app->yaw);
app->cam_dir = vec3_normalize(app->cam_dir);
app->right = (t_vec3){cosf(app->yaw), 0, sinf(app->yaw)};
app->right = vec3_normalize(app->right);
app->cam_up = vec3_normalize(vec3_cross(app->right, app->cam_dir));
app->scene.camera.pitch -= app->scene.camera.rot_speed;
if (app->scene.camera.pitch > 1.57f - 0.01f)
app->scene.camera.pitch = 1.57f - 0.01f;
if (app->scene.camera.pitch < -1.57f + 0.01f)
app->scene.camera.pitch = -1.57f + 0.01f;
app->scene.camera.camDir.x = cosf(app->scene.camera.pitch) * sinf(app->scene.camera.yaw);
app->scene.camera.camDir.y = sinf(app->scene.camera.pitch);
app->scene.camera.camDir.z = -cosf(app->scene.camera.pitch) * cosf(app->scene.camera.yaw);
app->scene.camera.camDir = vec3_normalize(app->scene.camera.camDir);
app->scene.camera.right = (t_vec3){cosf(app->scene.camera.yaw), 0, sinf(app->scene.camera.yaw)};
app->scene.camera.right = vec3_normalize(app->scene.camera.right);
app->scene.camera.up = vec3_normalize(vec3_cross(app->scene.camera.right, app->scene.camera.camDir));
}
static void update_camera_movement(t_app *app)
{
if (app->key_w)
app->cam_pos = vec3_add(app->cam_pos,
vec3_scale(app->cam_dir, app->move_speed));
app->scene.camera.camPos = vec3_add(app->scene.camera.camPos,
vec3_scale(app->scene.camera.camDir, app->scene.camera.move_speed));
if (app->key_s)
app->cam_pos = vec3_sub(app->cam_pos,
vec3_scale(app->cam_dir, app->move_speed));
app->scene.camera.camPos = vec3_sub(app->scene.camera.camPos,
vec3_scale(app->scene.camera.camDir, app->scene.camera.move_speed));
if (app->key_a)
app->cam_pos = vec3_sub(app->cam_pos,
vec3_scale(app->right, app->move_speed));
app->scene.camera.camPos = vec3_sub(app->scene.camera.camPos,
vec3_scale(app->scene.camera.right, app->scene.camera.move_speed));
if (app->key_d)
app->cam_pos = vec3_add(app->cam_pos,
vec3_scale(app->right, app->move_speed));
app->scene.camera.camPos = vec3_add(app->scene.camera.camPos,
vec3_scale(app->scene.camera.right, app->scene.camera.move_speed));
}
void update_camera(t_app *app)