plr start on middle of a cell, and wall height is well proportionned

This commit is contained in:
hugogogo
2022-04-30 12:09:44 +02:00
parent 58b862ce82
commit 888fa7c116
7 changed files with 26 additions and 111 deletions

View File

@@ -6,23 +6,21 @@
*/
/* nbr pixel player move */
# define PLR_MV 1
# define PLR_MV 2
/* degree of rotation of the player per press */
# define PLR_ROT 2
/* nbr key you can press at the same time */
# define MAX_NB_KEY 3
/* nbr of elements to parse in the .cub file (without the map) */
# define TOTAL_ELEMENTS 6
/* screen width */
# define SCREEN_WIDTH 500
# define SCREEN_WIDTH 600
/* screen height */
# define SCREEN_HEIGHT 300
# define SCREEN_HEIGHT 500
/* screen focal (in degree) */
# define SCREEN_FOCAL 90
# define SCREEN_FOCAL 70
/* size of a cell on the map */
# define CELL 20
/* horizon fr perspectiv */
# define HORIZON 700
/*
* keys macro

View File

@@ -35,7 +35,6 @@ typedef struct s_rcast
t_vec screen_size;
t_vec ray;
t_vec wall;
int hor;
int screen_width;
int screen_height;
int screen_dist;
@@ -121,6 +120,7 @@ typedef struct s_plr
t_coord pos;
// rot
int rot;
int deg;
double cosi;
double cosj;
double sini;

View File

@@ -1,10 +1,8 @@
R 801 597
NO ./texture/grey.xpm
SO ./texture/brick.xpm
WE ./texture/wood.xpm
EA ./texture/blue.xpm
NO textures/coin.xpm
SO textures/coin.xpm
EA textures/coin.xpm
WE textures/coin.xpm
S ./texture/dickbutt.xpm
F 66,66,66
C 33,33,33
@@ -15,19 +13,19 @@ C 33,33,33
100000111110000101010001
100000100010000000000001
100000100010000100010001
100000100010000E00020001
100200110110000101010001
100000100010000E00000001
100000110110000101010001
100000000000000000000001
100000000000000000000001
100000000000000000000001
100000000000000000000001
100000000000000000000001
100000000200000000020001
100000002000020000000001
100000001100000000000001
100000001100000000000001
111111001100000000000011
110100001100000000000001
110000101100000000000011
110102001100000000000001
110100001100000000000001
110111111100000000000011
110000000000000000000111
111111111100000000001111

View File

@@ -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;
}

View File

@@ -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,0,1},
{1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,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,0,1},
{1,0,0,0,0,0,1,1,0,1,1,0,0,0,0,1,0,1,0,1,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,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,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,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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},
};
int i = 0;
map->content = 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);
}

View File

@@ -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 */
/* */
/* ************************************************************************** */

View File

@@ -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);