Skip to content

Commit

Permalink
IT WORKKK!??!?!?! DANKU DUCOO
Browse files Browse the repository at this point in the history
  • Loading branch information
Joppe Boeve committed Jan 17, 2024
1 parent 437cdd8 commit a108cc0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/cub3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: yzaim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions src/game/raycaster.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: yzaim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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);
}
17 changes: 3 additions & 14 deletions src/game/render_viewport.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: yzaim <[email protected]> +#+ */
/* +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit a108cc0

Please sign in to comment.