1
0

🔨」 fix(DDA): fixed when some wall where not visible

This commit is contained in:
2024-11-06 12:35:35 +01:00
parent 5cb45ebb8a
commit e32e720545
3 changed files with 17 additions and 11 deletions

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/28 13:04:36 by adjoly #+# #+# */
/* Updated: 2024/11/02 15:57:19 by adjoly ### ########.fr */
/* Updated: 2024/11/06 12:30:52 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,6 +21,7 @@
typedef struct s_dda
{
bool h;
bool s;
int i;
t_vec2 map;
t_vec2 vert;

View File

@ -6,7 +6,7 @@
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/04 16:58:27 by madumerg #+# #+# */
/* Updated: 2024/11/02 14:21:07 by adjoly ### ########.fr */
/* Updated: 2024/11/06 11:50:38 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -48,8 +48,6 @@ int main(int ac, char **av)
render.mlx = mlx_init();
render.win = mlx_new_window(render.mlx, WINDOW_W, WINDOW_H, "WTF");
render.img = mlx_new_image(render.mlx, WINDOW_W, WINDOW_H);
render_frame(&render);
mlx_put_image_to_window(render.mlx, render.win, render.img, 0, 0);
(void)ac;
(void)av;
mlx_on_event(render.mlx, render.win, MLX_KEYDOWN, key_hook, &render);

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/07 16:55:09 by adjoly #+# #+# */
/* Updated: 2024/11/02 15:58:33 by adjoly ### ########.fr */
/* Updated: 2024/11/06 12:34:58 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,8 +18,9 @@
void setup_dda_ver(t_player *play, t_ray *ray, t_dda *dda)
{
dda->distance.x = 100000;
dda->s = true;
dda->h = false;
dda->distance.x = 100000;
ray->tan = tan(ray->angle);
if (cos(ray->angle) < -0.001)
{
@ -39,8 +40,9 @@ void setup_dda_ver(t_player *play, t_ray *ray, t_dda *dda)
void setup_dda_hor(t_player *play, t_ray *ray, t_dda *dda)
{
dda->distance.y = 100000;
dda->h = true;
dda->s = true;
dda->distance.y = 100000;
ray->tan = 1 / tan(ray->angle);
if (sin(ray->angle) < -0.001)
{
@ -56,14 +58,19 @@ void setup_dda_hor(t_player *play, t_ray *ray, t_dda *dda)
ray->pos.y = (((int)play->coord.y >> 6) << 6) - 0.001;
ray->pos.x = (play->coord.y - ray->pos.y) * ray->tan + play->coord.x;
}
else
{
dda->s = false;
ray->pos.x = play->coord.x;
ray->pos.y = play->coord.y;
}
}
void dda_loop(t_dda *dda, t_ray *ray, t_map *map, t_player *play)
{
while (dda->i)
{
dda->map.x = (int)((int)ray->pos.x / 64);
dda->map.y = (int)((int)ray->pos.y / 64);
while (dda->s && dda->i) {
dda->map.x = (ray->pos.x / 64);
dda->map.y = (ray->pos.y / 64);
if (dda->map.x >= 0 && dda->map.x < map->size.x && dda->map.y >= 0 && \
dda->map.y < map->size.y && \
map->arr[(int)dda->map.y][(int)dda->map.x] == '1')