-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Textures less trippy (still rotating with the players cam)
- Loading branch information
Yesim Zaim
committed
Jan 24, 2024
1 parent
67f736b
commit d361c67
Showing
7 changed files
with
43 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"files.associations": { | ||
"cstdlib": "c", | ||
"stdio.h": "c" | ||
} | ||
"cstdlib": "c", | ||
"stdio.h": "c", | ||
"meta.h": "c" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,20 +6,22 @@ | |
/* By: yzaim <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2024/01/24 13:13:37 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/24 14:17:50 by yzaim ######## odam.nl */ | ||
/* Updated: 2024/01/24 16:06:35 by yzaim ######## 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_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}; | ||
|
||
|
||
int p = y - WINDOW_HEIGHT / 2; | ||
double posZ = 0.5 * WINDOW_HEIGHT; | ||
|
@@ -29,5 +31,8 @@ t_vray floorcaster(t_vec2d pp, t_vec2d dir, t_vec2d cam_plane, uint32_t y) | |
|
||
ray.floor.x = pp.x + row_distance + raydir_left.x; | ||
ray.floor.y = pp.y + row_distance + raydir_left.y; | ||
|
||
|
||
|
||
return (ray); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: yzaim <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2024/01/08 15:27:23 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/24 14:06:15 by yzaim ######## odam.nl */ | ||
/* Updated: 2024/01/24 16:09:02 by yzaim ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -74,6 +74,7 @@ void player_raycast(t_player *p) | |
p->vrays[row] = floorcaster(p->position, p->direction, p->cam_plane, row); | ||
row++; | ||
} | ||
p->should_render = true; | ||
|
||
// TODO Just create the player.plane here instead of saving it. | ||
col = 0; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: yzaim <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2024/01/08 15:28:08 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/24 14:25:11 by yzaim ######## odam.nl */ | ||
/* Updated: 2024/01/24 16:06:25 by yzaim ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -59,17 +59,20 @@ static void draw_column(t_meta *meta, t_ray *ray, uint32_t col, uint32_t h) | |
} | ||
} | ||
|
||
void draw_fc(mlx_image_t *image, t_vray vray, mlx_texture_t *f_tex, mlx_texture_t *c_tex, uint32_t col, uint32_t row) | ||
void draw_fc(mlx_image_t *image, t_vray *vray, mlx_texture_t *f_tex, mlx_texture_t *c_tex, uint32_t col, uint32_t row) | ||
{ | ||
t_vec2i cell; | ||
|
||
cell = (t_vec2i){(int)vray.floor.x, (int)vray.floor.y}; | ||
cell = (t_vec2i){(int)vray->floor.x, (int)vray->floor.y}; | ||
// cell = vec2d_to_vec2i(floor); | ||
|
||
// coordinate of pixel in texture | ||
const t_vec2i c_t = (t_vec2i){(int)(c_tex->width * (vray.floor.x - cell.x)) & (c_tex->width - 1), (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 t_vec2i c_t = (t_vec2i){(int)(c_tex->width * (vray->floor.x - cell.x)) & (c_tex->width - 1), | ||
(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_color = pixel_picker(c_tex, c_t.x, c_t.y); | ||
const uint32_t f_color = pixel_picker(f_tex, f_t.x, f_t.y); | ||
|
@@ -82,17 +85,22 @@ void render_viewport(mlx_image_t *image, t_player *p) | |
uint32_t col = 0; | ||
uint32_t row = 0; | ||
//floor and ceiling | ||
while (row < image->height) | ||
|
||
if (p->should_render) | ||
{ | ||
col = 0; | ||
while (col < image->width) | ||
row = 0; | ||
while (row < image->height) | ||
{ | ||
draw_fc(p->meta->image, p->vrays[row], p->meta->attributes.f.tex, p->meta->attributes.c.tex, col, row); | ||
col++; | ||
col = 0; | ||
while (col < image->width) | ||
{ | ||
draw_fc(p->meta->image, &p->vrays[row], p->meta->attributes.f.tex, p->meta->attributes.c.tex, col, row); | ||
col++; | ||
} | ||
row++; | ||
} | ||
row++; | ||
p->should_render = false; | ||
} | ||
|
||
col = 0; | ||
while(col < image->width) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: yzaim <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2024/01/08 15:26:51 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/24 11:50:31 by yzaim ######## odam.nl */ | ||
/* Updated: 2024/01/24 15:49:05 by yzaim ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -17,9 +17,6 @@ | |
// calculate texture position | ||
void wall_texture_position(mlx_texture_t *texture, t_ray *ray, t_vec2i line_points, uint32_t h) | ||
{ | ||
static double x_old = 0; | ||
static double y_old = 0; | ||
|
||
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters