Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raycaster #15

Closed
wants to merge 49 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
adba72a
Merged stash
Dec 14, 2023
d21df57
Parser now sets its own player_start pos
Dec 14, 2023
46b6127
DDA BABY!?!
Dec 14, 2023
91cb91d
SIKE almost there
Dec 14, 2023
821555a
Workig on abstracting raycaster
Dec 15, 2023
bacdea8
changed the saving of position vector
ys-zm Dec 15, 2023
ecf00c2
Made raycaster
JopjeKnopje Dec 15, 2023
6c70475
Merge branch 'raycaster' of github.com:ys-zm/cub3d into raycaster
JopjeKnopje Dec 15, 2023
b5fa93b
Player.position is now between zero and the map's width, its only in …
JopjeKnopje Dec 15, 2023
c3588c9
Removed aboslute player position.
JopjeKnopje Dec 15, 2023
2b39dfa
More stuf
JopjeKnopje Dec 15, 2023
b971fd2
fixed small error in parser
Dec 15, 2023
8b5f4d1
Merge branch 'raycaster' of github.com:ys-zm/cub3d into raycaster
Dec 15, 2023
edd7d1e
Progress
JopjeKnopje Dec 15, 2023
266a19d
Cleaned up the raycaster function
JopjeKnopje Dec 15, 2023
e937e71
almost
JopjeKnopje Dec 15, 2023
a523494
Can cast and draw rays in minimap, but for some reason not yet in the
JopjeKnopje Dec 16, 2023
3ef257c
Its not the drawing function making the rays look weird in the Y-axis,
JopjeKnopje Dec 16, 2023
89db107
Add direction is normilized
JopjeKnopje Dec 16, 2023
ccaad96
Drawing camera plane.
JopjeKnopje Dec 16, 2023
43e581f
Can cast rays from camera plane, but there still is this weird rotation
JopjeKnopje Dec 16, 2023
996e391
doesnt really work but something is happening
ys-zm Dec 18, 2023
205a64f
Help
JopjeKnopje Dec 19, 2023
3d10132
Nothing really
JopjeKnopje Dec 19, 2023
e98246f
update
ys-zm Dec 20, 2023
8deafcb
update
ys-zm Dec 20, 2023
2716273
update
ys-zm Dec 20, 2023
180e5ec
update
ys-zm Dec 20, 2023
4f354fd
Ready for merge.
Dec 20, 2023
ef2c922
cleaned up
Dec 20, 2023
b19c074
Fixed weird not really fisheye issue
Dec 20, 2023
466fe00
ready for merge
Dec 20, 2023
5afb921
ready for merge
Dec 20, 2023
3ef6c7a
Merge branch 'raycaster' into test_raycast
JopjeKnopje Dec 20, 2023
5a245bb
Merge pull request #13 from ys-zm/test_raycast
JopjeKnopje Dec 20, 2023
4fff315
Merging stuff.
Dec 20, 2023
65b598e
fixed the wall overflow
Dec 20, 2023
4253a20
trying to fix the out of bounds issue
Dec 20, 2023
660a837
Add gameloop
Dec 20, 2023
def2338
Add fps hook.
Dec 20, 2023
9c9b75c
Addded `player_move` which takes a tranformation vector that it will add
Dec 21, 2023
53fdf6b
Add rotate speed modifier.
Dec 21, 2023
d1b117c
Working on adding basic mouse support
Dec 21, 2023
0489c4e
Mouse less choppy.
Dec 21, 2023
2921c91
Refactor `player_move` functions.
JopjeKnopje Jan 1, 2024
dc03553
Raycaster refactoring...
JopjeKnopje Jan 2, 2024
4719030
Refactored raycaster, and moved parser funcs stuff from meta.h to
JopjeKnopje Jan 2, 2024
b989215
Moved stuff around and add vector.h
JopjeKnopje Jan 2, 2024
1b7d149
Save rays to p.rays and draw then in render.c
JopjeKnopje Jan 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MLX42/include/MLX42/MLX42_Int.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: W2Wizard <[email protected]> +#+ */
/* +#+ */
/* Created: 2021/12/27 23:55:34 by W2Wizard #+# #+# */
/* Updated: 2023/11/10 03:22:56 by joppe ######## odam.nl */
/* Updated: 2023/12/21 01:39:28 by joppe ######## odam.nl */
/* */
/* ************************************************************************** */

Expand Down
32 changes: 10 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: #
# +:+ +:+ +:+ #
# By: jboeve <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/08/22 13:32:22 by jboeve #+# #+# #
# Updated: 2023/12/13 16:25:01 by jboeve ######## odam.nl #
# #
# **************************************************************************** #

######################
# OS Dependent flags #
######################
Expand All @@ -23,7 +11,7 @@ else ifeq ($(shell uname -m),x86_64)
endif

