update
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* frame.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/17 19:30:45 by yantoine #+# #+# */
|
||||
/* Updated: 2025/02/17 22:55:22 by yantoine ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "miniRT.h"
|
||||
|
||||
int update_frame(t_app *app)
|
||||
{
|
||||
update_camera(app);
|
||||
render_scene(app);
|
||||
mlx_put_image_to_window(app->mlx, app->win, app->img, 0, 0);
|
||||
return (0);
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/17 19:54:03 by yantoine #+# #+# */
|
||||
/* Updated: 2025/02/22 21:32:40 by yantoine ### ########.fr */
|
||||
/* Updated: 2025/02/24 17:03:04 by yantoine ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -43,14 +43,6 @@ static int init_mlx_and_image(t_app *app)
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void setup_hooks(t_app *app)
|
||||
{
|
||||
mlx_hook(app->win, 2, 1L << 0, key_press, app);
|
||||
mlx_hook(app->win, 3, 1L << 1, key_release, app);
|
||||
mlx_hook(app->win, 6, 1L << 6, mouse_move, app);
|
||||
mlx_loop_hook(app->mlx, update_frame, app);
|
||||
}
|
||||
|
||||
static int check_number(t_scene scene)
|
||||
{
|
||||
if (scene.num_camera > MAX_CAMERA)
|
||||
@@ -68,16 +60,20 @@ static int check_number(t_scene scene)
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
t_app app;
|
||||
|
||||
ft_bzero(&app, sizeof(t_app));
|
||||
init_app_config(&app, argc, argv);
|
||||
if (!check_number(app.scene) || 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_hook(app.win, 2, 1L << 0, key_press, &app);
|
||||
mlx_hook(app.win, 17, 0, handle_close, NULL);
|
||||
update_camera(&app);
|
||||
render_scene(&app);
|
||||
mlx_loop(app.mlx);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/13 20:02:36 by yantoine #+# #+# */
|
||||
/* Updated: 2025/02/22 21:21:03 by yantoine ### ########.fr */
|
||||
/* Updated: 2025/02/24 17:02:24 by yantoine ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -262,13 +262,11 @@ void compute_hit_normal(t_ray ray, t_cylinder cy, t_calc *calc,
|
||||
|
||||
// Peripherique
|
||||
int key_press(int keycode, t_app *app);
|
||||
int key_release(int keycode, t_app *app);
|
||||
int mouse_move(int x, int y, t_app *app);
|
||||
int handle_close(void *param);
|
||||
|
||||
// Render
|
||||
void update_camera(t_app *app);
|
||||
void render_scene(t_app *app);
|
||||
int update_frame(t_app *app);
|
||||
|
||||
// Array
|
||||
int ft_arraylen(char **array);
|
||||
|
||||
+7
-57
@@ -6,7 +6,7 @@
|
||||
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/17 19:22:27 by yantoine #+# #+# */
|
||||
/* Updated: 2025/02/17 22:55:44 by yantoine ### ########.fr */
|
||||
/* Updated: 2025/02/24 17:01:54 by yantoine ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -14,66 +14,16 @@
|
||||
|
||||
int key_press(int keycode, t_app *app)
|
||||
{
|
||||
if (keycode == 53)
|
||||
(void)app;
|
||||
printf("keycode: %d\n", keycode);
|
||||
if (keycode == 53 || keycode == 65307)
|
||||
exit(0);
|
||||
if (keycode == 13)
|
||||
app->key_w = 1;
|
||||
if (keycode == 1)
|
||||
app->key_s = 1;
|
||||
if (keycode == 0)
|
||||
app->key_a = 1;
|
||||
if (keycode == 2)
|
||||
app->key_d = 1;
|
||||
if (keycode == 123)
|
||||
app->key_left = 1;
|
||||
if (keycode == 124)
|
||||
app->key_right = 1;
|
||||
if (keycode == 126)
|
||||
app->key_up = 1;
|
||||
if (keycode == 125)
|
||||
app->key_down = 1;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int key_release(int keycode, t_app *app)
|
||||
int handle_close(void *param)
|
||||
{
|
||||
if (keycode == 13)
|
||||
app->key_w = 0;
|
||||
if (keycode == 1)
|
||||
app->key_s = 0;
|
||||
if (keycode == 0)
|
||||
app->key_a = 0;
|
||||
if (keycode == 2)
|
||||
app->key_d = 0;
|
||||
if (keycode == 123)
|
||||
app->key_left = 0;
|
||||
if (keycode == 124)
|
||||
app->key_right = 0;
|
||||
if (keycode == 126)
|
||||
app->key_up = 0;
|
||||
if (keycode == 125)
|
||||
app->key_down = 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int mouse_move(int x, int y, t_app *app)
|
||||
{
|
||||
static int last_x = -1;
|
||||
static int last_y = -1;
|
||||
int dx;
|
||||
int dy;
|
||||
|
||||
if (last_x == -1 || last_y == -1)
|
||||
{
|
||||
last_x = x;
|
||||
last_y = y;
|
||||
return (0);
|
||||
}
|
||||
dx = x - last_x;
|
||||
dy = y - last_y;
|
||||
app->scene.camera.yaw += dx * app->mouse_sens;
|
||||
app->scene.camera.pitch -= dy * app->mouse_sens;
|
||||
last_x = x;
|
||||
last_y = y;
|
||||
(void)param;
|
||||
exit(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/17 19:24:30 by yantoine #+# #+# */
|
||||
/* Updated: 2025/02/22 18:32:17 by yantoine ### ########.fr */
|
||||
/* Updated: 2025/02/24 16:51:15 by yantoine ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -41,9 +41,6 @@ static void render_pixel(t_app *app, int x, int y)
|
||||
|
||||
void render_scene(t_app *app)
|
||||
{
|
||||
const int total_pixels = app->win_height * app->win_width;
|
||||
static int done;
|
||||
static int progress;
|
||||
int y;
|
||||
int x;
|
||||
|
||||
@@ -53,16 +50,12 @@ void render_scene(t_app *app)
|
||||
x = 0;
|
||||
while (x < app->win_width)
|
||||
{
|
||||
progress = ((y * app->win_width + x + 1) * 100) / total_pixels;
|
||||
render_pixel(app, x, y);
|
||||
x++;
|
||||
if (!done)
|
||||
printf("\rChargement de l'écran : %d%% ", progress);
|
||||
else
|
||||
printf("\rTERMINE ");
|
||||
if (progress >= 100)
|
||||
done = 1;
|
||||
}
|
||||
y++;
|
||||
printf("%d / %d\n", y, app->win_height);
|
||||
mlx_put_image_to_window(app->mlx, app->win, app->img, 0, 0);
|
||||
}
|
||||
printf("%d / %d\n", y, app->win_height);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user