|
|
@ -6,7 +6,7 @@ |
|
|
|
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|
|
|
/* +#+#+#+#+#+ +#+ */ |
|
|
|
/* Created: 2022/05/31 09:33:02 by narnaud #+# #+# */ |
|
|
|
/* Updated: 2022/11/14 16:45:42 by narnaud ### ########.fr */ |
|
|
|
/* Updated: 2022/11/21 19:04:16 by narnaud ### ########.fr */ |
|
|
|
/* */ |
|
|
|
/* ************************************************************************** */ |
|
|
|
|
|
|
@ -30,7 +30,7 @@ void draw_wall(t_env *env, t_rc *rc, int wallHeight, int *wall_lim) |
|
|
|
double y_out; |
|
|
|
|
|
|
|
tex_height = env->tex[rc->tex].height; |
|
|
|
tex.x = (int)(rc->wallX * (double)env->tex[rc->tex].width); |
|
|
|
tex.x = (int)(rc->wall_x * (double)env->tex[rc->tex].width); |
|
|
|
if ((!rc->side && rc->vec.x > 0) || (rc->side && rc->vec.y < 0)) |
|
|
|
tex.x = env->tex[rc->tex].width - tex.x - 1; |
|
|
|
step = 1.0 * tex_height / wallHeight; |
|
|
@ -50,15 +50,15 @@ void draw_vert(t_env *env, t_rc *rc, int side) |
|
|
|
int wall_height; |
|
|
|
int wall_lim[2]; |
|
|
|
|
|
|
|
wall_height = (int)(WIN_Y_SZ / rc->sDist[side]); |
|
|
|
wall_height = (int)(WIN_Y_SZ / rc->s_dist[side]); |
|
|
|
if (wall_height < 0) |
|
|
|
wall_height = 0; |
|
|
|
get_wall(wall_lim, wall_lim + 1, wall_height); |
|
|
|
draw_rectangle(env, (t_rect){(t_vec){rc->x, 0}, |
|
|
|
(t_vec){1, wall_lim[0]}, env->ceilColor}, 0); |
|
|
|
(t_vec){1, wall_lim[0]}, env->ceil_color}, 0); |
|
|
|
draw_wall(env, rc, wall_height, wall_lim); |
|
|
|
draw_rectangle(env, (t_rect){(t_vec){rc->x, wall_lim[1]}, |
|
|
|
(t_vec){1, WIN_Y_SZ - wall_lim[1]}, env->floorColor}, 0); |
|
|
|
(t_vec){1, WIN_Y_SZ - wall_lim[1]}, env->floor_color}, 0); |
|
|
|
} |
|
|
|
|
|
|
|
void render_view(t_env *env) |
|
|
@ -72,14 +72,14 @@ void render_view(t_env *env) |
|
|
|
{ |
|
|
|
ft_bzero(&rc, sizeof(rc)); |
|
|
|
cam_x = 2 * x / (double)WIN_X_SZ - 1; |
|
|
|
dvec_set(&rc.vec, env->playerDir.x + env->camPlan.x * cam_x, |
|
|
|
env->playerDir.y + env->camPlan.y * cam_x); |
|
|
|
rc.cell = (int [2]){env->playerPos.x, env->playerPos.y}; |
|
|
|
dvec_set(&rc.vec, env->player_dir.x + env->cam_plan.x * cam_x, |
|
|
|
env->player_dir.y + env->cam_plan.y * cam_x); |
|
|
|
rc.cell = (int [2]){env->player_pos.x, env->player_pos.y}; |
|
|
|
rc.step = (int [2]){0, 0}; |
|
|
|
rc.x = x; |
|
|
|
init_ray(env, &rc); |
|
|
|
while (!ray_hit(env, &rc)) |
|
|
|
rc.sDist[rc.side] += rc.dDist[rc.side]; |
|
|
|
rc.s_dist[rc.side] += rc.d_dist[rc.side]; |
|
|
|
check_side(&rc); |
|
|
|
draw_vert(env, &rc, rc.side); |
|
|
|
x++; |
|
|
|