1
0

🏗️」 wip(Merge): Merged raycasting

This commit is contained in:
2024-11-06 12:53:26 +01:00
26 changed files with 734 additions and 109 deletions

View File

@ -6,13 +6,20 @@
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/04 17:01:05 by madumerg #+# #+# */
/* Updated: 2024/10/05 14:30:04 by madumerg ### ########.fr */
/* Updated: 2024/11/06 12:49:47 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CUB3D_H
# define CUB3D_H
# include "libft.h"
# include "mess_err.h"
# include <stdlib.h>
# include <math.h>
# include <unistd.h>
# include <fcntl.h>
# include <stdio.h>
# include "parsing.h"
#endif

View File

@ -1,41 +1,43 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* game.h :+: :+: :+: */
/* dda.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/11 16:38:40 by adjoly #+# #+# */
/* Updated: 2024/09/12 17:04:59 by adjoly ### ########.fr */
/* Created: 2024/10/28 13:04:36 by adjoly #+# #+# */
/* Updated: 2024/11/06 12:30:52 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef GAME_H
# define GAME_H
#ifndef DDA_H
# define DDA_H
typedef struct s_cub
# include <math.h>
# include "game.h"
# include "game/vectwo.h"
typedef struct s_dda
{
void *mlx;
void *win;
void *images;
char **map;
} t_cub;
bool h;
bool s;
int i;
t_vec2 map;
t_vec2 vert;
t_vec2 hori;
t_vec2 distance;
} t_dda;
#define ESCAPE_KEY 41
#define W_KEY 26
#define S_KEY 22
#define A_KEY 4
#define D_KEY 7
#define WHITE 0xFFFFFFFF
typedef struct s_ray
{
t_vec2 pos;
float tan;
float angle;
t_vec2 offset;
float distance;
} t_ray;
/**
* @brief This function is used to handle keypress
*
* @param key The key code of the pressed key
* @param mlx The mlx pointer(internal to MacroLibX)
*
* @return Minilibx go brrrr(useless always 0)
*/
int key_hook(int key, void *mlx);
void dda_algo(t_render *render, t_dda *dda, t_ray *ray);
#endif

86
includes/game/game.h Normal file
View File

@ -0,0 +1,86 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* game.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/11 16:38:40 by adjoly #+# #+# */
/* Updated: 2024/11/02 15:55:39 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef GAME_H
# define GAME_H
# include <unistd.h>
# include <stdint.h>
# include <math.h>
# include <stdbool.h>
# include <stdlib.h>
# include <stddef.h>
# include <stdio.h>
# include "settings.h"
# include "vectwo.h"
# include "../parsing.h"
typedef struct s_map
{
char **arr;
int floor;
int celling;
char p_side;
t_coord p_spawnpoint;
t_coord size;
} t_map;
typedef struct s_player
{
t_vec2 coord;
float direction;
} t_player;
typedef struct s_render
{
t_map *world;
void *mlx;
void *win;
void *img;
t_player *player;
void *texture[4];
} t_render;
/**
* @brief This function is used to handle keypress
*
* @param key The key code of the pressed key
* @param mlx The mlx pointer(internal to MacroLibX)
*
* @return Minilibx go brrrr(useless always 0)
*/
int key_hook(int key, void *param);
/**
* @brief This function is here to change the direction of the player
* by setting the t_player->direction and check overflow to be
* sure it stays between 0 and 2pi because it is expressed in
* radians
*
* @param speed The speed a which the player rotate
* @param clockwise The direction which the player rotate
* @param player A pointer to a t_player struct
*/
void change_direction(float speed, bool clockwise, t_player *player);
/**
* @brief Render a cub3d frame by executing a dda on every ray and
* putting the pixel on the window
*
* @param render The render struct with everything i need
*/
void render_frame(t_render *render);
#endif

14
includes/game/math.h Normal file
View File

@ -0,0 +1,14 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* math.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/29 10:07:24 by adjoly #+# #+# */
/* Updated: 2024/10/29 10:08:53 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef
void fix_ang(float *ang);

33
includes/game/settings.h Normal file
View File

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* settings.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/04 14:06:39 by adjoly #+# #+# */
/* Updated: 2024/11/02 15:55:02 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SETTINGS_H
# define SETTINGS_H
// Key code
# define ESCAPE_KEY 41
# define W_KEY 26
# define S_KEY 22
# define A_KEY 4
# define D_KEY 7
# define WHITE 0xFFFFFFFF
# define WINDOW_W 1600
# define WINDOW_H 900
# define PLAYER_ROT_SPEED 0.034906585039887
# define PLAYER_SPEED 1.5
# define FOV 70
# define CHUNK_SIZE 64
#endif

View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils_math.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/29 10:07:24 by adjoly #+# #+# */
/* Updated: 2024/11/02 15:54:32 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef UTILS_MATH_H
# define UTILS_MATH_H
# include <math.h>
void fix_ang(float *ang);
#endif

45
includes/game/vectwo.h Normal file
View File

@ -0,0 +1,45 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vectwo.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/28 13:32:14 by adjoly #+# #+# */
/* Updated: 2024/11/02 15:51:49 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef VECTWO_H
# define VECTWO_H
# include <stdint.h>
typedef struct s_vec2
{
float x;
float y;
} t_vec2;
/* ------------------ Vec2 Utils ------------------ */
/**
* @brief Gives you the distance between two point
*/
float vec2_dist(t_vec2 first, t_vec2 second);
/**
* @brief Just add second to first
*/
void vec2_add(t_vec2 *first, t_vec2 second);
/**
* @brief Just substract second to first
*/
void vec2_sub(t_vec2 *first, t_vec2 second);
/**
* @brief Multiply a vec2 by a number n and returns it
*/
t_vec2 vec2_mul_ret(t_vec2 vec, float n);
#endif

View File

@ -6,7 +6,7 @@
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/12 12:49:16 by madumerg #+# #+# */
/* Updated: 2024/10/06 16:16:31 by madumerg ### ########.fr */
/* Updated: 2024/11/06 12:50:01 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */