plr start on middle of a cell, and wall height is well proportionned
This commit is contained in:
@@ -50,25 +50,20 @@ static void wall_length(t_rcast *rcast)
|
||||
len /= rcast->slope_x;
|
||||
len = rcast->screen_dist * len / rcast->slope_y;
|
||||
}
|
||||
printf("len:%i\n", len);
|
||||
rcast->ray_len = ft_abs(len);
|
||||
}
|
||||
|
||||
static void wall_height(t_rcast *rcast)
|
||||
{
|
||||
double height;
|
||||
int height;
|
||||
|
||||
// height = rcast->screen_height * (rcast->hor - rcast->ray_len) / rcast->hor;
|
||||
|
||||
height = rcast->screen_height;
|
||||
height = rcast->screen_height * rcast->cell;
|
||||
if (rcast->ray_len)
|
||||
height /= (double)((double)rcast->ray_len / 100);
|
||||
|
||||
height /= rcast->ray_len;
|
||||
if (height < 0)
|
||||
height = 0;
|
||||
if (height >= rcast->screen_height)
|
||||
if (height > rcast->screen_height)
|
||||
height = rcast->screen_height;
|
||||
|
||||
rcast->wall.start.y = rcast->screen_height / 2 + height / 2;
|
||||
rcast->wall.end.y = rcast->screen_height / 2 - height / 2;
|
||||
}
|
||||
|
||||
@@ -9,57 +9,6 @@ static void init_img(t_img *img, void *mlx_ptr, t_win *win)
|
||||
|
||||
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},
|
||||
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
|
||||
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
|
||||
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
|
||||
{1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,1,0,1,0,1,0,0,0,1},
|
||||
{1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0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mb_alloc(sizeof(char*) * (map->size_y + 1));
|
||||
(map->content)[map->size_y] = NULL;
|
||||
while (i < 24)
|
||||
{
|
||||
(map->content)[i] = mb_alloc(sizeof(char) * (map->size_x + 1));
|
||||
(map->content)[i][map->size_x] = '\0';
|
||||
i++;
|
||||
}
|
||||
int j;
|
||||
i = 0;
|
||||
while (i < map->size_y)
|
||||
{
|
||||
j = 0;
|
||||
while (j < map->size_x)
|
||||
{
|
||||
(map->content)[i][j] = tmp[i][j] + '0';
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
} */
|
||||
map->content = NULL;
|
||||
map->tmp_str = NULL;
|
||||
map->cell = CELL;
|
||||
@@ -86,7 +35,6 @@ static void init_raycast(t_rcast *rcast)
|
||||
rcast->screen_dist = dist;
|
||||
rcast->screen_width = SCREEN_WIDTH;
|
||||
rcast->screen_height = SCREEN_HEIGHT;
|
||||
rcast->hor = HORIZON;
|
||||
// screen size
|
||||
rcast->screen_size.start.x = -SCREEN_WIDTH / 2;
|
||||
rcast->screen_size.start.y = -dist;
|
||||
@@ -102,11 +50,12 @@ static void init_raycast(t_rcast *rcast)
|
||||
void init_plr(t_plr *plr, t_map *map)
|
||||
{
|
||||
// player first position
|
||||
plr->exact.x = map->plr_x * CELL;
|
||||
plr->exact.y = map->plr_y * CELL;
|
||||
plr->exact.x = map->plr_x * CELL + CELL / 2;
|
||||
plr->exact.y = map->plr_y * CELL + CELL / 2;
|
||||
plr->pos.x = plr->exact.x;
|
||||
plr->pos.y = plr->exact.y;
|
||||
// rotation
|
||||
plr->deg = PLR_ROT;
|
||||
plr->rot = 0;
|
||||
plr->cosi = 0;
|
||||
plr->cosj = 0;
|
||||
@@ -123,31 +72,6 @@ t_game *init_struct(void)
|
||||
init_map(&(game->map));
|
||||
// init textures and floor/ceiling colors
|
||||
init_txt(&(game->txt));
|
||||
/* // plr
|
||||
init_plr(&(game->plr));
|
||||
// init connexion to server
|
||||
game->mlx_ptr = mlx_init();
|
||||
mb_add(game->mlx_ptr);
|
||||
|
||||
// tmp draw map
|
||||
game->map_win.size_x = game->map.size_x * CELL;
|
||||
game->map_win.size_y = game->map.size_y * CELL + SCREEN_HEIGHT;
|
||||
game->map_win.ptr = mlx_new_window(game->mlx_ptr, game->map_win.size_x, game->map_win.size_y, "map");
|
||||
init_img(&(game->map_img), game->mlx_ptr, &(game->map_win));
|
||||
// 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->mlx_ptr, &(game->win));
|
||||
// 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));
|
||||
game->rcast.cell = game->map.cell;
|
||||
// create image and get its data address
|
||||
init_img(&(game->map_img), game); */
|
||||
return (game);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: pblagoje <pblagoje@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/04/18 12:37:48 by pblagoje #+# #+# */
|
||||
/* Updated: 2022/04/23 19:18:16 by pblagoje ### ########.fr */
|
||||
/* Updated: 2022/04/30 11:56:09 by simplonco ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ void plr_turn_left(t_plr *plr)
|
||||
|
||||
if (plr->rot == -180)
|
||||
(plr->rot) *= -1;
|
||||
(plr->rot)--;
|
||||
plr->rot -= plr->deg;
|
||||
// calculate trigo for rotations
|
||||
radi = plr->rot * M_PI / 180;
|
||||
radj = radi + (M_PI / 2);
|
||||
@@ -64,7 +64,7 @@ void plr_turn_right(t_plr *plr)
|
||||
|
||||
if (plr->rot == 180)
|
||||
(plr->rot) *= -1;
|
||||
(plr->rot)++;
|
||||
plr->rot += plr->deg;
|
||||
// calculate trigo for rotations
|
||||
radi = plr->rot * M_PI / 180;
|
||||
radj = radi + (M_PI / 2);
|
||||
|
||||
Reference in New Issue
Block a user