NAME := app
RUN_CMD := ./$(NAME) test_maps/simple.cub
RUN_CMD := ./$(NAME) test_maps/valid.cub

# CFLAGS += -Wall -Wextra -Werror
CFLAGS += -Wall -Wextra
Expand All @@ -49,17 +37,17 @@ SRCS = parser/check_elements.c \
parser/utils_one.c \
parser/utils_two.c \
utils/error.c \
utils/free.c \
utils/free.c \
utils/vec2d_utils.c \
utils/colors.c \
game/game.c \
game/draw.c \
game/keys.c \
game/player.c \
game/raycaster.c \
game/render.c \
cub3d.c \
game.c \
input.c \
render.c \
draw.c \
player.c \
utils.c \
test_utils.c \
map.c \
vector.c \
timer.c

HEADER_DIR := include
Expand Down
173 changes: 58 additions & 115 deletions include/meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: jboeve <[email protected]> +#+ */
/* +#+ */
/* Created: 2023/11/01 20:07:37 by jboeve #+# #+# */
/* Updated: 2023/12/13 16:24:24 by jboeve ######## odam.nl */
/* Updated: 2024/01/02 19:51:20 by joppe ######## odam.nl */
/* */
/* ************************************************************************** */

Expand All @@ -22,11 +22,11 @@
#include <unistd.h>
#include <fcntl.h>
#include <stdbool.h>
#include <limits.h>

#include "timer.h"
#include "vector.h"
#include "libft.h"
#include "parser.h"
#include "vector.h"
#include "get_next_line.h"
#include "MLX42/MLX42.h"

Expand All @@ -45,43 +45,44 @@
#define PI 3.1415926535

// Window settings
#define WINDOW_WIDTH 1920
#define WINDOW_HEIGHT 1080
#define WINDOW_TITLE "Gammoe"
// #define WINDOW_WIDTH 1920
// #define WINDOW_HEIGHT 1080

#define PLAYER_VIEWPORT_X 720
#define PLAYER_VIEWPORT_Y 512
#define PLAYER_VIEWPORT_WALL_WIDTH 8
#define WINDOW_WIDTH 1280
#define WINDOW_HEIGHT 720

#define WINDOW_TITLE "Gammoe"

#define TICK_RATE (1.0 / 60.0)

// TODO Move all this stuff to some kind of game.h
#define CELL_WIDTH 64
#define CELL_HEIGHT 64
#define CELL_SIZE 64

#define PLAYER_WIDTH 16
#define PLAYER_HEIGHT 16
#define PLAYER_RAY_COUNT 90
#define PLAYER_WALK_SPEED 15
#define PLAYER_ROTATE_SPEED 5
#define PLAYER_MOVE_SPEED 5.0
#define PLAYER_RUN_MODIFIER 2.5
#define PLAYER_ROTATE_SPEED 5.0
#define PLAYER_ROTATE_MODIFIER 2.5


#define PLAYER_MOV_SPEED 0.08

#define COLOR_BACKGROUND 0x111111FF
#define COLOR_PLAYER 0xFFFFFFFF

#define VEC_X 0
#define VEC_Y 1

// #define FOV 0.66
#define FOV 0.80

typedef bool (t_ray_hitfunc) (void *p, uint32_t x, uint32_t y);
typedef struct s_meta t_meta;

typedef enum e_cell_type {
MAP_EMPTY,
MAP_WALL,
MAP_SPACE,
} t_cell_type;



typedef union s_rgba
{
uint32_t value;
Expand All @@ -94,30 +95,35 @@ typedef union s_rgba
};
} t_rgba;


typedef enum e_side {
HIT_NONE,
HIT_NS,
HIT_EW,
} t_side;

typedef struct s_ray {
t_vec2f start;
t_vec2f end;
t_side hit_side;
double length;
t_vec2d direction;
} t_ray;

typedef struct s_meta t_meta;

// NOTE: Maybe switch to double instead of float?
typedef struct s_player {
t_meta *meta;
// TODO Have a map_position which will be the position relative to the leftmost square.
// Based on that position we can just `position / CELL_WIDTH` to find the cell position.
t_vec2i map_cell;
t_vec2f position;
t_vec2f direction;
t_vec2f beam;
t_ray rays[PLAYER_RAY_COUNT];
float angle_rad;
t_meta *meta;
t_ray rays[WINDOW_WIDTH];
t_vec2d cam_plane;
t_vec2d position;
t_vec2d direction;
} t_player;


typedef struct s_map {
t_cell_type *level;
uint32_t width;
uint32_t height;
t_vec2u player_start;
char player_start_dir;
} t_map;

