tmp push merge resolution not finished
This commit is contained in:
parent
2568aa69a6
commit
00dc0e9e67
16 changed files with 454 additions and 59 deletions
30
Makefile
30
Makefile
|
|
@ -6,7 +6,7 @@
|
|||
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
||||
# Updated: 2024/11/27 16:05:42 by rparodi ### ########.fr #
|
||||
# Updated: 2024/11/28 14:30:42 by bgoulard ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
|
@ -44,20 +44,24 @@ MLXFLAGS += -L/opt/X11/lib
|
|||
LDFLAGS += $(MLXFLAGS)
|
||||
|
||||
SRC =\
|
||||
mlx_layer/mlx_init.c \
|
||||
mlx_layer/mlx_load_texture.c \
|
||||
raycast/frame_update.c \
|
||||
raycast/rc_utils.c \
|
||||
sources/options_impl.c \
|
||||
sources/main.c \
|
||||
sources/error.c \
|
||||
sources/cleanups.c \
|
||||
sources/options.c \
|
||||
sources/rgb_to_color.c \
|
||||
parsing/arguments.c \
|
||||
parsing/map.c \
|
||||
parsing/blank_for_raph.c \
|
||||
parsing/arguments.c
|
||||
|
||||
sources/rgb_to_color.c \
|
||||
sources/error.c \
|
||||
sources/options.c \
|
||||
sources/options_impl.c \
|
||||
sources/cleanups.c \
|
||||
sources/main.c \
|
||||
mlx_layer/mlx_load_texture.c \
|
||||
mlx_layer/mlx_init.c \
|
||||
mlx_layer/mooves.c \
|
||||
mlx_layer/looks.c \
|
||||
mlx_layer/hooks.c \
|
||||
raycast/utils_math.c \
|
||||
raycast/rc_utils.c \
|
||||
raycast/get_cl.c \
|
||||
raycast/frame_update.c \
|
||||
|
||||
# Objects
|
||||
OBJDIRNAME = ./build
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/30 16:30:26 by rparodi #+# #+# */
|
||||
/* Updated: 2024/11/28 13:54:39 by bgoulard ### ########.fr */
|
||||
/* Updated: 2024/11/28 15:15:31 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -22,6 +22,23 @@
|
|||
|
||||
# include <stdbool.h>
|
||||
|
||||
// utils
|
||||
int render_frame(t_info *data);
|
||||
void my_mlx_pixel_put(t_info *data, int x, int y, int color);
|
||||
double deg2rad(int deg);
|
||||
void rotate_plane(t_dpoint *plane, double angle);
|
||||
|
||||
// key pressed func
|
||||
void look_left(t_info *data);
|
||||
void look_right(t_info *data);
|
||||
void move_straight(t_info *data);
|
||||
void move_backward(t_info *data);
|
||||
void move_left(t_info *data);
|
||||
void move_right(t_info *data);
|
||||
|
||||
int get_cl(int side, t_ipoint step);
|
||||
t_tile *c3_get_cell(t_tile *map, t_ipoint dimensions, t_ipoint pos);
|
||||
|
||||
/// @brief Createsa a blank map for rapahael to test the raycasting
|
||||
/// @note Dev only function.
|
||||
void blank(t_info *info);
|
||||
|
|
@ -38,6 +55,6 @@ void parse_map(t_info *info);
|
|||
void parse_args(char *arg, t_info *inf);
|
||||
|
||||
int main(int argc, char *argv[]);
|
||||
void shelves_launch(t_info *info);
|
||||
int shelves_launch(t_info *info);
|
||||
|
||||
#endif /* CUB3D_H */
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/28 13:53:54 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/11/28 13:54:53 by bgoulard ### ########.fr */
|
||||
/* Updated: 2024/11/28 15:36:36 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -20,9 +20,13 @@
|
|||
# define FILE_EXTENSION_LEN 4
|
||||
# define BG_CLG 0
|
||||
# define BG_FLR 1
|
||||
|
||||
#define FOV 65
|
||||
#define TILE_SIZE 64
|
||||
|
||||
// defines that should be mooved to a config option / file
|
||||
#define FOV 70
|
||||
#define ROT_SPEED 0.1
|
||||
#define MOVE_SPEED 0.5
|
||||
|
||||
// -- graphic utils
|
||||
|
||||
typedef struct s_color
|
||||
|
|
@ -96,7 +100,9 @@ typedef struct s_map
|
|||
typedef struct s_player
|
||||
{
|
||||
t_dpoint pos;
|
||||
double view;
|
||||
t_ipoint pos_i;
|
||||
t_dpoint dir;
|
||||
t_dpoint plane;
|
||||
} t_player;
|
||||
|
||||
// -- cli utils
|
||||
|
|
@ -129,6 +135,15 @@ typedef enum e_error
|
|||
ERROR_IMPLEM,
|
||||
} t_error;
|
||||
|
||||
typedef struct s_pixel_buffer
|
||||
{
|
||||
char *img_addr;
|
||||
t_img *screen_buff;
|
||||
int bpp;
|
||||
int line_len;
|
||||
int endian;
|
||||
} t_pixel_buffer;
|
||||
|
||||
// -- main struct
|
||||
|
||||
typedef struct s_info
|
||||
|
|
@ -138,9 +153,13 @@ typedef struct s_info
|
|||
|
||||
t_xvar *mlx_ptr;
|
||||
t_win_list *win_ptr;
|
||||
t_ipoint screen_size;
|
||||
t_pixel_buffer camera;
|
||||
|
||||
t_map map;
|
||||
t_player player;
|
||||
t_cli cli_ctx;
|
||||
|
||||
} t_info;
|
||||
|
||||
#endif /* CUB3D_STRUCT_H */
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
SO ./textures/png_ugly.png
|
||||
NO ./textures/png_ugly.png
|
||||
WE ./textures/png_pretty.png
|
||||
EA ./textures/png_pretty.png
|
||||
SO ./textures/a.xpm
|
||||
NO ./textures/a.xpm
|
||||
WE ./textures/a.xpm
|
||||
EA ./textures/a.xpm
|
||||
|
||||
F 255,255,255
|
||||
C 255,255,255
|
||||
|
|
@ -18,6 +18,11 @@ C 255,255,255
|
|||
|
||||
|
||||
|
||||
111
|
||||
1N1
|
||||
111
|
||||
11111111111111111111111
|
||||
100000000N0000000000001
|
||||
10000000000000000000001
|
||||
10000000000000000000001
|
||||
11111011101100111110011
|
||||
11000000000000000000001
|
||||
11110111111111111111111
|
||||
11111111
|
||||
|
|
|
|||
38
mlx_layer/hooks.c
Normal file
38
mlx_layer/hooks.c
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* hooks.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/28 14:12:25 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/11/28 14:57:01 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
#include "cub3d_struct.h"
|
||||
|
||||
#include "mlx_functions.h"
|
||||
|
||||
#include <X11/keysym.h>
|
||||
|
||||
int key_hook(int keycode, t_info *data)
|
||||
{
|
||||
if (keycode == XK_Escape)
|
||||
mlx_loop_end(data->mlx_ptr);
|
||||
if (keycode == XK_w)
|
||||
move_straight(data);
|
||||
if (keycode == XK_s)
|
||||
move_backward(data);
|
||||
if (keycode == XK_a)
|
||||
move_right(data);
|
||||
if (keycode == XK_d)
|
||||
move_left(data);
|
||||
if (keycode == XK_Left)
|
||||
look_left(data);
|
||||
if (keycode == XK_Right)
|
||||
look_right(data);
|
||||
return (0);
|
||||
}
|
||||
|
||||
26
mlx_layer/looks.c
Normal file
26
mlx_layer/looks.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* looks.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/28 14:11:28 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/11/28 14:51:53 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
#include "cub3d_struct.h"
|
||||
|
||||
void look_left(t_info *data)
|
||||
{
|
||||
rotate_plane(&data->player.dir, ROT_SPEED);
|
||||
rotate_plane(&data->player.plane, ROT_SPEED);
|
||||
}
|
||||
|
||||
void look_right(t_info *data)
|
||||
{
|
||||
rotate_plane(&data->player.dir, -ROT_SPEED);
|
||||
rotate_plane(&data->player.plane, -ROT_SPEED);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/11 19:53:42 by rparodi #+# #+# */
|
||||
/* Updated: 2024/11/28 13:55:09 by bgoulard ### ########.fr */
|
||||
/* Updated: 2024/11/28 14:06:03 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -55,6 +55,5 @@ int init_mlx_env(t_info *info)
|
|||
mlx_hook(info->win_ptr, KeyPress, KeyPressMask, c3_keyhook, info);
|
||||
mlx_hook(info->win_ptr, DestroyNotify, StructureNotifyMask, c3_redcross, info);
|
||||
mlx_loop_hook(info->mlx_ptr, (int (*)())shelves_launch, &info);
|
||||
mlx_loop_hook(info->mlx_ptr, c3_frame_update, info);
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
|
|
|||
80
mlx_layer/mooves.c
Normal file
80
mlx_layer/mooves.c
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mooves.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/28 14:10:44 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/11/28 14:50:48 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
#include "cub3d_struct.h"
|
||||
|
||||
void move_straight(t_info *data)
|
||||
{
|
||||
t_tile *tile_x;
|
||||
t_tile *tile_y;
|
||||
|
||||
tile_x = c3_get_cell(data->map.map, data->map.size,
|
||||
(t_ipoint){(int)(data->player.pos.x + data->player.dir.x * MOVE_SPEED), (int)data->player.pos.y});
|
||||
if (tile_x->tile_type == EMPTY)
|
||||
data->player.pos.x += data->player.dir.x * MOVE_SPEED;
|
||||
tile_y = c3_get_cell(data->map.map, data->map.size,
|
||||
(t_ipoint){(int)data->player.pos.x, (int)(data->player.pos.y + data->player.dir.y * MOVE_SPEED)});
|
||||
if (tile_y->tile_type == EMPTY)
|
||||
data->player.pos.y += data->player.dir.y * MOVE_SPEED;
|
||||
}
|
||||
|
||||
void move_backward(t_info *data)
|
||||
{
|
||||
t_tile *tile_x;
|
||||
t_tile *tile_y;
|
||||
|
||||
tile_x = c3_get_cell(data->map.map, data->map.size,
|
||||
(t_ipoint){(int)(data->player.pos.x - data->player.dir.x * MOVE_SPEED), (int)data->player.pos.y});
|
||||
if (tile_x->tile_type == EMPTY)
|
||||
data->player.pos.x -= data->player.dir.x * MOVE_SPEED;
|
||||
tile_y = c3_get_cell(data->map.map, data->map.size,
|
||||
(t_ipoint){(int)data->player.pos.x, (int)(data->player.pos.y - data->player.dir.y * MOVE_SPEED)});
|
||||
if (tile_y->tile_type == EMPTY)
|
||||
data->player.pos.y -= data->player.dir.y * MOVE_SPEED;
|
||||
}
|
||||
|
||||
void move_left(t_info *data)
|
||||
{
|
||||
t_dpoint pplayer;
|
||||
t_tile *tile_x;
|
||||
t_tile *tile_y;
|
||||
|
||||
pplayer.x = -data->player.dir.y;
|
||||
pplayer.y = data->player.dir.x;
|
||||
tile_x = c3_get_cell(data->map.map, data->map.size,
|
||||
(t_ipoint){(int)(data->player.pos.x + pplayer.x * MOVE_SPEED), (int)data->player.pos.y});
|
||||
if (tile_x->tile_type == EMPTY)
|
||||
data->player.pos.x += pplayer.x * MOVE_SPEED;
|
||||
tile_y = c3_get_cell(data->map.map, data->map.size,
|
||||
(t_ipoint){(int)data->player.pos.x, (int)(data->player.pos.y + pplayer.y * MOVE_SPEED)});
|
||||
if (tile_y->tile_type == EMPTY)
|
||||
data->player.pos.y += pplayer.y * MOVE_SPEED;
|
||||
}
|
||||
|
||||
void move_right(t_info *data)
|
||||
{
|
||||
t_dpoint pplayer;
|
||||
t_tile *tile_x;
|
||||
t_tile *tile_y;
|
||||
|
||||
pplayer.x = -data->player.dir.y;
|
||||
pplayer.y = data->player.dir.x;
|
||||
tile_x = c3_get_cell(data->map.map, data->map.size,
|
||||
(t_ipoint){(int)(data->player.pos.x - pplayer.x * MOVE_SPEED), (int)data->player.pos.y});
|
||||
if (tile_x->tile_type == EMPTY)
|
||||
data->player.pos.x -= pplayer.x * MOVE_SPEED;
|
||||
tile_y = c3_get_cell(data->map.map, data->map.size,
|
||||
(t_ipoint){(int)data->player.pos.x, (int)(data->player.pos.y - pplayer.y * MOVE_SPEED)});
|
||||
if (tile_y->tile_type == EMPTY)
|
||||
data->player.pos.y -= pplayer.y * MOVE_SPEED;
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/13 06:44:42 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/11/13 06:55:09 by bgoulard ### ########.fr */
|
||||
/* Updated: 2024/11/28 13:59:33 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,8 +18,8 @@
|
|||
static t_tile char_to_tile(char c)
|
||||
{
|
||||
if (c == '1' || c == ' ')
|
||||
return (WALL);
|
||||
return (EMPTY);
|
||||
return ((t_tile)WALL);
|
||||
return ((t_tile)EMPTY);
|
||||
}
|
||||
|
||||
/// @brief Createsa a blank map for rapahael to test the raycasting
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/12 08:31:06 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/11/27 11:53:06 by bgoulard ### ########.fr */
|
||||
/* Updated: 2024/11/28 15:41:02 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -84,7 +84,7 @@ info->last_error = ERROR_MALLOC, false);
|
|||
if (texture.img == NULL)
|
||||
return (info->errno_state = errno,
|
||||
info->last_error = ERROR_MLX, false);
|
||||
return (info->map.texture[i] = texture, true);
|
||||
return (info->map.texture_[i] = texture, true);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
|
@ -266,6 +266,7 @@ t_tile *c3_get_cell(t_tile *map, t_ipoint dimensions, t_ipoint pos)
|
|||
|
||||
bool flood_fill(t_tile *tiles, t_ipoint pos, t_ipoint maxs)
|
||||
{
|
||||
printf("dbg marker %s\n", __func__);
|
||||
t_tile *current;
|
||||
size_t i;
|
||||
const t_ipoint to_check[] = {
|
||||
|
|
@ -294,6 +295,7 @@ bool flood_fill(t_tile *tiles, t_ipoint pos, t_ipoint maxs)
|
|||
|
||||
void *traverse_map(void *data)
|
||||
{
|
||||
printf("dbg marker %s\n", __func__);
|
||||
t_info *info;
|
||||
t_ipoint pos_start;
|
||||
|
||||
|
|
@ -304,6 +306,7 @@ void *traverse_map(void *data)
|
|||
return (info);
|
||||
}
|
||||
|
||||
void dump_map(t_tile *map, t_ipoint size);
|
||||
void parse_map(t_info *info)
|
||||
{
|
||||
t_optional opt;
|
||||
|
|
@ -320,4 +323,5 @@ void parse_map(t_info *info)
|
|||
info->map.path = info->cli_ctx.file;
|
||||
if (ft_optional_chain(&opt, function_list) == false)
|
||||
return (c3_perror(info), (void)0);
|
||||
dump_map(info->map.map, info->map.size);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,17 +6,126 @@
|
|||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/12 06:02:54 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/11/18 12:12:29 by bgoulard ### ########.fr */
|
||||
/* Updated: 2024/11/28 15:18:47 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
#include "cub3d_struct.h"
|
||||
|
||||
#include "mlx_functions.h"
|
||||
#include "ft_string.h"
|
||||
#include "ft_math.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void draw_(int side, double perpWallDist, t_ipoint step, int x, t_info *data)
|
||||
{
|
||||
const int lineHeight = (int)(data->screen_size.y / perpWallDist) * cos(deg2rad(FOV/ 2));
|
||||
int drawStart;
|
||||
int drawEnd;
|
||||
int color;
|
||||
|
||||
drawStart = -lineHeight / 2 + data->screen_size.y / 2;
|
||||
drawEnd = lineHeight / 2 + data->screen_size.y / 2;
|
||||
// normalize drawStart and drawEnd
|
||||
drawStart = ft_clamp(drawStart, 0, data->screen_size.y - 1);
|
||||
drawEnd = ft_clamp(drawEnd, 0, data->screen_size.y - 1);
|
||||
color = get_cl(side, step);
|
||||
while (drawStart < drawEnd)
|
||||
my_mlx_pixel_put(data, x, drawStart++, color);
|
||||
}
|
||||
|
||||
void search_hit(t_dpoint *sideDist, t_dpoint deltaDist, t_ipoint *map, t_ipoint step, void *_data[2])
|
||||
{
|
||||
int *side = (int *)_data[1];
|
||||
t_info *data = (t_info *)_data[0];
|
||||
|
||||
while (true) {
|
||||
if (sideDist->x < sideDist->y) {
|
||||
sideDist->x += deltaDist.x;
|
||||
map->x += step.x;
|
||||
*side = 0;
|
||||
} else {
|
||||
sideDist->y += deltaDist.y;
|
||||
map->y += step.y;
|
||||
*side = 1;
|
||||
}
|
||||
printf("map.x: %d, map.y: %d\n", map->x, map->y);
|
||||
if ((*c3_get_cell(data->map.map, data->map.size, *map))
|
||||
.tile_type != EMPTY)
|
||||
return ;
|
||||
}
|
||||
}
|
||||
|
||||
void static set_step(t_ipoint *step, t_dpoint raydir)
|
||||
{
|
||||
if (raydir.x < 0)
|
||||
step->x = -1;
|
||||
else
|
||||
step->x = 1;
|
||||
if (raydir.y < 0)
|
||||
step->y = -1;
|
||||
else
|
||||
step->y = 1;
|
||||
}
|
||||
|
||||
void static set_side_dist(t_dpoint *sideDist, t_dpoint *tb, t_ipoint map)
|
||||
{
|
||||
t_dpoint rayDir = tb[0];
|
||||
t_dpoint pos = tb[1];
|
||||
t_dpoint deltaDist = tb[2];
|
||||
|
||||
if (rayDir.x < 0)
|
||||
sideDist->x = (pos.x - map.x) * deltaDist.x;
|
||||
else
|
||||
sideDist->x = (map.x + 1.0 - pos.x) * deltaDist.x;
|
||||
if (rayDir.y < 0)
|
||||
sideDist->y = (pos.y - map.y) * deltaDist.y;
|
||||
else
|
||||
sideDist->y = (map.y + 1.0 - pos.y) * deltaDist.y;
|
||||
}
|
||||
|
||||
void column_handler(t_ipoint map, t_dpoint rayDir, t_info *data, int x)
|
||||
{
|
||||
t_dpoint sideDist;
|
||||
t_dpoint deltaDist;
|
||||
double perpWallDist;
|
||||
t_ipoint step;
|
||||
int side;
|
||||
|
||||
deltaDist = (t_dpoint){fabs(1 / rayDir.x), fabs(1 / rayDir.y)};
|
||||
set_step(&step, rayDir);
|
||||
set_side_dist(&sideDist, (t_dpoint[]){rayDir, data->player.pos, deltaDist}, map);
|
||||
search_hit(&sideDist, deltaDist, &map, step, (void *[]){data, &side});
|
||||
if (side == 0)
|
||||
perpWallDist = (map.x - data->player.pos.x + (double)(1 - step.x) / 2)
|
||||
/ rayDir.x;
|
||||
else
|
||||
perpWallDist = (map.y - data->player.pos.y + (double)(1 - step.y) / 2)
|
||||
/ rayDir.y;
|
||||
draw_(side, perpWallDist, step, x, data);
|
||||
}
|
||||
|
||||
int render_frame(t_info *data)
|
||||
{
|
||||
double camera_x;
|
||||
double coef;
|
||||
|
||||
coef = 2 * tan(deg2rad(FOV) / 2) / (double)data->screen_size.x;
|
||||
ft_bzero(data->camera.img_addr, data->screen_size.x * data->screen_size.y * data->camera.bpp / 8);
|
||||
for(int x = 0; x < data->screen_size.x; x++)
|
||||
{
|
||||
camera_x = x * coef - 1;
|
||||
column_handler((t_ipoint){(int)data->player.pos.x, (int)data->player.pos.y},
|
||||
(t_dpoint){data->player.dir.x + data->player.plane.x * camera_x, data->player.dir.y + data->player.plane.y * camera_x},
|
||||
data, x);
|
||||
}
|
||||
mlx_put_image_to_window(data->mlx_ptr, data->win_ptr, data->camera.screen_buff, 0, 0);
|
||||
return (0);
|
||||
}
|
||||
// Return 42 is irrelevant check mlx_loop to see that mlx doesn't care for the
|
||||
// return of the function...
|
||||
// (Why 'int (*)(void*)' when you dont use the int)
|
||||
|
|
|
|||
29
raycast/get_cl.c
Normal file
29
raycast/get_cl.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* get_cl.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/28 14:15:04 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/11/28 14:57:25 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d_struct.h"
|
||||
|
||||
int get_cl(int side, t_ipoint step)
|
||||
{
|
||||
int color;
|
||||
|
||||
if (side == 0 && step.x > 0)
|
||||
color = 0x00FF0000;
|
||||
else if (side == 0 && step.x < 0)
|
||||
color = 0x0000FF00;
|
||||
else if (side == 1 && step.y > 0)
|
||||
color = 0x000000FF;
|
||||
else
|
||||
color = 0x00FFFF00;
|
||||
return (color);
|
||||
}
|
||||
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/12 12:24:35 by rparodi #+# #+# */
|
||||
/* Updated: 2024/11/26 13:39:56 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/11/28 15:15:15 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,17 +14,7 @@
|
|||
#include "cub3d_struct.h"
|
||||
#include "mlx_functions.h"
|
||||
#include "raycast.h"
|
||||
|
||||
/**
|
||||
* @brief convert a angle in degrees to radian
|
||||
*
|
||||
* @param degrees the angle in degrees
|
||||
* @return the angle in radian
|
||||
*/
|
||||
double cub_convert_deg_to_rad(double degrees)
|
||||
{
|
||||
return (degrees * (M_PI / 180.0));
|
||||
}
|
||||
#include <stdlib.h>
|
||||
|
||||
/**
|
||||
* @brief Launches a ray for raycasting to determine the distance to the first wall.
|
||||
|
|
@ -78,7 +68,7 @@ void draw_line(t_info *info, int x, int start, int end, unsigned int color)
|
|||
}
|
||||
}
|
||||
|
||||
void shelves_launch(t_info *info)
|
||||
/*
|
||||
{
|
||||
info->player.pos = (t_dpoint){ 4.5, 4.5 }; // Starting in the middle of the map
|
||||
info->player.view = 0; int x;
|
||||
|
|
@ -99,4 +89,10 @@ void shelves_launch(t_info *info)
|
|||
|
||||
draw_line(info, x, start, end, 0xFFFFFF);
|
||||
}
|
||||
}*/
|
||||
|
||||
int shelves_launch(t_info *info)
|
||||
{
|
||||
render_frame(info);
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
|
|
|
|||
39
raycast/utils_math.c
Normal file
39
raycast/utils_math.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* utils_math.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/28 14:09:12 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/11/28 14:54:32 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d_struct.h"
|
||||
#include <math.h>
|
||||
|
||||
void my_mlx_pixel_put(t_info *data, int x, int y, int color)
|
||||
{
|
||||
uint *dst;
|
||||
|
||||
x *= data->camera.bpp / 8;
|
||||
dst = (uint *)(data->camera.img_addr + (y * data->camera.line_len + x));
|
||||
*dst = color;
|
||||
}
|
||||
|
||||
double deg2rad(int deg)
|
||||
{
|
||||
return (deg * M_PI / 180);
|
||||
}
|
||||
|
||||
void rotate_plane(t_dpoint *plane, double angle)
|
||||
{
|
||||
double old_plane_x;
|
||||
double old_plane_y;
|
||||
|
||||
old_plane_x = (*plane).x;
|
||||
old_plane_y = (*plane).y;
|
||||
plane->x = plane->x * cos(angle) - plane->y * sin(angle);
|
||||
plane->y = old_plane_x * sin(angle) + plane->y * cos(angle);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/09 01:11:01 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/11/18 17:14:06 by bgoulard ### ########.fr */
|
||||
/* Updated: 2024/11/28 13:58:48 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -38,11 +38,14 @@ static void cleanup_mlx(t_info *info)
|
|||
mlx_destroy_window(info->mlx_ptr, info->win_ptr);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (info->map.texture[i].img)
|
||||
mlx_destroy_image(info->mlx_ptr, info->map.texture[i].img);
|
||||
if (info->map.texture[i].path)
|
||||
ft_free((void **)&info->map.texture[i].path);
|
||||
if (info->map.texture_[i].img)
|
||||
mlx_destroy_image(info->mlx_ptr, info->map.texture_[i].img);
|
||||
if (info->map.texture_[i].path)
|
||||
ft_free((void **)&info->map.texture_[i].path);
|
||||
if (info->map.texture[i])
|
||||
mlx_destroy_image(info->mlx_ptr, info->map.texture[i]);
|
||||
}
|
||||
|
||||
mlx_destroy_display(info->mlx_ptr);
|
||||
ft_free((void **)&info->mlx_ptr);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/30 16:30:03 by rparodi #+# #+# */
|
||||
/* Updated: 2024/11/28 13:55:42 by bgoulard ### ########.fr */
|
||||
/* Updated: 2024/11/28 15:38:55 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -22,11 +22,30 @@
|
|||
|
||||
void blank(t_info *info);
|
||||
|
||||
void dump_map(t_tile *map, t_ipoint size)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
while (i < size.y)
|
||||
{
|
||||
j = 0;
|
||||
while (j < size.x)
|
||||
{
|
||||
printf("%d", map[i * size.x + j].tile_type);
|
||||
j++;
|
||||
}
|
||||
printf("\n");
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
// not normed but we'll take care of this as a niceties at the last
|
||||
// possible moment :)
|
||||
void dump_info(t_info *info)
|
||||
{
|
||||
const char *bool_str[2] = {"True", "False"};
|
||||
const char *bool_str[2] = {"False", "True"};
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
|
|
@ -47,6 +66,15 @@ void dump_info(t_info *info)
|
|||
printf("\t\tmap.fraw[%zu]: %s\n", i, info->map.fraw[i]);
|
||||
i++;
|
||||
}
|
||||
printf("\t\ttexture[0]: %p\n", info->map.texture[0]);
|
||||
printf("\t\ttexture[1]: %p\n", info->map.texture[1]);
|
||||
printf("\t\ttexture[2]: %p\n", info->map.texture[2]);
|
||||
printf("\t\ttexture[3]: %p\n", info->map.texture[3]);
|
||||
printf("\t\tmap: %p\n", info->map.map);
|
||||
dump_map(info->map.map, info->map.size);
|
||||
|
||||
printf("\tlast_error: %d\n", info->last_error);
|
||||
printf("\terno_state: %d\n", info->errno_state);
|
||||
}
|
||||
|
||||
void check_err(t_info *info)
|
||||
|
|
@ -65,7 +93,6 @@ void check_err(t_info *info)
|
|||
|
||||
void run_cub3d(t_info *info)
|
||||
{
|
||||
blank(info);
|
||||
if (init_mlx_env(info) != NO_ERROR)
|
||||
return ;
|
||||
parse_map(info);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue