Avancement problème déplacement, manque texture

This commit is contained in:
Etienne Rey-bethbeder 2023-05-04 14:42:39 +02:00
parent ebe8b84f78
commit d58732b159
97 changed files with 65 additions and 47 deletions

View File

@ -9,7 +9,7 @@ SRCS := ${SRCS_MAP} \
OBJS := ${SRCS:.c=.o}
CC := clang
LIBS := libftx/libftx.a MLX42/build/libmlx42.a -ldl -lglfw -lm
CFLAGS := -g -Wall -Wextra -Werror
CFLAGS := -g -Wall -Wextra -Werror -Wno-conversion -Ofast
NAME := cub3D
all: ${NAME}

BIN
cub3D Executable file

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/02 15:49:00 by erey-bet #+# #+# */
/* Updated: 2023/05/03 17:37:31 by erey-bet ### ########.fr */
/* Updated: 2023/05/04 14:37:21 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -55,7 +55,7 @@ void init_dda(t_game *game, t_dda *dda)
dda->hit = 0;
}
void loop_dda(t_game *game, t_dda *dda)
void loop_dda(t_game *game, t_dda *dda)
{
while (dda->hit == 0)
{
@ -71,18 +71,23 @@ void loop_dda(t_game *game, t_dda *dda)
dda->map_y += dda->step_y;
dda->side = 1;
}
if (dda->map_x >= 0 && dda->map_y >= 0 &&
game->map.map[dda->map_y][dda->map_x] == '1')
if (dda->map_x < 0 || dda->map_y < 0
|| dda->map_x >= (int)game->map.size_x || dda->map_y >= (int)game->map.size_y)
{
dda->perp_wall_dist = 1e30;
return ;
}
if (game->map.map[dda->map_y][dda->map_x] == '1')
dda->hit = 1;
}
}
void ray_dda(t_dda *dda)
{
if(dda->side == 0)
dda->perp_wall_dist = dda->side_dist_x - dda->delta_dist_x;
else
dda->perp_wall_dist = dda->side_dist_y - dda->delta_dist_y;
}
void ray_dda(t_dda *dda)
{
if (dda->perp_wall_dist == 0)
dda->perp_wall_dist = 1e30;
dda->line_height = (int)(HEIGHT / dda->perp_wall_dist);
@ -96,7 +101,7 @@ void ray_dda(t_dda *dda)
unsigned int get_rgba(int r, int g, int b, int a)
{
return (a << 24 | r << 16 | g << 8 | b);
return (r << 24 | g << 16 | b << 8 | a);
}
void draw_line(t_game *game, t_dda *dda, unsigned int color, int x)
@ -120,7 +125,7 @@ void draw_line(t_game *game, t_dda *dda, unsigned int color, int x)
{
mlx_put_pixel(game->window, x, y, white);
}
y ++;
y++;
}
}
@ -129,14 +134,16 @@ void draw_dda(t_game *game, t_dda *dda, int x)
{
unsigned int color;
if (dda->step_x == -1 && dda->side == 0) // EAST
color = get_rgba(255, 0, 0, 255);
else if (dda->step_x == 1 && dda->side == 0) // WEST
color = get_rgba(0, 255, 0, 255);
else if (dda->step_y == 1 && dda->side == 1) // NORTH
color = get_rgba(0, 0, 255, 255);
else // SOUTH
color = get_rgba(100, 100, 100, 255);
if (dda->step_x < 0 && dda->side == 0) // NORTH
color = get_rgba(0, 0, 200, 255);
else if (dda->step_x > 0 && dda->side == 0) // SOUTH
color = get_rgba(200, 0, 0, 255);
else if (dda->step_y < 0 && dda->side == 1) // EAST
color = get_rgba(0, 200, 0, 255);
else if (dda->step_y > 0 && dda->side == 1) // WEST
color = get_rgba(50, 100, 50, 255);
else
color = get_rgba(0, 0, 0, 255);
draw_line(game, dda, color, x);
}

BIN
game/dda.o Normal file

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/26 15:29:34 by erey-bet #+# #+# */
/* Updated: 2023/05/03 16:51:50 by erey-bet ### ########.fr */
/* Updated: 2023/05/04 13:27:54 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -45,8 +45,8 @@
# define WIDTH 1920
# define HEIGHT 1080
# define MOVESPEED 0.1
# define ROTATIONSPEED 10
# define MOVESPEED 0.10
# define ROTATIONSPEED 60
typedef struct s_player
{

BIN
game/game.o Normal file

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/27 14:50:22 by erey-bet #+# #+# */
/* Updated: 2023/05/03 17:47:38 by erey-bet ### ########.fr */
/* Updated: 2023/05/04 14:34:47 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,8 +18,8 @@ void init_ply(t_map map, t_ply *ply)
ply->pos_y = map.ply_y;
ply->dir_x = -1;
ply->dir_y = 0;
ply->pla_x = 0;
ply->pla_y = 0.90;
ply->pla_x = 0.66;
ply->pla_y = 0.66;
}
void init_ray(t_ray *ray)

BIN
game/init.o Normal file

Binary file not shown.

BIN
game/manage.o Normal file

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/27 14:14:51 by erey-bet #+# #+# */
/* Updated: 2023/05/03 16:16:34 by erey-bet ### ########.fr */
/* Updated: 2023/05/04 14:16:06 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,28 +15,31 @@
void rotate(t_ply *ply, bool right)
{
double old_dir_x;
double old_dir_y;
double old_plane_x;
double old_plane_y;
double speed;
old_dir_x = ply->dir_x;
old_dir_y = ply->dir_y;
old_plane_x = ply->pla_x;
old_plane_y = ply->pla_y;
speed = ROTATIONSPEED * (M_1_PI / 180.0);
if (right)
speed = -speed;
ply->dir_x = ply->dir_x * cos(speed) - ply->dir_y * sin(speed);
ply->dir_y = old_dir_x * sin(speed) + ply->dir_y * cos(speed);
ply->pla_x = ply->pla_x * cos(speed) - ply->pla_y * sin(speed);
ply->pla_y = old_plane_x * sin(speed) + ply->pla_y * cos(speed);
ply->dir_x = old_dir_x * cos(speed) - old_dir_y * sin(speed);
ply->dir_y = old_dir_x * sin(speed) + old_dir_y * cos(speed);
ply->pla_x = old_plane_x * cos(speed) - old_plane_y * sin(speed);
ply->pla_y = old_plane_x * sin(speed) + old_plane_y * cos(speed);
}
void movement(t_game *game, t_ply *ply, double x, double y)
{
if(game->map.map[(int)(ply->pos_x + ply->dir_x * MOVESPEED)][(int)ply->pos_y] == '0')
(void)game;
//if(game->map.map[(int)(ply->pos_x + x)][(int)ply->pos_y] == '0')
ply->pos_x += x;
if(game->map.map[(int)ply->pos_x][(int)(ply->pos_y + ply->dir_y * MOVESPEED)] == '0')
//if(game->map.map[(int)ply->pos_x][(int)(ply->pos_y + y)] == '0')
ply->pos_y += y;
printf("ply->pos_x: %f, ply->pos_y: %f\n", ply->pos_x, ply->pos_y);
printf("x: %f, y: %f\n", x, y);
}
@ -45,13 +48,18 @@ int manage_movement(t_game *game, int key)
t_ply *ply;
ply = &game->ply;
printf("dir_x: %f, dir_y: %f\n", ply->dir_x, ply->dir_y);
if (key == MLX_KEY_W)
movement(game, ply, ply->dir_x * MOVESPEED, ply->dir_y * MOVESPEED);
movement(game, ply, (ply->dir_x * MOVESPEED), (ply->dir_y * MOVESPEED));
else if (key == MLX_KEY_S)
movement(game, ply, -(ply->dir_x * MOVESPEED), -(ply->dir_y * MOVESPEED));
else if (key == MLX_KEY_D)
rotate(ply, true);
movement(game, ply, -(ply->dir_x * MOVESPEED), (ply->dir_y * MOVESPEED));
else if (key == MLX_KEY_A)
movement(game, ply, (ply->dir_x * MOVESPEED), -(ply->dir_y * MOVESPEED));
else if (key == MLX_KEY_L)
rotate(ply, true);
else if (key == MLX_KEY_J)
rotate(ply, false);
return (1);
}
@ -61,12 +69,15 @@ int manage_keys(mlx_key_data_t keys, t_game *game)
int is_moving;
is_moving = 0;
if (keys.key == MLX_KEY_ESCAPE)
if (keys.key == MLX_KEY_Q)
mlx_close_window(game->mlx);
else if (keys.key == MLX_KEY_W
|| keys.key == MLX_KEY_S
|| keys.key == MLX_KEY_D
|| keys.key == MLX_KEY_A)
|| keys.key == MLX_KEY_A
|| keys.key == MLX_KEY_ESCAPE
|| keys.key == MLX_KEY_L
|| keys.key == MLX_KEY_J )
is_moving = manage_movement(game, keys.key);
if (is_moving)
return (1);

BIN
game/manage_keys.o Normal file

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/27 14:30:29 by erey-bet #+# #+# */
/* Updated: 2023/05/03 17:44:24 by erey-bet ### ########.fr */
/* Updated: 2023/05/04 14:41:50 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -23,11 +23,11 @@ int ray(t_game *game)
p = &game->ply;
ray = &game->ray;
while (x <= WIDTH)
while (x < WIDTH)
{
camera = 2 * x / ((double)(WIDTH - 1));
ray->dir_x = p->dir_x + p->pla_x * camera;
ray->dir_y = p->dir_y + p->pla_y * camera;
ray->dir_x = (p->dir_x + 0.45) + p->pla_x * camera;
ray->dir_y = (p->dir_y - 0.45) + p->pla_y * camera;
dda(game, x);
x++;
}
@ -37,6 +37,5 @@ int ray(t_game *game)
int raycasting(t_game *game)
{
ray(game);
write(1, "raycasting...\n", 14);
return (0);
}

BIN
game/raycasting.o Normal file

Binary file not shown.

BIN
libftx/extra/extra.a Normal file

Binary file not shown.

Binary file not shown.

BIN
libftx/extra/ft_freer.o Normal file

Binary file not shown.

BIN
libftx/extra/ft_is_in.o Normal file

Binary file not shown.

Binary file not shown.

BIN
libftx/extra/ft_strchri.o Normal file

Binary file not shown.

BIN
libftx/extra/ft_strcmp.o Normal file

Binary file not shown.

BIN
libftx/extra/ft_strfjoin.o Normal file

Binary file not shown.

BIN
libftx/extra/ft_strgen.o Normal file

Binary file not shown.

BIN
libftx/extra/ft_strmerger.o Normal file

Binary file not shown.

BIN
libftx/extra/ft_strndup.o Normal file

Binary file not shown.

BIN
libftx/extra/ft_swap.o Normal file

Binary file not shown.

BIN
libftx/extra/ft_tablen.o Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
libftx/gnl/get_next_line.a Normal file

Binary file not shown.

BIN
libftx/gnl/get_next_line.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_atoi.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_bzero.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_calloc.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_isalnum.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_isalpha.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_isascii.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_isdigit.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_isprint.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_itoa.o Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
libftx/libft/ft_lstclear.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_lstdelone.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_lstiter.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_lstlast.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_lstmap.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_lstnew.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_lstsize.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_memchr.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_memcmp.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_memcpy.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_memmove.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_memset.o Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
libftx/libft/ft_putnbr_fd.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_putstr_fd.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_split.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_strchr.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_strdup.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_striteri.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_strjoin.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_strlcat.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_strlcpy.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_strlen.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_strmapi.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_strncmp.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_strnstr.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_strrchr.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_strtrim.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_substr.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_tolower.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_toupper.o Normal file

Binary file not shown.

BIN
libftx/libft/libft.a Normal file

Binary file not shown.

BIN
libftx/libftx.a Normal file

Binary file not shown.

BIN
libftx/printf/ft_dprintX.o Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
libftx/printf/ft_dprintul.o Normal file

Binary file not shown.

Binary file not shown.

BIN
libftx/printf/ft_dprintx.o Normal file

Binary file not shown.

BIN
libftx/printf/ft_eprintf.o Normal file

Binary file not shown.

BIN
libftx/printf/ft_isarg.o Normal file

Binary file not shown.

BIN
libftx/printf/ft_isdigit.o Normal file

Binary file not shown.

BIN
libftx/printf/ft_printf.a Normal file

Binary file not shown.

BIN
libftx/printf/ft_printf.o Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
libftx/printf/ft_skipflag.o Normal file

Binary file not shown.

BIN
libftx/printf/ft_strlen.o Normal file

Binary file not shown.

BIN
libftx/printf/ft_vdprintf.o Normal file

Binary file not shown.

8
main.c
View File

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/26 12:44:55 by erey-bet #+# #+# */
/* Updated: 2023/05/03 17:33:16 by erey-bet ### ########.fr */
/* Updated: 2023/05/04 13:39:00 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -32,11 +32,11 @@ int main(int argc, char **argv)
map.map[1] = "100101";
map.map[2] = "101001";
map.map[3] = "100001";
map.map[4] = "10N001";
map.map[4] = "100001";
map.map[5] = "101001";
map.map[6] = "111111";
map.size_x = 5;
map.size_y = 5;
map.size_x = 6;
map.size_y = 7;
map.ply_x = 2;
map.ply_y = 4;
if (start_game(map))

BIN
main.o Normal file

Binary file not shown.

1
pos Normal file
View File

@ -0,0 +1 @@
Binary file (standard input) matches