-
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.
almost there with floor and ceiling textures
- Loading branch information
Yesim Zaim
committed
Jan 24, 2024
1 parent
6ed2982
commit 67f736b
Showing
5 changed files
with
44 additions
and
28 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
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,14 +6,15 @@ | |
/* By: yzaim <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2024/01/24 13:13:37 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/24 13:29:23 by yzaim ######## odam.nl */ | ||
/* Updated: 2024/01/24 14:17:50 by yzaim ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "meta.h" | ||
|
||
t_vec2d floorcaster(t_vec2d pp, t_vec2d dir, t_vec2d cam_plane, uint32_t y) | ||
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; | ||
|
||
|
@@ -23,12 +24,10 @@ t_vec2d floorcaster(t_vec2d pp, t_vec2d dir, t_vec2d cam_plane, uint32_t y) | |
int p = y - WINDOW_HEIGHT / 2; | ||
double posZ = 0.5 * WINDOW_HEIGHT; | ||
double row_distance = posZ / p; | ||
t_vec2d floor_step; | ||
floor_step.x = row_distance * (raydir_right.x - raydir_left.x) / WINDOW_WIDTH; | ||
floor_step.y = row_distance * (raydir_right.y - raydir_left.y) / WINDOW_WIDTH; | ||
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; | ||
|
||
t_vec2d floor; | ||
floor.x = pp.x + row_distance + raydir_left.x; | ||
floor.y = pp.y + row_distance + raydir_left.y; | ||
return (floor); | ||
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 13:31:54 by yzaim ######## odam.nl */ | ||
/* Updated: 2024/01/24 14:06:15 by yzaim ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -71,7 +71,7 @@ void player_raycast(t_player *p) | |
row = 0; | ||
while (row < h) | ||
{ | ||
p->vertical_rays[row] = floorcaster(p->position, p->direction, p->cam_plane, row); | ||
p->vrays[row] = floorcaster(p->position, p->direction, p->cam_plane, row); | ||
row++; | ||
} | ||
|
||
|
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 13:37:01 by yzaim ######## odam.nl */ | ||
/* Updated: 2024/01/24 14:25:11 by yzaim ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -53,30 +53,44 @@ static void draw_column(t_meta *meta, t_ray *ray, uint32_t col, uint32_t h) | |
ray->texture_point.y = ((int) ray->texture_position) & (texture->height - 1); | ||
ray->texture_position += ray->step; | ||
color = pixel_picker(texture, (int)round(ray->texture_point.x), (int)round(ray->texture_point.y)); | ||
mlx_put_pixel(meta->image, col, y, color); | ||
} | ||
mlx_put_pixel(meta->image, col, y, color); | ||
y++; | ||
} | ||
} | ||
|
||
void draw_fc(t_vec2d floor, ) | ||
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)floor.x, (int)floor.y}; | ||
cell = (t_vec2i){(int)vray.floor.x, (int)vray.floor.y}; | ||
// cell = vec2d_to_vec2i(floor); | ||
|
||
t_vec2i t; | ||
t.x = (int) | ||
|
||
// 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 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); | ||
mlx_put_pixel(image, col, WINDOW_HEIGHT - row - 1, c_color); | ||
mlx_put_pixel(image, col, row, f_color); | ||
} | ||
|
||
void render_viewport(mlx_image_t *image, t_player *p) | ||
{ | ||
uint32_t col = 0; | ||
uint32_t col = 0; | ||
uint32_t row = 0; | ||
//floor and ceiling | ||
while (col < image->width) | ||
while (row < image->height) | ||
{ | ||
|
||
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++; | ||
} | ||
|
||
col = 0; | ||
|