Skip to content

Commit

Permalink
WRKS!!???!?!?
Browse files Browse the repository at this point in the history
  • Loading branch information
Joppe Boeve committed Jan 24, 2024
1 parent 20b3c73 commit 0a01786
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
16 changes: 7 additions & 9 deletions src/game/floorcaster.c
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* floorcaster.c :+: :+: */
/* floorcaster.c :+: :+: */
/* +:+ */
/* By: yzaim <[email protected]> +#+ */
/* +#+ */
/* Created: 2024/01/24 13:13:37 by yzaim #+# #+# */
/* Updated: 2024/01/24 17:05:20 by yzaim ######## odam.nl */
/* Updated: 2024/01/24 18:23:45 by jboeve ######## odam.nl */
/* */
/* ************************************************************************** */

#include "meta.h"

t_vray floorcaster(t_vec2d pp, t_vec2d dir, t_vec2d cam_plane, uint32_t y)
{

t_vray ray;
t_vec2d raydir_left;
t_vec2d raydir_right;

raydir_left = ((t_vec2d){dir.x - cam_plane.x, dir.y - cam_plane.y});
raydir_right = ((t_vec2d){dir.x + cam_plane.x, dir.y + cam_plane.y});

raydir_left = ((t_vec2d){dir.x - cam_plane.x, dir.y - cam_plane.y});
raydir_right = ((t_vec2d){dir.x + cam_plane.x, dir.y + cam_plane.y});

int p = y - WINDOW_HEIGHT / 2;
double posZ = 0.5 * WINDOW_HEIGHT;
double row_distance = posZ / p;
ray.step.x = row_distance * (raydir_right.x - raydir_left.x) / WINDOW_WIDTH;
ray.step.y = row_distance * (raydir_right.y - raydir_left.y) / WINDOW_WIDTH;

ray.floor.x = pp.x + row_distance + raydir_left.x;
ray.floor.y = pp.y + row_distance + raydir_left.y;
ray.floor.x = pp.x + row_distance * raydir_left.x;
ray.floor.y = pp.y + row_distance * raydir_left.y;

return (ray);
}
}
4 changes: 2 additions & 2 deletions src/game/player.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* player.c :+: :+: */
/* player.c :+: :+: */
/* +:+ */
/* By: yzaim <[email protected]> +#+ */
/* +#+ */
/* Created: 2024/01/08 15:27:23 by yzaim #+# #+# */
/* Updated: 2024/01/24 17:09:42 by yzaim ######## odam.nl */
/* Updated: 2024/01/24 18:21:22 by jboeve ######## odam.nl */
/* */
/* ************************************************************************** */

Expand Down
6 changes: 3 additions & 3 deletions src/game/render_viewport.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* render_viewport.c :+: :+: */
/* render_viewport.c :+: :+: */
/* +:+ */
/* By: yzaim <[email protected]> +#+ */
/* +#+ */
/* Created: 2024/01/08 15:28:08 by yzaim #+# #+# */
/* Updated: 2024/01/24 17:08:29 by yzaim ######## odam.nl */
/* Updated: 2024/01/24 18:17:54 by jboeve ######## odam.nl */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -71,7 +71,7 @@ void draw_fc(mlx_image_t *image, t_vray *vray, mlx_texture_t *f_tex, mlx_texture
(int)(c_tex->height * (vray->floor.y - cell.y)) & (c_tex->height - 1)};
const t_vec2i f_t = (t_vec2i){(int)(f_tex->width * (vray->floor.x - cell.x)) & (f_tex->width - 1),
(int)(f_tex->height * (vray->floor.y - cell.y)) & (f_tex->height - 1)};

vray->floor = vec2d_add(vray->floor, vray->step);

const uint32_t c_pixel = pixel_picker(c_tex, c_t.x, c_t.y);
Expand Down

0 comments on commit 0a01786

Please sign in to comment.