mirror of
https://github.com/Ladebeze66/cub3D.git
synced 2025-12-15 21:56:57 +01:00
68 lines
3.0 KiB
C
68 lines
3.0 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_3d_view.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/01/12 17:35:53 by fgras-ca #+# #+# */
|
|
/* Updated: 2024/01/22 15:44:42 by fgras-ca ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "../cub3d.h"
|
|
|
|
void init_line_params(t_line_params *lineparams, t_ray_params *rayParams)
|
|
{
|
|
lineparams->w = rayParams->w;
|
|
lineparams->x0 = (int)rayParams->w->s_player.px;
|
|
lineparams->y0 = (int)rayParams->w->s_player.py;
|
|
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,
|
|
t_ray_params *rayParams)
|
|
{
|
|
textureparams->w = rayParams->w;
|
|
textureparams->lineOff = rayParams->lineOff;
|
|
textureparams->lineH = rayParams->lineH;
|
|
textureparams->wallDir = rayParams->wallDir;
|
|
textureparams->rx = rayParams->rx + rayParams->backgroundOffsetX;
|
|
textureparams->ry = rayParams->ry;
|
|
textureparams->disT = rayParams->disT;
|
|
}
|
|
|
|
void drawray(t_ray_params *rayparams)
|
|
{
|
|
t_line_params lineparams;
|
|
t_texture_params textureparams;
|
|
|
|
rayparams->start3DHeight = 0;
|
|
rayparams->max3DHeight = rayparams->w->s_win.height
|
|
+ rayparams->start3DHeight;
|
|
rayparams->lineH = (rayparams->tileSize * rayparams->max3DHeight)
|
|
/ rayparams->disT;
|
|
if (rayparams->lineH > rayparams->max3DHeight)
|
|
{
|
|
rayparams->lineH = rayparams->max3DHeight;
|
|
}
|
|
rayparams->lineOff = ((rayparams->max3DHeight - rayparams->lineH) / 2);
|
|
rayparams->backgroundOffsetX = BOV;
|
|
rayparams->raywidth = rayparams->w->s_win.width / rayparams->numRays;
|
|
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);
|
|
draw_texture(&textureparams);
|
|
}
|