This commit is contained in:
Ladebeze66 2024-01-22 16:33:54 +01:00
parent 6d8196504c
commit 84c17810af
13 changed files with 49 additions and 63 deletions

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/12 17:49:42 by fgras-ca #+# #+# */
/* Updated: 2024/01/21 21:17:37 by fgras-ca ### ########.fr */
/* Updated: 2024/01/22 16:15:17 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@ -31,7 +31,7 @@ void init_base_params(t_base_params *params, t_structure_main *w)
params->FOV = FOVIEW * (PI / 180);
params->DR = params->FOV / params->numrays;
params->ra = w->s_player.pa - (params->FOV / 2);
//printf("initbaseparams: %d , %f\n", params->tilesize, params->ra);
printf("init_base_params: Player Position: x = %f, y = %f, Angle = %f\n", w->s_player.px, w->s_player.py, w->s_player.pa);
draw_background(w);
}
@ -61,6 +61,7 @@ void calculate_ray(t_base_params *base, t_ray_state *state,
rayparams->r = calc->r;
rayparams->numRays = base->numrays;
rayparams->color = calc->color;
printf("calculate_ray: Ray #%d, Distance = %f, rx = %f, ry = %f, Wall Direction = %d\n", calc->r, rayparams->disT, rayparams->rx, rayparams->ry, rayparams->wallDir);
}
void drawrays2d(t_structure_main *w) {
@ -73,7 +74,7 @@ void drawrays2d(t_structure_main *w) {
params.base_params.ra = fmod(params.base_params.ra + 2 * PI, 2 * PI);
// Ajout de logs pour les paramètres du rayon
printf("drawrays2d BEFORE: Ray #%d, Angle (ra) = %f\n", params.ray_calc.r, params.base_params.ra);
//printf("drawrays2d BEFORE: Ray #%d, Angle (ra) = %f\n", params.ray_calc.r, params.base_params.ra);
params.hrayparams = (t_ray_calc_params){w, params.base_params.ra,
&params.ray_state.disH, &params.ray_state.hx,
@ -85,14 +86,14 @@ void drawrays2d(t_structure_main *w) {
calculateverticalray(&params.vrayparams);
calculate_ray(&params.base_params, &params.ray_state,
&params.ray_calc, &params.rayparams);
printf("drawrays2d AFTER : Ray #%d, ra: %f\n", params.ray_calc.r, params.base_params.ra);
printf("drawrays2d AFTER : Ray #%d, ra: %f\n", params.ray_calc.r, params.base_params.ra);
//Plus de logs après les calculs des rayons
//printf("drawrays2d: Ray #%d, Player Position: x = %f, y = %f, Angle (ra) = %f\n",
// params.ray_calc.r, w->s_player.px, w->s_player.py, params.base_params.ra);
//printf("Horizontal Ray: Distance = %f, x = %f, y = %f\n", params.ray_state.disH, params.ray_state.hx, params.ray_state.hy);
//printf("Vertical Ray: Distance = %f, x = %f, y = %f\n", params.ray_state.disV, params.ray_state.vx, params.ray_state.vy);
//printf("Drawray start\n");
drawray(&params.rayparams);
params.base_params.ra += params.base_params.DR;
}

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/12 17:35:53 by fgras-ca #+# #+# */
/* Updated: 2024/01/21 19:55:50 by fgras-ca ### ########.fr */
/* Updated: 2024/01/22 15:44:42 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 14:09:52 by fgras-ca #+# #+# */
/* Updated: 2024/01/21 21:40:56 by fgras-ca ### ########.fr */
/* Updated: 2024/01/22 13:25:35 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,17 +16,17 @@ void calculate_future_position(t_position_params *params) {
*(params->future_px) = params->px + params->pdx + params->collisionBuffer;
*(params->future_py) = params->py + params->pdy + params->collisionBuffer;
printf("calculate_future_position: Current px = %d, pdx = %d, collisionBuffer = %d\n", params->px, params->pdx, params->collisionBuffer);
printf("calculate_future_position: Current py = %d, pdy = %d, collisionBuffer = %d\n", params->py, params->pdy, params->collisionBuffer);
printf("calculate_future_position: Calculated Future Position: x = %d, y = %d\n", *(params->future_px), *(params->future_py));
//printf("calculate_future_position: Current px = %d, pdx = %d, collisionBuffer = %d\n", params->px, params->pdx, params->collisionBuffer);
//printf("calculate_future_position: Current py = %d, pdy = %d, collisionBuffer = %d\n", params->py, params->pdy, params->collisionBuffer);
//printf("calculate_future_position: Calculated Future Position: x = %d, y = %d\n", *(params->future_px), *(params->future_py));
}
int check_collision(t_structure_main *w, int future_px, int future_py) {
int future_ipx = future_px / w->s_map.mapS;
int future_ipy = future_py / w->s_map.mapS;
printf("check_collision: Checking Collision at Future Map Index: x = %d, y = %d\n", future_ipx, future_ipy);
printf("check_collision: Collision Status: %s\n", w->s_map.map[future_ipy * w->s_map.mapX + future_ipx] == '0' ? "No Collision" : "Collision Detected");
//printf("check_collision: Checking Collision at Future Map Index: x = %d, y = %d\n", future_ipx, future_ipy);
//printf("check_collision: Collision Status: %s\n", w->s_map.map[future_ipy * w->s_map.mapX + future_ipx] == '0' ? "No Collision" : "Collision Detected");
return (w->s_map.map[future_ipy * w->s_map.mapX + future_ipx] == '0');
}
@ -48,6 +48,6 @@ void calculate_future_position_right_left(t_position_params *params) {
*(params->future_px) = collision_px;
*(params->future_py) = collision_py;
printf("calculate_future_position_right_left: Current px = %d, py = %d, direction = %c\n", params->px, params->py, params->direction);
printf("calculate_future_position_right_left: Calculated Future Position: x = %d, y = %d\n", collision_px, collision_py);
//printf("calculate_future_position_right_left: Current px = %d, py = %d, direction = %c\n", params->px, params->py, params->direction);
//printf("calculate_future_position_right_left: Calculated Future Position: x = %d, y = %d\n", collision_px, collision_py);
}

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 14:17:56 by fgras-ca #+# #+# */
/* Updated: 2024/01/21 21:12:41 by fgras-ca ### ########.fr */
/* Updated: 2024/01/22 16:24:44 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@ -35,32 +35,26 @@ int *kill_prog(t_structure_main *w)
return (0);
}
void adjust_player_angle(t_structure_main *w, int key)
{
double angle_adjustment;
printf("adjust_player_angle: Key pressed: %d\n", key);
printf("adjust_player_angle: Before adjustment - pa: %f\n", w->s_player.pa);
void adjust_player_angle(t_structure_main *w, int key) {
const double rotation_speed = 0.174533; // Environ 10 degrés en radians
if (key != 65361 && key != 65363)
return;
angle_adjustment = 16 * ((PI / 3) / NUMRAY);
if (key == 65361)
{
w->s_player.pa -= angle_adjustment;
if (w->s_player.pa < 0)
w->s_player.pa += 2 * PI;
if (key == 65363) { // Touche droite
w->s_player.pa += rotation_speed;
} else if (key == 65361) { // Touche gauche
w->s_player.pa -= rotation_speed;
}
else
{
w->s_player.pa += angle_adjustment;
if (w->s_player.pa > 2 * PI)
w->s_player.pa -= 2 * PI;
// Normalisation de l'angle
if (w->s_player.pa < 0) {
w->s_player.pa += 2 * M_PI;
} else if (w->s_player.pa >= 2 * M_PI) {
w->s_player.pa -= 2 * M_PI;
}
w->s_player.pdx = cos(w->s_player.pa) * 5;
w->s_player.pdy = sin(w->s_player.pa) * 5;
printf("adjust_player_angle: After adjustment - pa: %f\n", w->s_player.pa);
}
void handle_movement_keys(t_structure_main *w, int key)
{
if (key == 119 || key == 100 || key == 115 || key == 97)
@ -81,7 +75,7 @@ int deal_key(int key, t_structure_main *w)
{
adjust_player_angle(w, key);
}
else
else if (key == 119 || key == 100 || key == 115 || key == 97)
{
handle_movement_keys(w, key);
}

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 14:08:25 by fgras-ca #+# #+# */
/* Updated: 2024/01/21 21:09:26 by fgras-ca ### ########.fr */
/* Updated: 2024/01/22 16:10:32 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@ -35,6 +35,7 @@ void move_forward(t_structure_main *w, int key)
w->s_player.px += w->s_player.pdx;
w->s_player.py += w->s_player.pdy;
}
//printf("move %d, pa %f\n", key, w->s_player.pa);
printf("move_forward: After move - px: %f, py: %f\n", w->s_player.px, w->s_player.py);
}
@ -61,6 +62,7 @@ void move_backward(t_structure_main *w, int key)
w->s_player.px -= w->s_player.pdx;
w->s_player.py -= w->s_player.pdy;
}
//printf("move %d, pa %f\n", key, w->s_player.pa);
printf("Move Backward: Player position after moving backward: x = %f, y = %f\n", w->s_player.px, w->s_player.py);
}
@ -87,6 +89,7 @@ void move_right(t_structure_main *w, int key)
w->s_player.px = future_px;
w->s_player.py = future_py;
}
//printf("move %d, pa %f\n", key, w->s_player.pa);
printf("Move Backward: Player position after moving backward: x = %f, y = %f\n", w->s_player.px, w->s_player.py);
}
@ -113,6 +116,7 @@ void move_left(t_structure_main *w, int key)
w->s_player.px = future_px;
w->s_player.py = future_py;
}
//printf("move %d, pa %f\n", key, w->s_player.pa);
printf("Move Backward: Player position after moving backward: x = %f, y = %f\n", w->s_player.px, w->s_player.py);
}

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/14 20:09:23 by fgras-ca #+# #+# */
/* Updated: 2024/01/21 14:33:45 by fgras-ca ### ########.fr */
/* Updated: 2024/01/22 14:16:09 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,48 +14,35 @@
void init_player(t_structure_main *w)
{
// Ajouter des logs pour vérifier les valeurs
printf("Initialisation du joueur:\n");
printf("Position X: %f\n", w->s_map.player_x);
printf("Position Y: %f\n", w->s_map.player_y);
//printf("Initialisation du joueur:\n");
w->s_player.px = w->s_map.player_x;
w->s_player.py = w->s_map.player_y;
if (w->s_map.player_direction == 'N')
{
w->s_player.pa = M_PI;
w->s_player.pdx = 0;
w->s_player.pdy = -5;
}
else if (w->s_map.player_direction == 'S')
{
w->s_player.pa = 0;
w->s_player.pdx = 0;
w->s_player.pdy = 5;
}
else if (w->s_map.player_direction == 'E')
{
w->s_player.pa = M_PI / 2;
w->s_player.pdx = 5;
w->s_player.pdy = 0;
}
else if (w->s_map.player_direction == 'W')
{
w->s_player.pa = 3 * M_PI / 2;
w->s_player.pdx = -5;
w->s_player.pdy = 0;
}
// Ajouter des logs pour vérifier les valeurs après l'initialisation
w->s_player.pdx = cos(w->s_player.pa) * 5;
w->s_player.pdy = sin(w->s_player.pa) * 5;
printf("Angle de direction: %f radians\n", w->s_player.pa);
printf("Vecteur de déplacement X: %f\n", w->s_player.pdx);
printf("Vecteur de déplacement Y: %f\n", w->s_player.pdy);
//printf("Vecteur de déplacement X: %f\n", w->s_player.pdx);
//printf("Vecteur de déplacement Y: %f\n", w->s_player.pdy);
}
void init_mlx_and_window(t_structure_main *w)
{
w->s_win.mlx = mlx_init();

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/15 19:50:24 by fgras-ca #+# #+# */
/* Updated: 2024/01/21 21:10:56 by fgras-ca ### ########.fr */
/* Updated: 2024/01/22 15:41:55 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@ -29,23 +29,23 @@ void rescale_sprite(t_structure_main *w, t_state *state) {
void refresh_window(t_structure_main *w, t_state *state)
{
printf("refresh_window: Destroying old image\n");
//printf("refresh_window: Destroying old image\n");
mlx_destroy_image(w->s_win.mlx, w->s_img.buffer);
//printf("refresh_window: Creating new image\n");
w->s_img.buffer = mlx_new_image(w->s_win.mlx, w->s_win.width,
w->s_win.height);
//printf("refresh_window: Getting data address\n");
printf("refresh_window: Getting data address\n");
w->s_img.addr = mlx_get_data_addr(w->s_img.buffer,
&(w->s_img.bpp), &(w->s_img.line_len), &(w->s_img.endian));
//printf("refresh_window: Drawing map\n");
printf("refresh_window: Drawing map\n");
draw_map(w);
//printf("refresh_window: Drawing rays 2D\n");
printf("refresh_window: Drawing rays 2D\n");
drawrays2d(w);
//printf("refresh_window: Putting image to window\n");
mlx_put_image_to_window(w->s_win.mlx, w->s_win.win, w->s_img.buffer, 0, 0);
//printf("refresh_window: Rescaling sprite\n");
rescale_sprite(w, state);
printf("refresh_window: Window refreshed\n");
//printf("refresh_window: Window refreshed\n");
}
void handle_mouse_movement(t_structure_main *w)