1
0

🚧」 test(ft_pipi): pipi popo not working

This commit is contained in:
Maelys
2024-11-01 18:38:58 +01:00
parent 0d54c93764
commit 6e88f4960a
5 changed files with 26 additions and 31 deletions

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/04 14:06:39 by adjoly #+# #+# */
/* Updated: 2024/11/01 15:53:20 by madumerg ### ########.fr */
/* Updated: 2024/11/01 18:15:03 by madumerg ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,14 +21,12 @@
# define D_KEY 7
# define WHITE 0xFFFFFFFF
# define DEG_TO_RAD 0.0174533
# define WINDOW_H 900
# define WINDOW_W 1600
# define PLAYER_ROT_SPEED (2 * M_PI) / 128
# define PLAYER_SPEED 0.01
# define RAY_SIZE 50
# define FOV ( 60 * (M_PI / 180) )
# define FOV 70
# define CHUNK_SIZE 64

View File

@ -6,7 +6,7 @@
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/04 16:58:27 by madumerg #+# #+# */
/* Updated: 2024/11/01 16:16:52 by madumerg ### ########.fr */
/* Updated: 2024/11/01 18:09:53 by madumerg ### ########.fr */
/* */
/* ************************************************************************** */
@ -30,9 +30,9 @@ int main(int ac, char **av)
world.arr = ft_split("11111 10001 10001 10001 11111", ' ');
world.size.x = 5;
world.size.y = 5;
player.coord.x = 2.5;
player.coord.y = 3.5;
player.direction = 2 * M_PI - 0.001;
player.coord.x = 2 * CHUNK_SIZE;
player.coord.y = 3 * CHUNK_SIZE;
player.direction = 0;
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);

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/07 16:55:09 by adjoly #+# #+# */
/* Updated: 2024/11/01 16:13:57 by madumerg ### ########.fr */
/* Updated: 2024/11/01 18:33:52 by madumerg ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,7 +18,7 @@
void setup_dda_ver(t_player *play, t_ray *ray, t_dda *dda)
{
dda->distance.x = 1000000;
dda->distance.x = 100000;
dda->h = false;
dda->s = true;
ray->tan = tan(ray->angle);
@ -27,14 +27,14 @@ void setup_dda_ver(t_player *play, t_ray *ray, t_dda *dda)
ray->offset.x = -CHUNK_SIZE;
ray->offset.y = CHUNK_SIZE * ray->tan;
ray->pos.x = (((int)play->coord.x >> 6) << 6) - 0.001;
ray->pos.y -= (play->coord.x - ray->pos.x) * ray->tan + play->coord.y;
ray->pos.y = (play->coord.x - ray->pos.x) * ray->tan + play->coord.y;
}
else if(cos(ray->angle) > 0.001)
{
ray->offset.x = CHUNK_SIZE;
ray->offset.y = -CHUNK_SIZE * ray->tan;
ray->pos.x = (((int)play->coord.x >> 6) << 6) + CHUNK_SIZE;
ray->pos.y -= (play->coord.x - ray->pos.x) * ray->tan + play->coord.y;
ray->pos.y = (play->coord.x - ray->pos.x) * ray->tan + play->coord.y;
}
else
{
@ -46,7 +46,7 @@ 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 = 1000000;
dda->distance.y = 100000;
dda->s = true;
dda->h = true;
ray->tan = 1 / tan(ray->angle);
@ -62,7 +62,7 @@ void setup_dda_hor(t_player *play, t_ray *ray, t_dda *dda)
ray->offset.y = -CHUNK_SIZE;
ray->offset.x = CHUNK_SIZE * ray->tan;
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;
ray->pos.x = (play->coord.y - ray->pos.y) * ray->tan + play->coord.x;
}
else
{
@ -81,8 +81,8 @@ void dda_loop(t_dda *dda, t_ray *ray, t_map *map, t_player *play)
h = map->size.y;
while (dda->s && dda->i)
{
dda->map.x = (int)(ray->pos.x / 64);
dda->map.y = (int)(ray->pos.y / 64);
dda->map.x = (int)((int)ray->pos.x / 64);
dda->map.y = (int)((int)ray->pos.y / 64);
if (dda->map.x >= 0 && dda->map.x < w && dda->map.y >= 0 && dda->map.y < h && \
map->arr[(int)dda->map.y][(int)dda->map.x] == '1')
{
@ -104,12 +104,16 @@ void dda_algo(t_render *render, t_dda *dda, t_ray *ray)
{
setup_dda_hor(render->player, ray, dda);
dda->i = render->world->size.y;
printf("caca pos = %f, %f\n", ray->pos.x, ray->pos.y);
dda_loop(dda, ray, render->world, render->player);
printf("pipi pos = %f, %f\n", ray->pos.x, ray->pos.y);
dda->hori.x = ray->pos.x;
dda->hori.y = ray->pos.y;
setup_dda_ver(render->player, ray, dda);
dda->i = render->world->size.x;
printf("caca pos = %f, %f\n", ray->pos.x, ray->pos.y);
dda_loop(dda, ray, render->world, render->player);
printf("pipi pos = %f, %f\n", ray->pos.x, ray->pos.y);
dda->vert.x = ray->pos.x;
dda->vert.y = ray->pos.y;
if (dda->distance.y < dda->distance.x)

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/29 10:05:15 by adjoly #+# #+# */
/* Updated: 2024/10/29 10:05:29 by adjoly ### ########.fr */
/* Updated: 2024/11/01 17:25:32 by madumerg ### ########.fr */
/* */
/* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/28 15:48:39 by adjoly #+# #+# */
/* Updated: 2024/11/01 16:30:17 by madumerg ### ########.fr */
/* Updated: 2024/11/01 18:32:01 by madumerg ### ########.fr */
/* */
/* ************************************************************************** */
@ -57,45 +57,38 @@ void print_line(t_render *render, t_ray *ray, int x)
int line;
int line_start;
int y;
int j;
line = (CHUNK_SIZE * WINDOW_H) / ray->distance;
line_start = -line / 2 + WINDOW_H / 2;
y = 0;
while (y < line)
{
j = 0;
while (j < RAY_SIZE)
{
mlx_set_image_pixel(render->mlx, render->img, x + j, line_start + y, WHITE);
j++;
}
mlx_set_image_pixel(render->mlx, render->img, x, line_start + y, WHITE);
y++;
}
}
void render_frame(t_render *render)
{
size_t i;
int i;
t_dda dda;
t_ray ray;
float ang;
i = WINDOW_W;
ray.angle = render->player->direction - (M_PI / 180) / (FOV / 2);
ray.angle = render->player->direction - (M_PI / 180) / ((float)FOV / 2);
fix_ang(&ray.angle);
draw_celling(render);
draw_floor(render);
while(i > 0)
while(i > -1)
{
dda_algo(render, &dda, &ray);
ang = render->player->direction - ray.angle;
fix_ang(&ang);
ray.distance *= cos(ang);
printf("distance = %f\n", ray.distance);
print_line(render, &ray, i);
ray.angle += (M_PI / 180) / ((WINDOW_W * RAY_SIZE) / FOV);
ray.angle += (M_PI / 180) / ((float)WINDOW_W / FOV);
fix_ang(&ray.angle);
i -= RAY_SIZE;
i--;
}
}