typedef struct s_tex {
Expand All @@ -134,13 +140,14 @@ typedef struct s_meta {
mlx_image_t *image;
t_timer update_timer;
t_timer fps_timer;
t_player player;
t_player player;
uint32_t fps;
t_map map;
t_tex tex;
char *map_file;
} t_meta;


// cub3d.c
int cub3d(int argc, char *argv[]);

Expand All @@ -149,109 +156,45 @@ void game_init(t_meta *meta);
void game_loop(void* param);

// player.c
void player_move(t_player *p, t_vec2f transform);
void player_look(t_player *p, double angle);
void player_move(t_player *p, t_vec2d transform);
void player_turn(t_player *p, float radiant);
void player_raycast(t_player *p);

// input.c
void key_hook(mlx_key_data_t keydata, void* param);
void cursor_hook(double xpos, double ypos, void* param);
// keys.c
void mouse_hook(double xpos, double ypos, void* param);
void keys_handle(t_meta *meta, double time_delta);

// render.c
t_vec2i render_get_draw_offset();
void render_player_view(mlx_image_t *image, t_player *p);
void render_player(mlx_image_t *image, t_player *p);
void render_player_viewport(mlx_image_t *image, t_player *p);
void render_clear_bg(mlx_image_t *image);
void render_map_grid(mlx_image_t *image, t_map *m);

// map.c
t_cell_type map_get_cell_type(t_map *m, t_vec2f pos);
void render_minimap(mlx_image_t *image, t_map *m);

// draw.c
void draw_rect(mlx_image_t* image, uint32_t x_pos, uint32_t y_pos, uint32_t width, uint32_t height, uint32_t color);
void draw_line(mlx_image_t *image, t_vec2i start, t_vec2i end, t_rgba c);
void draw_put_pixel(mlx_image_t* image, uint32_t x, uint32_t y, uint32_t color);

// utils.c
float deg_to_rad(float deg);

// test_utils.c
void print_vec2f(const char *s, t_vec2f vec);
void print_vec2i(const char *s, t_vec2i vec);
void print_cell(t_cell_type cell);
void game_init(t_meta *meta);
void game_loop(void* param);

// keys.c
void keyhook(mlx_key_data_t keydata, void* param);
void keys_update(mlx_key_data_t keydata, void *param);

// draw.c
void draw_square(mlx_image_t* image, uint32_t x_pos, uint32_t y_pos, uint32_t width, uint32_t height, uint32_t color);
void cube_put_pixel(mlx_image_t* image, uint32_t x, uint32_t y, uint32_t color);

// check_map.c
int check_map(t_meta *meta, char *rect);
int find_index(t_meta *meta, uint32_t x, uint32_t y);

// free.c
void meta_free(t_meta *meta);

// PARSER

// parser.c
char *read_file(int fd);
int map_ext(char *file);
int parser(t_meta *meta, char *map_file);

// parse_map.c
bool is_map_line(char *file);
int input_map(t_meta *meta, char *file);

// parse_elements.c
int input_texture(t_tex *tex, char *file);
int input_colour(t_tex *tex, char *file);
int save_elements(t_tex *tex, char *file);
int parse_elements(t_meta *meta, char *file);

// check_colors.c
bool valid_rgb_value(char *file);
bool is_valid_color(char *file);
bool colors_valid(char *file);

// check_elements.c
bool is_valid_element(char *file);
bool only_spaces(char *file);
bool is_map_element(char *file);
bool elements_order(char *file);
bool check_missing(int *found);
bool is_missing(char *file);
bool is_duplicate(char *file);

// check_map.c
bool is_map_chars_valid(char *map);
int flood_fill(t_meta *meta, char *map, int x, int y);
bool save_start_pos(t_meta *meta, char *map);
bool is_floor_exposed(t_meta *meta, char *map);

// parse_textures.c
void get_colour_value(char *file, t_rgba *col);
char *get_tex_val(char *file);
bool is_texture(char *file);
bool is_colour(char *file);

// utils_one.c
void skip_line(char **file);
void skip_spaces(char **file);
void skip_digits(char **file);
int valid_map_char(char c);
int player_pos_char(char c);

// utils_two.c
uint32_t find_width(char *map);
uint32_t find_height(char *map);
char *make_rect(char *map, uint32_t w, uint32_t h);
// raycaster.c
t_ray raycaster_cast(t_meta *meta, t_vec2d pp, t_vec2d dir, t_ray_hitfunc hit);

// test_utils.c
void print_map(char *map, uint32_t w, uint32_t h);
void print_map(char *map, uint32_t w, uint32_t h);

// colors.c
int32_t set_color(int32_t r, int32_t g, int32_t b, int32_t a);
int32_t find_wall_color(t_side side);

// free.c
void meta_free(t_meta *meta);

#endif
Loading
Loading