「🏗️」 wip(ft_passagepietion): passage pieton working 👍
This commit is contained in:
Submodule MacroLibX updated: 226430f01e...4d640ed70c
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/04 14:06:39 by adjoly #+# #+# */
|
/* Created: 2024/10/04 14:06:39 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/10/29 14:55:59 by adjoly ### ########.fr */
|
/* Updated: 2024/11/01 15:53:20 by madumerg ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -27,7 +27,7 @@
|
|||||||
# define WINDOW_W 1600
|
# define WINDOW_W 1600
|
||||||
# define PLAYER_ROT_SPEED (2 * M_PI) / 128
|
# define PLAYER_ROT_SPEED (2 * M_PI) / 128
|
||||||
# define PLAYER_SPEED 0.01
|
# define PLAYER_SPEED 0.01
|
||||||
# define RAY_SIZE 1
|
# define RAY_SIZE 50
|
||||||
# define FOV ( 60 * (M_PI / 180) )
|
# define FOV ( 60 * (M_PI / 180) )
|
||||||
|
|
||||||
# define CHUNK_SIZE 64
|
# define CHUNK_SIZE 64
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/04 16:58:27 by madumerg #+# #+# */
|
/* Created: 2024/09/04 16:58:27 by madumerg #+# #+# */
|
||||||
/* Updated: 2024/10/30 10:02:56 by adjoly ### ########.fr */
|
/* Updated: 2024/11/01 16:16:52 by madumerg ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -30,9 +30,9 @@ int main(int ac, char **av)
|
|||||||
world.arr = ft_split("11111 10001 10001 10001 11111", ' ');
|
world.arr = ft_split("11111 10001 10001 10001 11111", ' ');
|
||||||
world.size.x = 5;
|
world.size.x = 5;
|
||||||
world.size.y = 5;
|
world.size.y = 5;
|
||||||
player.coord.x = 1;
|
player.coord.x = 2.5;
|
||||||
player.coord.y = 1;
|
player.coord.y = 3.5;
|
||||||
player.direction = 0;
|
player.direction = 2 * M_PI - 0.001;
|
||||||
render.mlx = mlx_init();
|
render.mlx = mlx_init();
|
||||||
render.win = mlx_new_window(render.mlx, WINDOW_W, WINDOW_H, "WTF");
|
render.win = mlx_new_window(render.mlx, WINDOW_W, WINDOW_H, "WTF");
|
||||||
render.img = mlx_new_image(render.mlx, WINDOW_W, WINDOW_H);
|
render.img = mlx_new_image(render.mlx, WINDOW_W, WINDOW_H);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/07 16:55:09 by adjoly #+# #+# */
|
/* Created: 2024/10/07 16:55:09 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/10/30 14:42:06 by adjoly ### ########.fr */
|
/* Updated: 2024/11/01 16:13:57 by madumerg ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,10 +14,12 @@
|
|||||||
#include <game/settings.h>
|
#include <game/settings.h>
|
||||||
#include <game/dda.h>
|
#include <game/dda.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
void setup_dda_hor(t_player *play, t_ray *ray, t_dda *dda)
|
void setup_dda_ver(t_player *play, t_ray *ray, t_dda *dda)
|
||||||
{
|
{
|
||||||
dda->h = true;
|
dda->distance.x = 1000000;
|
||||||
|
dda->h = false;
|
||||||
dda->s = true;
|
dda->s = true;
|
||||||
ray->tan = tan(ray->angle);
|
ray->tan = tan(ray->angle);
|
||||||
if (cos(ray->angle) < -0.001)
|
if (cos(ray->angle) < -0.001)
|
||||||
@ -36,36 +38,37 @@ void setup_dda_hor(t_player *play, t_ray *ray, t_dda *dda)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dda->s = false;
|
|
||||||
ray->pos.x = play->coord.x;
|
ray->pos.x = play->coord.x;
|
||||||
ray->pos.y = play->coord.y;
|
ray->pos.y = play->coord.y;
|
||||||
|
dda->s = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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->s = true;
|
dda->s = true;
|
||||||
dda->h = false;
|
dda->h = true;
|
||||||
ray->tan = 1 / tan(ray->angle);
|
ray->tan = 1 / tan(ray->angle);
|
||||||
if (sin(ray->angle) < -0.001)
|
if (sin(ray->angle) < -0.001)
|
||||||
{
|
{
|
||||||
ray->offset.y = CHUNK_SIZE;
|
ray->offset.y = CHUNK_SIZE;
|
||||||
ray->offset.x = -CHUNK_SIZE * ray->tan;
|
ray->offset.x = -CHUNK_SIZE * ray->tan;
|
||||||
ray->pos.y = (((int)play->coord.y >> 6) << 6) - CHUNK_SIZE;
|
ray->pos.y = (((int)play->coord.y >> 6) << 6) + CHUNK_SIZE;
|
||||||
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 if(sin(ray->angle) > 0.001)
|
else if(sin(ray->angle) > 0.001)
|
||||||
{
|
{
|
||||||
ray->offset.y = -CHUNK_SIZE;
|
ray->offset.y = -CHUNK_SIZE;
|
||||||
ray->offset.x = CHUNK_SIZE * ray->tan;
|
ray->offset.x = CHUNK_SIZE * ray->tan;
|
||||||
ray->pos.y = (((int)play->coord.y >> 6) << 6) + 0.001;
|
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
|
else
|
||||||
{
|
{
|
||||||
dda->s = false;
|
|
||||||
ray->pos.x = play->coord.x;
|
ray->pos.x = play->coord.x;
|
||||||
ray->pos.y = play->coord.y;
|
ray->pos.y = play->coord.y;
|
||||||
|
dda->s = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +83,6 @@ void dda_loop(t_dda *dda, t_ray *ray, t_map *map, t_player *play)
|
|||||||
{
|
{
|
||||||
dda->map.x = (int)(ray->pos.x / 64);
|
dda->map.x = (int)(ray->pos.x / 64);
|
||||||
dda->map.y = (int)(ray->pos.y / 64);
|
dda->map.y = (int)(ray->pos.y / 64);
|
||||||
printf("%f, %f\n", ray->pos.x, ray->pos.y);
|
|
||||||
if (dda->map.x >= 0 && dda->map.x < w && dda->map.y >= 0 && dda->map.y < h && \
|
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')
|
map->arr[(int)dda->map.y][(int)dda->map.x] == '1')
|
||||||
{
|
{
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/11 16:37:56 by adjoly #+# #+# */
|
/* Created: 2024/09/11 16:37:56 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/10/29 14:57:10 by adjoly ### ########.fr */
|
/* Updated: 2024/11/01 16:05:37 by madumerg ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/28 15:48:39 by adjoly #+# #+# */
|
/* Created: 2024/10/28 15:48:39 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/10/29 14:22:37 by adjoly ### ########.fr */
|
/* Updated: 2024/11/01 16:30:17 by madumerg ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -64,9 +64,12 @@ void print_line(t_render *render, t_ray *ray, int x)
|
|||||||
y = 0;
|
y = 0;
|
||||||
while (y < line)
|
while (y < line)
|
||||||
{
|
{
|
||||||
j = -1;
|
j = 0;
|
||||||
while (++j <= RAY_SIZE)
|
while (j < RAY_SIZE)
|
||||||
|
{
|
||||||
mlx_set_image_pixel(render->mlx, render->img, x + j, line_start + y, WHITE);
|
mlx_set_image_pixel(render->mlx, render->img, x + j, line_start + y, WHITE);
|
||||||
|
j++;
|
||||||
|
}
|
||||||
y++;
|
y++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,8 +92,9 @@ void render_frame(t_render *render)
|
|||||||
ang = render->player->direction - ray.angle;
|
ang = render->player->direction - ray.angle;
|
||||||
fix_ang(&ang);
|
fix_ang(&ang);
|
||||||
ray.distance *= cos(ang);
|
ray.distance *= cos(ang);
|
||||||
|
printf("distance = %f\n", ray.distance);
|
||||||
print_line(render, &ray, i);
|
print_line(render, &ray, i);
|
||||||
ray.angle += (M_PI / 180) / (WINDOW_W / FOV);
|
ray.angle += (M_PI / 180) / ((WINDOW_W * RAY_SIZE) / FOV);
|
||||||
fix_ang(&ray.angle);
|
fix_ang(&ray.angle);
|
||||||
i -= RAY_SIZE;
|
i -= RAY_SIZE;
|
||||||
}
|
}
|
||||||
|
@ -6,14 +6,13 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/26 15:47:29 by adjoly #+# #+# */
|
/* Created: 2024/10/26 15:47:29 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/10/28 15:20:24 by adjoly ### ########.fr */
|
/* Updated: 2024/11/01 16:07:33 by madumerg ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "game/vectwo.h"
|
#include "game/vectwo.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
|
||||||
float vec2_dist(t_vec2 first, t_vec2 second)
|
float vec2_dist(t_vec2 first, t_vec2 second)
|
||||||
{
|
{
|
||||||
return (sqrt(powf(second.x - first.x, 2) + powf(second.y - first.y, 2)));
|
return (sqrt(powf(second.x - first.x, 2) + powf(second.y - first.y, 2)));
|
||||||
|
Reference in New Issue
Block a user