From a108cc090466614987ad8b84a15ada7381312ae5 Mon Sep 17 00:00:00 2001 From: Joppe Boeve Date: Wed, 17 Jan 2024 16:28:49 +0100 Subject: [PATCH] IT WORKKK!??!?!?! DANKU DUCOO --- src/cub3d.c | 4 ++-- src/game/raycaster.c | 7 ++++--- src/game/render_viewport.c | 17 +++-------------- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/cub3d.c b/src/cub3d.c index 9889a64..16fd9bd 100644 --- a/src/cub3d.c +++ b/src/cub3d.c @@ -6,7 +6,7 @@ /* By: yzaim +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/08 15:24:47 by yzaim #+# #+# */ -/* Updated: 2024/01/17 13:25:18 by jboeve ######## odam.nl */ +/* Updated: 2024/01/17 16:28:16 by jboeve ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -118,7 +118,7 @@ int cub3d(int argc, char **argv) mlx_set_cursor_mode(meta.mlx, MLX_MOUSE_HIDDEN); mlx_loop_hook(meta.mlx, game_loop, &meta); mlx_loop_hook(meta.mlx, fps_hook, &meta); - // mlx_cursor_hook(meta.mlx, cursor_hook, &meta); + mlx_cursor_hook(meta.mlx, cursor_hook, &meta); mlx_loop(meta.mlx); mlx_terminate(meta.mlx); meta_free(&meta); diff --git a/src/game/raycaster.c b/src/game/raycaster.c index 1c24f0b..a9a5d60 100644 --- a/src/game/raycaster.c +++ b/src/game/raycaster.c @@ -6,7 +6,7 @@ /* By: yzaim +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/08 15:27:33 by yzaim #+# #+# */ -/* Updated: 2024/01/17 15:58:39 by jboeve ######## odam.nl */ +/* Updated: 2024/01/17 16:27:30 by jboeve ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -126,10 +126,11 @@ t_ray raycaster_cast(t_vec2d pp, t_vec2d dir, t_ray_hitfunc hit, const void *par r.line_point.y = r.line_height / 2 + ((double)WINDOW_HEIGHT) / 2; if (r.line_point.y >= WINDOW_HEIGHT) r.line_point.y = WINDOW_HEIGHT - 1; + if (r.hit_side == SIDE_N || r.hit_side == SIDE_S) - r.wall_x = r.map_pos.y + r.length * r.direction.y; + r.wall_x = pp.y + r.length * r.direction.y; else - r.wall_x = r.map_pos.x + r.length * r.direction.x; + r.wall_x = pp.x + r.length * r.direction.x; r.wall_x -= floor(r.wall_x); return (r); } diff --git a/src/game/render_viewport.c b/src/game/render_viewport.c index a0fdda8..d5d1ab7 100644 --- a/src/game/render_viewport.c +++ b/src/game/render_viewport.c @@ -6,7 +6,7 @@ /* By: yzaim +#+ */ /* +#+ */ /* Created: 2024/01/08 15:28:08 by yzaim #+# #+# */ -/* Updated: 2024/01/17 16:10:04 by jboeve ######## odam.nl */ +/* Updated: 2024/01/17 16:22:52 by jboeve ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -38,20 +38,15 @@ static void draw_column(t_meta *meta, t_vec2i line, t_ray *ray, uint32_t col, ui texture = get_texture(ray->hit_side, meta->attributes); - ray->texture_point.x = (int)(ray->wall_x * (int)texture->width); - + ray->texture_point.x = (int)(ray->wall_x * (double)texture->width); if ((ray->hit_side == SIDE_N || ray->hit_side == SIDE_S) && ray->direction.x > 0) - { ray->texture_point.x = texture->width - ray->texture_point.x - 1; - } if ((ray->hit_side == SIDE_E || ray->hit_side == SIDE_W) && ray->direction.y < 0) - { ray->texture_point.x = texture->width - ray->texture_point.x - 1; - } ray->step = 1.0 * texture->height / ray->line_height; + ray->texture_position = (ray->line_point.x + (ray->line_height - h) / 2) * ray->step; - ray->texture_position = ((ray->line_point.x - (double) (h / 2.0) + ray->line_height / 2.0) * ray->step); printf("line_height [%lf]\n", ray->line_height); printf("step [%lf]\n", ray->step); @@ -62,16 +57,10 @@ static void draw_column(t_meta *meta, t_vec2i line, t_ray *ray, uint32_t col, ui y = 0; while (y < (int32_t) h) { - // ceiling if (y < line.x) - { color = find_color(meta->attributes.ceiling_c); - } - // floor else if (y > line.y) - { color = find_color(meta->attributes.floor_c); - } else { ray->texture_point.y = ((int) ray->texture_position) & (texture->height - 1);