2023-04-27 09:13:32 -04:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* raycasting.c :+: :+: :+: */
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
/* Created: 2023/04/27 14:30:29 by erey-bet #+# #+# */
|
2023-05-05 08:00:20 -04:00
|
|
|
/* Updated: 2023/05/05 13:59:57 by erey-bet ### ########.fr */
|
2023-04-27 09:13:32 -04:00
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
#include "game.h"
|
|
|
|
|
2023-05-11 10:25:29 -04:00
|
|
|
int raycasting(t_game *game)
|
2023-05-02 09:39:16 -04:00
|
|
|
{
|
|
|
|
t_ply *p;
|
|
|
|
t_ray *ray;
|
|
|
|
double camera;
|
2023-05-03 11:48:36 -04:00
|
|
|
int x;
|
2023-05-02 09:39:16 -04:00
|
|
|
|
2023-05-03 11:48:36 -04:00
|
|
|
x = 0;
|
|
|
|
p = &game->ply;
|
|
|
|
ray = &game->ray;
|
2023-05-04 08:42:39 -04:00
|
|
|
while (x < WIDTH)
|
2023-05-02 09:39:16 -04:00
|
|
|
{
|
2023-05-05 08:00:20 -04:00
|
|
|
camera = 2 * x / (double)WIDTH - 1;
|
2023-05-02 10:58:55 -04:00
|
|
|
ray->dir_x = p->dir_x + p->pla_x * camera;
|
|
|
|
ray->dir_y = p->dir_y + p->pla_y * camera;
|
2023-05-03 11:48:36 -04:00
|
|
|
dda(game, x);
|
|
|
|
x++;
|
2023-05-02 09:39:16 -04:00
|
|
|
}
|
2023-04-27 09:13:32 -04:00
|
|
|
return (0);
|
|
|
|
}
|