This commit is contained in:
Ladebeze66
2024-01-25 15:16:02 +01:00
parent 4e8cb2de1b
commit 50ff43445b
6 changed files with 147 additions and 74 deletions

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/23 20:46:34 by fgras-ca ### ########.fr */
/* Updated: 2024/01/25 14:58:34 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -38,6 +38,9 @@ void drawray(t_ray_params *rayparams)
{
t_line_params lineparams;
t_texture_params textureparams;
float olineh;
int deca;
int color;
rayparams->start3DHeight = 0;
rayparams->max3DHeight = rayparams->w->s_win.height
@@ -49,6 +52,7 @@ void drawray(t_ray_params *rayparams)
rayparams->lineH = rayparams->max3DHeight;
}
rayparams->lineOff = ((rayparams->max3DHeight - rayparams->lineH) / 2);
olineh = (rayparams->w->s_map.mapS * rayparams->w->s_win.height) / rayparams->disT;
rayparams->backgroundOffsetX = BOV;
rayparams->raywidth = rayparams->w->s_win.width / rayparams->numRays;
textureparams.startX = rayparams->r * rayparams->raywidth
@@ -57,5 +61,75 @@ void drawray(t_ray_params *rayparams)
init_texture_params(&textureparams, rayparams);
init_line_params(&lineparams, rayparams);
draw_line(&lineparams);
draw_texture(&textureparams);
if (olineh > rayparams->w->s_win.height)
deca = olineh - rayparams->w->s_win.height;
else
deca = 0;
//draw_black_ground(rayparams);
if (deca != 0)
draw_yolo(rayparams, &textureparams, deca);
else
draw_texture(&textureparams);
}
void draw_yolo(t_ray_params *rparams, t_texture_params *tparams, int deca)
{
int texturewidth;
int textureheight;
int i;
int y;
int x;
float perspectivefactor;
int texturex;
int color;
texturewidth = tparams->w->s_img.texture_width;
textureheight = tparams->w->s_img.texture_height;
i = 0;
for (y = rparams->lineOff; y < rparams->lineOff + rparams->lineH; y++) {
// La variable perspectiveFactor permet de mapper la texture en tenant compte de la perspective
perspectivefactor = (float)(y - rparams->lineOff) / rparams->lineH;
int textureY = perspectivefactor * (textureheight );
if (textureY >= textureheight) {
textureY = textureheight - 1;
}
//for (int x = startX; x < endX; x++) {
x = tparams->startX;
switch (tparams->wallDir) {
case NORTH:
case SOUTH:
// Assurez-vous que rx est normalisé correctement pour le mappage de texture
texturex = (int)(tparams->rx * texturewidth / tparams->w->s_map.mapS) % texturewidth;
break;
case WEST:
case EAST:
// Assurez-vous que ry est normalisé correctement pour le mappage de texture
texturex = (int)(tparams->ry * texturewidth / tparams->w->s_map.mapS) % texturewidth;
break;
}
if (texturex >= texturewidth) {
texturex = texturewidth - 1;
}
//printf("%f %f\n",lineOff, lineOff/lineH);
color = get_texture_color(tparams->w, tparams->wallDir, texturex, y);
// BLOCK OK MEH
// float ww = ((720+merde)/lineH);
// //printf("%d %d %d\n", t ,td, merde);
// put_pixel_img(w, x, (int)(iii*ww)-merde/2, color);
// iii++;
int a = tparams->lineOff - deca / 2;
int b = tparams->lineH + (deca /2);
int c = tparams->lineH;
double step = (b - a)/(double)(c - 1);
//printf("%d %d %d\n", t ,td, merde);
put_pixel_img(tparams->w, x, (int)(a + i * step), color);
i++;
//}
}
}

View File

@@ -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/20 11:18:10 by fgras-ca ### ########.fr */
/* Updated: 2024/01/25 14:56:59 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -45,3 +45,16 @@ void draw_background(t_structure_main *w)
ground_params.backgroundOffsetX = backgroundoffsetx;
draw_sky_ground(&ground_params);
}
void draw_black_ground(t_ray_params *params)
{
t_square_params square_params;
square_params.w = params->w;
square_params.y = params->texture.startX;
square_params.x = params->lineOff;
square_params.yo = params->texture.startX + 1;
square_params.xo = params->lineOff + params->lineH ;
square_params.color = 0x000000;
draw_square_raw(&square_params);
}