mirror of
https://github.com/Ladebeze66/cub3D.git
synced 2026-11-09 13:47:10 +01:00
manquecorrigetouchesetparsing
This commit is contained in:
@@ -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/17 21:47:17 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/21 21:17:37 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -31,6 +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);
|
||||
draw_background(w);
|
||||
}
|
||||
|
||||
@@ -62,27 +63,37 @@ void calculate_ray(t_base_params *base, t_ray_state *state,
|
||||
rayparams->color = calc->color;
|
||||
}
|
||||
|
||||
void drawrays2d(t_structure_main *w)
|
||||
{
|
||||
t_drawrays2d_params params;
|
||||
void drawrays2d(t_structure_main *w) {
|
||||
t_drawrays2d_params params;
|
||||
|
||||
init_base_params(¶ms.base_params, w);
|
||||
params.ray_calc.w = w;
|
||||
params.ray_calc.r = 0;
|
||||
while (params.ray_calc.r++ < params.base_params.numrays)
|
||||
{
|
||||
params.base_params.ra = fmod(params.base_params.ra + 2 * PI, 2 * PI);
|
||||
params.hrayparams = (t_ray_calc_params){w, params.base_params.ra,
|
||||
¶ms.ray_state.disH, ¶ms.ray_state.hx,
|
||||
¶ms.ray_state.hy, ¶ms.ray_state.hwalldir};
|
||||
params.vrayparams = (t_ray_calc_params){w, params.base_params.ra,
|
||||
¶ms.ray_state.disV, ¶ms.ray_state.vx,
|
||||
¶ms.ray_state.vy, ¶ms.ray_state.vwalldir};
|
||||
calculatehorizontalray(¶ms.hrayparams);
|
||||
calculateverticalray(¶ms.vrayparams);
|
||||
calculate_ray(¶ms.base_params, ¶ms.ray_state,
|
||||
¶ms.ray_calc, ¶ms.rayparams);
|
||||
drawray(¶ms.rayparams);
|
||||
params.base_params.ra += params.base_params.DR;
|
||||
}
|
||||
init_base_params(¶ms.base_params, w);
|
||||
params.ray_calc.w = w;
|
||||
params.ray_calc.r = 0;
|
||||
while (params.ray_calc.r++ < params.base_params.numrays) {
|
||||
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);
|
||||
|
||||
params.hrayparams = (t_ray_calc_params){w, params.base_params.ra,
|
||||
¶ms.ray_state.disH, ¶ms.ray_state.hx,
|
||||
¶ms.ray_state.hy, ¶ms.ray_state.hwalldir};
|
||||
params.vrayparams = (t_ray_calc_params){w, params.base_params.ra,
|
||||
¶ms.ray_state.disV, ¶ms.ray_state.vx,
|
||||
¶ms.ray_state.vy, ¶ms.ray_state.vwalldir};
|
||||
calculatehorizontalray(¶ms.hrayparams);
|
||||
calculateverticalray(¶ms.vrayparams);
|
||||
calculate_ray(¶ms.base_params, ¶ms.ray_state,
|
||||
¶ms.ray_calc, ¶ms.rayparams);
|
||||
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);
|
||||
|
||||
drawray(¶ms.rayparams);
|
||||
params.base_params.ra += params.base_params.DR;
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -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/14 17:19:42 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/21 19:55:50 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -20,6 +20,8 @@ void init_line_params(t_line_params *lineparams, t_ray_params *rayParams)
|
||||
lineparams->x1 = (int)rayParams->rx;
|
||||
lineparams->y1 = (int)rayParams->ry;
|
||||
lineparams->color = rayParams->color;
|
||||
//printf("init_line_params: Player Position: x0 = %d, y0 = %d\n", lineparams->x0, lineparams->y0);
|
||||
//printf("init_line_params: Ray End Position: x1 = %d, y1 = %d\n", lineparams->x1, lineparams->y1);
|
||||
}
|
||||
|
||||
void init_texture_params(t_texture_params *textureparams,
|
||||
@@ -54,6 +56,10 @@ void drawray(t_ray_params *rayparams)
|
||||
textureparams.startX = rayparams->r * rayparams->raywidth
|
||||
+ rayparams->backgroundOffsetX;
|
||||
textureparams.endX = textureparams.startX + rayparams->raywidth;
|
||||
//printf("drawray: Player Position: x = %f, y = %f\n", rayparams->w->s_player.px, rayparams->w->s_player.py);
|
||||
//printf("drawray: Ray Angle: pa = %f\n", rayparams->w->s_player.pa);
|
||||
//printf("drawray: Ray Distance: disT = %f\n", rayparams->disT);
|
||||
//printf("drawray: Ray Height: lineH = %f\n", rayparams->lineH);
|
||||
init_line_params(&lineparams, rayparams);
|
||||
draw_line(&lineparams);
|
||||
init_texture_params(&textureparams, rayparams);
|
||||
|
||||
Binary file not shown.
@@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/11 23:19:39 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/14 17:37:52 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/21 13:23:24 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -32,16 +32,21 @@ void draw_background(t_structure_main *w)
|
||||
t_sky_ground_params ground_params;
|
||||
|
||||
backgroundoffsetx = BOV;
|
||||
if (!w || !w->t)
|
||||
{
|
||||
fprintf(stderr, "Structure w or w->t not properly initialized.\n");
|
||||
exit_error(w);
|
||||
}
|
||||
sky_params.w = w;
|
||||
sky_params.startHeight = 0;
|
||||
sky_params.endHeight = w->s_win.height / 2;
|
||||
sky_params.color = 0xB2FFFF;
|
||||
sky_params.color = w->t->ceil_color;
|
||||
sky_params.backgroundOffsetX = backgroundoffsetx;
|
||||
draw_sky_ground(&sky_params);
|
||||
ground_params.w = w;
|
||||
ground_params.startHeight = w->s_win.height / 2;
|
||||
ground_params.endHeight = w->s_win.height;
|
||||
ground_params.color = 0x280000;
|
||||
ground_params.color = w->t->floor_color;
|
||||
ground_params.backgroundOffsetX = backgroundoffsetx;
|
||||
draw_sky_ground(&ground_params);
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/14 20:30:59 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/17 21:45:36 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/21 14:06:26 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -16,8 +16,7 @@ void load_texture(t_structure_main *w, char *file_path, void **texture_ptr)
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
//w->s_win.mlx = mlx_init();
|
||||
printf("file path %s\n", file_path);
|
||||
|
||||
width = 0;
|
||||
height = 0;
|
||||
*texture_ptr = mlx_xpm_file_to_image(w->s_win.mlx,
|
||||
@@ -29,24 +28,26 @@ void load_texture(t_structure_main *w, char *file_path, void **texture_ptr)
|
||||
}
|
||||
w->s_img.texture_width = width;
|
||||
w->s_img.texture_height = height;
|
||||
printf("height %d\n", height);
|
||||
printf("width %d\n", width);
|
||||
printf("Loaded texture from %s: width = %d, height = %d\n", file_path, width, height);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
void load_wall_textures(t_structure_main *w)
|
||||
{
|
||||
printf("load wall texture %s\n", w->t->north);
|
||||
printf("load wall texture %s\n", w->t->south);
|
||||
printf("load wall texture %s\n", w->t->east);
|
||||
printf("load wall texture %s\n", w->t->west);
|
||||
if (!w || !w->t)
|
||||
{
|
||||
fprintf(stderr, "Structures not properly initialized.\n");
|
||||
exit_error(w);
|
||||
}
|
||||
if (!w->t->north || !w->t->south || !w->t->west || !w->t->east)
|
||||
{
|
||||
fprintf(stderr, "One or more texture paths are not set.\n");
|
||||
exit_error(w);
|
||||
}
|
||||
load_texture(w, w->t->north, (void **)&w->s_img.north_texture);
|
||||
load_texture(w, w->t->south, (void **)&w->s_img.south_texture);
|
||||
load_texture(w, w->t->west, (void **)&w->s_img.west_texture);
|
||||
load_texture(w, w->t->east, (void **)&w->s_img.east_texture);
|
||||
printf("load wall texture %s\n", w->t->north);
|
||||
printf("load wall texture %s\n", w->t->south);
|
||||
printf("load wall texture %s\n", w->t->east);
|
||||
printf("load wall texture %s\n", w->t->west);
|
||||
}
|
||||
|
||||
void exit_error(t_structure_main *w)
|
||||
|
||||
Binary file not shown.
@@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/12 17:39:11 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/17 21:38:40 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/21 13:27:19 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -36,7 +36,6 @@ void draw_texture_line(t_texture_params *params, float y, int textureY)
|
||||
put_pixel_img(params->w, x, y, color);
|
||||
x++;
|
||||
}
|
||||
printf("draw_texture_line: texturex = %d, textureY = %d, color = %d\n", texturex, textureY, color);
|
||||
}
|
||||
|
||||
void draw_texture(t_texture_params *params)
|
||||
@@ -56,32 +55,30 @@ void draw_texture(t_texture_params *params)
|
||||
texturey = textureheight - 1;
|
||||
draw_texture_line(params, y, texturey);
|
||||
y++;
|
||||
}printf("draw_texture: y = %f, texturey = %d\n", y, texturey);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void *get_selected_texture(t_structure_main *w, WallDirection wallDir)
|
||||
{
|
||||
void *texture = NULL;
|
||||
if (wallDir == NORTH)
|
||||
return (w->t->north);
|
||||
return (w->s_img.north_texture);
|
||||
else if (wallDir == SOUTH)
|
||||
return (w->t->south);
|
||||
return (w->s_img.south_texture);
|
||||
else if (wallDir == WEST)
|
||||
return (w->t->west);
|
||||
return (w->s_img.west_texture);
|
||||
else if (wallDir == EAST)
|
||||
return (w->t->east);
|
||||
return (w->s_img.east_texture);
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Invalid wall direction.\n");
|
||||
exit_error(w);
|
||||
return (NULL);
|
||||
}
|
||||
if (texture == NULL) {
|
||||
fprintf(stderr, "get_selected_texture: selected texture is NULL\n");
|
||||
} else {
|
||||
printf("get_selected_texture: selected texture = %p\n", texture);
|
||||
}
|
||||
if (texture == NULL)
|
||||
fprintf(stderr, "get_selected_texture: selected texture is NULL\n");
|
||||
else
|
||||
printf("get_selected_texture: selected texture = %p\n", texture);
|
||||
}
|
||||
|
||||
t_texture_data get_texture_data(void *texture)
|
||||
@@ -90,7 +87,6 @@ t_texture_data get_texture_data(void *texture)
|
||||
|
||||
texture_data.data = mlx_get_data_addr(texture, &texture_data.bpp,
|
||||
&texture_data.size_line, &texture_data.endian);
|
||||
printf("get_texture_data: bpp = %d, size_line = %d, endian = %d\n", texture_data.bpp, texture_data.size_line, texture_data.endian);
|
||||
return (texture_data);
|
||||
}
|
||||
|
||||
@@ -103,13 +99,12 @@ int get_texture_color(t_structure_main *w, WallDirection wallDir,
|
||||
|
||||
selected_texture = get_selected_texture(w, wallDir);
|
||||
if (selected_texture == NULL)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
texture_data = get_texture_data(selected_texture);
|
||||
pixel_pos = (textureX + textureY * w->s_img.texture_width)
|
||||
* (texture_data.bpp / 8);
|
||||
printf("get_texture_color: textureX = %d, textureY = %d, pixel_pos = %d\n", textureX, textureY, pixel_pos);
|
||||
if (textureX < 0 || textureX >= w->s_img.texture_width || textureY < 0)
|
||||
return (0);
|
||||
pixel_pos = textureX * (texture_data.bpp / 8) + textureY * texture_data.size_line;
|
||||
if (pixel_pos < 0)
|
||||
return (0);
|
||||
return (*(int *)(texture_data.data + pixel_pos));
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user