-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged main into branch. Issues with render_utils having been moved a…
…nd subsequently deleted
- Loading branch information
Showing
11 changed files
with
109 additions
and
71 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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
# By: jteissie <[email protected]> +#+ +:+ +#+ # | ||
# +#+#+#+#+#+ +#+ # | ||
# Created: 2024/08/15 12:02:08 by tsuchen #+# #+# # | ||
# Updated: 2024/08/29 17:27:35 by jteissie ### ########.fr # | ||
# Updated: 2024/08/29 17:44:16 by jteissie ### ########.fr # | ||
# # | ||
# **************************************************************************** # | ||
|
||
|
@@ -15,7 +15,8 @@ NAME = cub3d | |
SRCS_M = main.c \ | ||
game_init.c \ | ||
cleanup.c \ | ||
color_utils.c | ||
color_utils.c \ | ||
render_utils.c | ||
|
||
|
||
SRCS_PS = parser.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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: jteissie <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/15 00:19:44 by tsuchen #+# #+# */ | ||
/* Updated: 2024/08/29 17:33:28 by jteissie ### ########.fr */ | ||
/* Updated: 2024/08/29 17:42:57 by jteissie ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -48,10 +48,11 @@ | |
# define WIDTH 1280 | ||
# define HEIGHT 720 | ||
# define FOV 90 | ||
# define ROT_STEP 1.0f | ||
# define MOV_STEP 0.1f | ||
# define KEY_PRESS 2 | ||
# define MOUSE_PRESS 4 | ||
# define MOUSE_MOVE 6 | ||
# define CLOSE_BUTTON 17 | ||
# define FILE_EXTENSION ".cub" | ||
|
||
typedef enum e_texture t_texture; | ||
|
@@ -80,6 +81,20 @@ typedef enum e_bool | |
FALSE, | ||
TRUE, | ||
} t_bool; | ||
|
||
typedef enum e_rot | ||
{ | ||
CLOCK, | ||
CCLOCK, | ||
} t_rot; | ||
|
||
typedef enum e_move | ||
{ | ||
FORWARD, | ||
BACKWARD, | ||
RIGHT, | ||
LEFT, | ||
} t_move; | ||
typedef enum e_p_dir | ||
{ | ||
NORTH = 'N', | ||
|
@@ -88,6 +103,15 @@ typedef enum e_p_dir | |
EAST = 'E', | ||
} t_p_dir; | ||
|
||
typedef struct s_image | ||
{ | ||
void *img; | ||
char *addr; | ||
int bpp; | ||
int line_length; | ||
int endian; | ||
} t_image; | ||
|
||
typedef struct s_data | ||
{ | ||
char *map_path; | ||
|
@@ -97,7 +121,7 @@ typedef struct s_data | |
char **map; | ||
void *mlx; | ||
void *window; | ||
t_image *image; | ||
t_image image; | ||
t_textdata *textures; | ||
t_wall wall_data; | ||
t_p_dir p_dir_default; | ||
|
@@ -117,5 +141,8 @@ int create_trgb(int t, int r, int g, int b); | |
int get_color(int trgb, char index); | ||
int add_shade(double factor, int color); | ||
int get_opposite(int color); | ||
/* rendering utils*/ | ||
void rc_mlx_pixel_put(t_image *image, int x, int y, int color); | ||
void rc_stripe_pixel_put(t_data *data, int x, double ray_dist); | ||
|
||
#endif |
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,34 +6,18 @@ | |
/* By: jteissie <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/27 17:39:13 by tsuchen #+# #+# */ | ||
/* Updated: 2024/08/29 17:37:26 by jteissie ### ########.fr */ | ||
/* Updated: 2024/08/29 17:43:28 by jteissie ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef RAYCASTING_H | ||
# define RAYCASTING_H | ||
|
||
# define WIDTH 1280 | ||
# define HEIGHT 720 | ||
|
||
# include "vector.h" | ||
# include "cub3d.h" | ||
|
||
typedef struct s_vec t_vec; | ||
typedef struct s_data t_data; | ||
|
||
typedef struct s_image | ||
{ | ||
void *img; | ||
char *addr; | ||
int bpp; | ||
int line_length; | ||
int endian; | ||
} t_image; | ||
|
||
|
||
void rc_mlx_pixel_put(t_image *image, int x, int y, int color); | ||
void rc_stripe_pixel_put(t_data *data, int x, double ray_dist); | ||
int rc_dda(t_vec *dist, t_vec *unit_dist, t_vec *pos, t_vec *dir); | ||
void rc_ray_init(t_vec *dist, t_vec *pos, t_vec *dir, t_vec *unit_dst); | ||
double rc_raydist(t_vec *ray, t_data *data); | ||
|
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: tsuchen <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/27 10:56:32 by tsuchen #+# #+# */ | ||
/* Updated: 2024/08/28 16:45:05 by tsuchen ### ########.fr */ | ||
/* Updated: 2024/08/29 16:43:25 by tsuchen ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -38,5 +38,6 @@ void vec_mirror(t_vec *vec); | |
void vec_transp(t_vec *vec); | ||
void vec_rotate(t_vec *vec, double angle); | ||
double vec_cos(t_vec *vec_a, t_vec *vec_b); | ||
void vec_copy_scale(t_vec *vec_a, const t_vec *vec_b, double scale); | ||
|
||
#endif |
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: jteissie <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/27 17:04:32 by jteissie #+# #+# */ | ||
/* Updated: 2024/08/29 14:38:59 by jteissie ### ########.fr */ | ||
/* Updated: 2024/08/29 17:45:39 by jteissie ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -37,11 +37,11 @@ int cleanup(t_data *data) | |
{ | ||
if (data->textures) | ||
cleanup_textures(data->textures, data->mlx); | ||
if (data->image) | ||
mlx_destroy_image(data->mlx, data->image->img); | ||
if (data->image.img) | ||
mlx_destroy_image(data->mlx, data->image.img); | ||
if (data->window) | ||
mlx_destroy_window(data->mlx, data->window); | ||
mlx_destroy_display(data->mlx); | ||
free(data->mlx); | ||
return (SUCCESS); | ||
exit(SUCCESS); | ||
} |
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,7 +6,7 @@ | |
/* By: jteissie <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/27 17:03:43 by jteissie #+# #+# */ | ||
/* Updated: 2024/08/29 17:29:02 by jteissie ### ########.fr */ | ||
/* Updated: 2024/08/29 17:44:55 by jteissie ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -45,7 +45,7 @@ int game_init(t_data *data) | |
data->mlx = mlx_init(); | ||
if (!data->mlx) | ||
return (PANIC); | ||
data->window = mlx_new_window(data->mlx, WIDTH, HEIGHT, "cub3d"); | ||
data->window = mlx_new_window(data->mlx, WIDTH, HEIGHT, P_NAME); | ||
if (!data->window) | ||
{ | ||
cleanup(data); | ||
|
@@ -56,5 +56,8 @@ int game_init(t_data *data) | |
cleanup(data); | ||
return (PANIC); | ||
} | ||
data->image.img = mlx_new_image(data->mlx, WIDTH, HEIGHT); | ||
data->image.addr = mlx_get_data_addr(data->image.img, &data->image.bpp, | ||
&data->image.line_length, &data->image.endian); | ||
return (SUCCESS); | ||
} |
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,7 +6,7 @@ | |
/* By: jteissie <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/15 12:13:34 by tsuchen #+# #+# */ | ||
/* Updated: 2024/08/29 17:30:08 by jteissie ### ########.fr */ | ||
/* Updated: 2024/08/29 17:45:05 by jteissie ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -52,7 +52,7 @@ double rc_raydist(t_vec *ray, t_data *data) | |
t_vec unit_dist; | ||
t_vec dist_ray; | ||
|
||
vec_init(&ray_pos, (int)data->p_pos.x, (int)data->p_pos.y); | ||
vec_init(&ray_pos, data->p_pos.x, data->p_pos.y); | ||
unit_dist.x = sqrt(1 + ((ray->y * ray->y) / (ray->x * ray->x))); | ||
unit_dist.y = sqrt(1 + ((ray->x * ray->x) / (ray->y * ray->y))); | ||
rc_ray_init(&dist_ray, &ray_pos, ray, &unit_dist); | ||
|
@@ -68,7 +68,7 @@ double rc_raydist(t_vec *ray, t_data *data) | |
return ((dist_ray.x - unit_dist.x) * vec_cos(ray, &data->p_dir)); | ||
} | ||
|
||
void rc_rendering(t_data *data) | ||
int rc_rendering(t_data *data) | ||
{ | ||
int x; | ||
double cam_x; | ||
|
@@ -84,5 +84,6 @@ void rc_rendering(t_data *data) | |
ray_dist = rc_raydist(&data->ray_dir, data); | ||
rc_stripe_pixel_put(data, x, ray_dist); | ||
} | ||
mlx_put_image_to_window(data->mlx, data->window, data->image->img, 0, 0); | ||
mlx_put_image_to_window(data->mlx, data->window, data->image.img, 0, 0); | ||
return (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,11 +6,11 @@ | |
/* By: jteissie <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/29 12:12:17 by tsuchen #+# #+# */ | ||
/* Updated: 2024/08/29 16:52:12 by jteissie ### ########.fr */ | ||
/* Updated: 2024/08/29 17:47:57 by jteissie ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "raycasting.h" | ||
#include "cub3d.h" | ||
|
||
void rc_mlx_pixel_put(t_image *image, int x, int y, int color) | ||
{ | ||
|
@@ -30,9 +30,9 @@ void rc_stripe_pixel_put(t_data *data, int x, double ray_dist) | |
while (++y < HEIGHT) | ||
{ | ||
if (y < (HEIGHT - wall_height) / 2) | ||
rc_mlx_pixel_put(data->image, x, y, data->textures->ceiling); | ||
rc_mlx_pixel_put(&data->image, x, y, data->textures->ceiling); | ||
else if (y > (HEIGHT + wall_height) / 2) | ||
rc_mlx_pixel_put(data->image, x, y, data->textures->floor); | ||
rc_mlx_pixel_put(&data->image, x, y, data->textures->floor); | ||
else | ||
mlx_render_wall(data, x, y, ray_dist); | ||
} | ||
|
Oops, something went wrong.