params adjust angle of view and size of game window

This commit is contained in:
hugogogo
2022-04-24 11:14:08 +02:00
parent fac1f78230
commit c886118bd6
9 changed files with 135 additions and 103 deletions

View File

@@ -12,6 +12,7 @@ static void init_map(t_map *map)
{
map->size_x = 24;
map->size_y = 24;
map->cell = CELL;
// map
int tmp[24][24] = {
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
@@ -64,21 +65,26 @@ static void init_map(t_map *map)
static void init_raycast(t_rcast *rcast)
{
// draw screen dist
double dist;
dist = (SCREEN_FOCAL / 2) * M_PI / 180;
dist = cos(dist) * ((SCREEN_WIDTH / 2) / sin(dist));
rcast->screen_def = SCREEN_WIDTH;
// screen dist
rcast->screen_dist.start.x = 0;
rcast->screen_dist.start.y = 0;
rcast->screen_dist.end.x = 0;
rcast->screen_dist.end.y = -SCREEN_DIST;
// draw screen size
rcast->screen_size.start.x = -SCREEN_SIZE / 2;
rcast->screen_size.start.y = -SCREEN_DIST;
rcast->screen_size.end.x = SCREEN_SIZE / 2;
rcast->screen_size.end.y = -SCREEN_DIST;
// draw ray
rcast->screen_dist.end.y = -dist;
// screen size
rcast->screen_size.start.x = -SCREEN_WIDTH / 2;
rcast->screen_size.start.y = -dist;
rcast->screen_size.end.x = SCREEN_WIDTH / 2;
rcast->screen_size.end.y = -dist;
// first ray
rcast->ray.start.x = 0;
rcast->ray.start.y = 0;
rcast->ray.end.x = -SCREEN_SIZE / 2;
rcast->ray.end.y = -SCREEN_DIST;
rcast->ray.end.x = -SCREEN_WIDTH / 2;
rcast->ray.end.y = -dist;
}
static void init_plr(t_plr *plr)
@@ -105,20 +111,30 @@ t_game *init_game(void)
init_map(&(game->map));
// plr
init_plr(&(game->plr));
// size window map
game->map_win.size_x = game->map.size_x * CELL;
game->map_win.size_y = game->map.size_y * CELL;
// init connexion to server
game->mlx_ptr = mlx_init();
mb_add(game->mlx_ptr);
// create the window
game->map_win.ptr = mlx_new_window(game->mlx_ptr, game->map_win.size_x,
game->map_win.size_y, "test");
// tmp draw map
// size window map
game->map_win.size_x = game->map.size_x * CELL;
game->map_win.size_y = game->map.size_y * CELL + SCREEN_HEIGHT;
// create the window
game->map_win.ptr = mlx_new_window(game->mlx_ptr, game->map_win.size_x,
game->map_win.size_y, "map");
// create image and get its data address
init_img(&(game->map_img), game);
// tmp end
game->win.size_x = SCREEN_WIDTH;
game->win.size_y = SCREEN_HEIGHT;
game->win.ptr = mlx_new_window(game->mlx_ptr, game->win.size_x,
game->win.size_y, "cub3d");
init_img(&(game->img), game);
// k(ey)_hook is the array containing the values of key press events
ft_bzero(&game->k_hook, sizeof(game->k_hook));
// raycasting
init_raycast(&(game->rcast));
// create image and get its data address
init_img(&(game->map_img), game);
game->rcast.cell = game->map.cell;
return (game);
}