From 778ddef39392bbdb54e58e8b64449b777df87b18 Mon Sep 17 00:00:00 2001 From: hugogogo Date: Fri, 29 Apr 2022 09:57:41 +0200 Subject: [PATCH] wip solving buble effect by wall height calculation --- headers/cube3d_macro.h | 2 +- headers/cube3d_proto.h | 2 -- srcs/cube3d.c | 5 ----- srcs/draw/raycast.c | 11 +++++++++++ srcs/player/player_rotates.c | 15 --------------- 5 files changed, 12 insertions(+), 23 deletions(-) diff --git a/headers/cube3d_macro.h b/headers/cube3d_macro.h index dbc1015..2415f9b 100644 --- a/headers/cube3d_macro.h +++ b/headers/cube3d_macro.h @@ -16,7 +16,7 @@ /* screen width */ # define SCREEN_WIDTH 500 /* screen height */ -# define SCREEN_HEIGHT 200 +# define SCREEN_HEIGHT 300 /* screen focal (in degree) */ # define SCREEN_FOCAL 90 /* size of a cell on the map */ diff --git a/headers/cube3d_proto.h b/headers/cube3d_proto.h index 2ac7f01..ea12ba9 100644 --- a/headers/cube3d_proto.h +++ b/headers/cube3d_proto.h @@ -1,8 +1,6 @@ #ifndef CUBE3D_PROTO_H # define CUBE3D_PROTO_H -void plr_turn(t_plr *plr, int deg); - // ------------------------------- // SRC // ------------------------------- diff --git a/srcs/cube3d.c b/srcs/cube3d.c index af82b9a..18c47b2 100644 --- a/srcs/cube3d.c +++ b/srcs/cube3d.c @@ -42,11 +42,6 @@ int main(int ac, char **av) mb_init(destroy_mlx, game); // draw game a first time before it start - - // tmp - plr_turn(&game->plr, -63); - // tmp end - draw(game); // receive a keypress event diff --git a/srcs/draw/raycast.c b/srcs/draw/raycast.c index 48a8d3e..01ba6ac 100644 --- a/srcs/draw/raycast.c +++ b/srcs/draw/raycast.c @@ -57,6 +57,7 @@ static void wall_height(t_rcast *rcast) { int height; +/* height = rcast->screen_height * (rcast->hor - rcast->ray_len) / rcast->hor; if (height < 0) @@ -66,6 +67,16 @@ static void wall_height(t_rcast *rcast) rcast->wall.start.y = rcast->screen_height / 2 + height / 2; rcast->wall.end.y = rcast->screen_height / 2 - height / 2; +*/ + if (rcast->ray_len) + height = rcast->screen_height / rcast->ray_len; + + rcast->wall.start.y = -height / 2 + rcast->screen_height / 2; + if (rcast->wall.start.y < 0) + rcast->wall.start.y = 0; + rcast->wall.end.y = height / 2 + rcast->screen_height / 2; + if (rcast->wall.end.y >= rcast->screen_height) + rcast->wall.end.y = rcast->screen_height; } void draw_column(t_game *game, t_rcast *rcast) diff --git a/srcs/player/player_rotates.c b/srcs/player/player_rotates.c index 0a31c75..a0f3f55 100644 --- a/srcs/player/player_rotates.c +++ b/srcs/player/player_rotates.c @@ -73,18 +73,3 @@ void plr_turn_right(t_plr *plr) plr->cosj = cos(radj); plr->sinj = sin(radj); } - -void plr_turn(t_plr *plr, int deg) -{ - double radi; - double radj; - - plr->rot = deg; - // calculate trigo for rotations - radi = plr->rot * M_PI / 180; - radj = radi + (M_PI / 2); - plr->cosi = cos(radi); - plr->sini = sin(radi); - plr->cosj = cos(radj); - plr->sinj = sin(radj); -}