-
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.
- Loading branch information
Yesim Zaim
committed
Jan 24, 2024
1 parent
9968c7e
commit 6ed2982
Showing
6 changed files
with
104 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* :::::::: */ | ||
/* floorcaster.c :+: :+: */ | ||
/* +:+ */ | ||
/* By: yzaim <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2024/01/24 13:13:37 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/24 13:29:23 by yzaim ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "meta.h" | ||
|
||
t_vec2d floorcaster(t_vec2d pp, t_vec2d dir, t_vec2d cam_plane, uint32_t y) | ||
{ | ||
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; | ||
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; | ||
|
||
t_vec2d floor; | ||
floor.x = pp.x + row_distance + raydir_left.x; | ||
floor.y = pp.y + row_distance + raydir_left.y; | ||
return (floor); | ||
} |
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,12 +1,12 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* player.c :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: yzaim <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/08 15:27:23 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/17 15:55:18 by jboeve ######## odam.nl */ | ||
/* :::::::: */ | ||
/* player.c :+: :+: */ | ||
/* +:+ */ | ||
/* By: yzaim <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2024/01/08 15:27:23 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/24 13:31:54 by yzaim ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -61,11 +61,20 @@ void player_turn(t_player *p, float radiant) | |
|
||
void player_raycast(t_player *p) | ||
{ | ||
uint32_t w = p->meta->image->width; | ||
uint32_t col; | ||
t_vec2d ray_start; | ||
double camera_x; | ||
uint32_t w = p->meta->image->width; | ||
uint32_t h = p->meta->image->height; | ||
uint32_t col; | ||
uint32_t row; | ||
t_vec2d ray_start; | ||
double camera_x; | ||
|
||
row = 0; | ||
while (row < h) | ||
{ | ||
p->vertical_rays[row] = floorcaster(p->position, p->direction, p->cam_plane, row); | ||
row++; | ||
} | ||
|
||
// TODO Just create the player.plane here instead of saving it. | ||
col = 0; | ||
while(col < w) | ||
|
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,12 +1,12 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* raycaster.c :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: yzaim <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/08 15:27:33 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/18 12:05:53 by jboeve ######## odam.nl */ | ||
/* :::::::: */ | ||
/* raycaster.c :+: :+: */ | ||
/* +:+ */ | ||
/* By: yzaim <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2024/01/08 15:27:33 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/24 13:11:30 by yzaim ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
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,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/18 12:27:01 by jboeve ######## odam.nl */ | ||
/* Updated: 2024/01/24 13:37:01 by yzaim ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -59,9 +59,27 @@ static void draw_column(t_meta *meta, t_ray *ray, uint32_t col, uint32_t h) | |
} | ||
} | ||
|
||
void draw_fc(t_vec2d floor, ) | ||
{ | ||
t_vec2i cell; | ||
|
||
cell = (t_vec2i){(int)floor.x, (int)floor.y}; | ||
// cell = vec2d_to_vec2i(floor); | ||
|
||
t_vec2i t; | ||
t.x = (int) | ||
} | ||
|
||
void render_viewport(mlx_image_t *image, t_player *p) | ||
{ | ||
uint32_t col = 0; | ||
//floor and ceiling | ||
while (col < image->width) | ||
{ | ||
|
||
} | ||
|
||
col = 0; | ||
while(col < image->width) | ||
{ | ||
draw_column(p->meta, &p->rays[col], col, image->height); | ||
|
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,12 +1,12 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* pixel_picker.c :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: yzaim <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/08 15:26:51 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/17 15:42:56 by jboeve ######## odam.nl */ | ||
/* :::::::: */ | ||
/* pixel_picker.c :+: :+: */ | ||
/* +:+ */ | ||
/* By: yzaim <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2024/01/08 15:26:51 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/24 11:50:31 by yzaim ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -43,18 +43,16 @@ void wall_texture_position(mlx_texture_t *texture, t_ray *ray, t_vec2i line_poin | |
|
||
uint32_t pixel_picker(mlx_texture_t *texture, int32_t x, int32_t y) | ||
{ | ||
int32_t r; | ||
int32_t g; | ||
int32_t b; | ||
int32_t a; | ||
int32_t index; | ||
uint8_t r; | ||
uint8_t g; | ||
uint8_t b; | ||
uint8_t a; | ||
uint32_t index; | ||
|
||
// printf("x: %u | y: %u\n", x, y); | ||
index = y * texture->width * 4 + x * 4; | ||
// printf("index: %d\n", index); | ||
r = (uint32_t)texture->pixels[index]; | ||
g = (uint32_t)texture->pixels[index + 1]; | ||
b = (uint32_t)texture->pixels[index + 2]; | ||
a = (uint32_t)texture->pixels[index + 3]; | ||
r = texture->pixels[index]; | ||
g = texture->pixels[index + 1]; | ||
b = texture->pixels[index + 2]; | ||
a = texture->pixels[index + 3]; | ||
return (r << 24 | g << 16 | b << 8 | a); | ||
} |