mirror of
https://github.com/Ladebeze66/cub3D.git
synced 2026-11-09 13:47:10 +01:00
versiontexturecouleur
This commit is contained in:
@@ -6,84 +6,89 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/12 17:49:42 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/14 23:34:45 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/17 21:47:17 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../cub3d.h"
|
||||
|
||||
void drawRays2D(t_structure_main *w)
|
||||
float correctfisheye(float distance, float ra, float playerAngle)
|
||||
{
|
||||
int r;
|
||||
int color;
|
||||
int tilesize;
|
||||
int numrays;
|
||||
float ra;
|
||||
float disH;
|
||||
float disV;
|
||||
float disT;
|
||||
float hx;
|
||||
float hy;
|
||||
float vx;
|
||||
float vy;
|
||||
float FOV;
|
||||
float DR;
|
||||
WallDirection hwalldir;
|
||||
WallDirection vwalldir;
|
||||
t_ray_params rayparams;
|
||||
t_ray_calc_params hrayparams;
|
||||
t_ray_calc_params vrayparams;
|
||||
float ca;
|
||||
|
||||
tilesize = w->s_map.mapS;
|
||||
numrays = NUMRAY;
|
||||
FOV = FOVIEW * (PI / 180);
|
||||
DR = FOV / numrays;
|
||||
ca = playerAngle - ra;
|
||||
if (ca < 0)
|
||||
ca += 2 * PI;
|
||||
if (ca > 2 * PI)
|
||||
ca -= 2 * PI;
|
||||
return (distance * cos(ca));
|
||||
}
|
||||
|
||||
void init_base_params(t_base_params *params, t_structure_main *w)
|
||||
{
|
||||
params->tilesize = w->s_map.mapS;
|
||||
params->numrays = NUMRAY;
|
||||
params->FOV = FOVIEW * (PI / 180);
|
||||
params->DR = params->FOV / params->numrays;
|
||||
params->ra = w->s_player.pa - (params->FOV / 2);
|
||||
printf("DEBUG: Initialisation des paramètres de base\n");
|
||||
printf("DEBUG: tilesize (taille de la tuile) = %d\n", w->s_map.mapS);
|
||||
printf("DEBUG: numrays (nombre de rayons) = %d\n", NUMRAY);
|
||||
printf("DEBUG: FOV (champ de vision) = %f\n", FOVIEW * (PI / 180));
|
||||
printf("DEBUG: DR (delta rayon) = %f\n", params->FOV / params->numrays);
|
||||
printf("DEBUG: ra (rayon actuel) = %f\n", w->s_player.pa - (params->FOV / 2));
|
||||
draw_background(w);
|
||||
}
|
||||
|
||||
ra = w->s_player.pa - (FOV / 2);
|
||||
r = 0;
|
||||
while (r++ < numrays)
|
||||
void calculate_ray(t_base_params *base, t_ray_state *state,
|
||||
t_ray_calc *calc, t_ray_params *rayparams)
|
||||
{
|
||||
if (state->disH < state->disV)
|
||||
{
|
||||
ra = fmod(ra + 2 * PI, 2 * PI);
|
||||
rayparams->disT = state->disH;
|
||||
calc->color = 0xFF0000;
|
||||
rayparams->wallDir = state->hwalldir;
|
||||
rayparams->rx = state->hx;
|
||||
rayparams->ry = state->hy;
|
||||
}
|
||||
else
|
||||
{
|
||||
rayparams->disT = state->disV;
|
||||
calc->color = 0x00FF00;
|
||||
rayparams->wallDir = state->vwalldir;
|
||||
rayparams->rx = state->vx;
|
||||
rayparams->ry = state->vy;
|
||||
}
|
||||
rayparams->disT = correctfisheye(rayparams->disT,
|
||||
base->ra, calc->w->s_player.pa);
|
||||
rayparams->w = calc->w;
|
||||
rayparams->tileSize = base->tilesize;
|
||||
rayparams->r = calc->r;
|
||||
rayparams->numRays = base->numrays;
|
||||
rayparams->color = calc->color;
|
||||
}
|
||||
|
||||
hrayparams.w = w;
|
||||
hrayparams.ra = ra;
|
||||
hrayparams.disRay = &disH;
|
||||
hrayparams.rx = &hx;
|
||||
hrayparams.ry = &hy;
|
||||
hrayparams.wallDir = &hwalldir;
|
||||
calculatehorizontalray(&hrayparams);
|
||||
vrayparams.w = w;
|
||||
vrayparams.ra = ra;
|
||||
vrayparams.disRay = &disV;
|
||||
vrayparams.rx = &vx;
|
||||
vrayparams.ry = &vy;
|
||||
vrayparams.wallDir = &vwalldir;
|
||||
calculateverticalray(&vrayparams);
|
||||
if (disH < disV)
|
||||
{
|
||||
disT = disH;
|
||||
color = 0xFF0000;
|
||||
rayparams.wallDir = hwalldir;
|
||||
rayparams.rx = hx;
|
||||
rayparams.ry = hy;
|
||||
}
|
||||
else
|
||||
{
|
||||
disT = disV;
|
||||
color = 0x00FF00;
|
||||
rayparams.wallDir = vwalldir;
|
||||
rayparams.rx = vx;
|
||||
rayparams.ry = vy;
|
||||
}
|
||||
disT = correctFisheye(disT, ra, w->s_player.pa);
|
||||
rayparams.w = w;
|
||||
rayparams.tileSize = tilesize;
|
||||
rayparams.r = r;
|
||||
rayparams.disT = disT;
|
||||
rayparams.numRays = numrays;
|
||||
rayparams.color = color;
|
||||
drawray(&rayparams);
|
||||
ra += DR;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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/20 11:18:10 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -35,13 +35,13 @@ void draw_background(t_structure_main *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);
|
||||
}
|
||||
|
||||
@@ -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/14 20:56:42 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/20 11:12:22 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -32,10 +32,10 @@ void load_texture(t_structure_main *w, char *file_path, void **texture_ptr)
|
||||
|
||||
void load_wall_textures(t_structure_main *w)
|
||||
{
|
||||
load_texture(w, "textures/NO.xpm", (void **)&w->s_img.north_texture);
|
||||
load_texture(w, "textures/SO.xpm", (void **)&w->s_img.south_texture);
|
||||
load_texture(w, "textures/WE.xpm", (void **)&w->s_img.west_texture);
|
||||
load_texture(w, "textures/EA.xpm", (void **)&w->s_img.east_texture);
|
||||
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);
|
||||
}
|
||||
|
||||
void exit_error(t_structure_main *w)
|
||||
|
||||
@@ -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/14 21:26:16 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/20 11:05:59 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -60,6 +60,7 @@ void draw_texture(t_texture_params *params)
|
||||
|
||||
void *get_selected_texture(t_structure_main *w, WallDirection wallDir)
|
||||
{
|
||||
void *texture = NULL;
|
||||
if (wallDir == NORTH)
|
||||
return (w->s_img.north_texture);
|
||||
else if (wallDir == SOUTH)
|
||||
@@ -74,6 +75,10 @@ void *get_selected_texture(t_structure_main *w, WallDirection wallDir)
|
||||
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);
|
||||
}
|
||||
|
||||
t_texture_data get_texture_data(void *texture)
|
||||
@@ -97,6 +102,7 @@ int get_texture_color(t_structure_main *w, WallDirection wallDir,
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
texture_data = get_texture_data(selected_texture);
|
||||
pixel_pos = (textureX + textureY * w->s_img.texture_width)
|
||||
* (texture_data.bpp / 8);
|
||||
|
||||
Reference in New Issue
Block a user