「🏗️」 wip(DDA): Fuck that was hard (thx @kbz-8)
This commit is contained in:
@ -5,59 +5,38 @@
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/04 14:04:10 by adjoly #+# #+# */
|
||||
/* Updated: 2024/10/23 15:00:05 by adjoly ### ########.fr */
|
||||
/* Created: 2024/10/28 13:04:36 by adjoly #+# #+# */
|
||||
/* Updated: 2024/10/28 14:37:10 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef DDA_H
|
||||
# ifndef DDA_H
|
||||
# define DDA_H
|
||||
|
||||
# include "typedef.h"
|
||||
# include "settings.h"
|
||||
# include <stdint.h>
|
||||
# include <math.h>
|
||||
|
||||
/**
|
||||
* @brief Function used to get all the ray angle
|
||||
*
|
||||
* @param player The address of the t_player struct
|
||||
* @param dda The address of the t_dda struct
|
||||
*/
|
||||
void get_ray_angle(t_player *player, t_dda (*dda)[800]);
|
||||
# include "game.h"
|
||||
#include "game/vectwo.h"
|
||||
|
||||
/**
|
||||
* @brief Function used to setup all the dda variable prior to casting
|
||||
* the rays
|
||||
*
|
||||
* @param player The address of the t_player struct
|
||||
* @param dda The address of the t_dda struct
|
||||
*
|
||||
*/
|
||||
void setup_dda(t_dda (*dda)[800], t_player *player);
|
||||
typedef struct s_dda
|
||||
{
|
||||
bool h;
|
||||
int i;
|
||||
t_vec2 map;
|
||||
t_vec2 vert;
|
||||
t_vec2 hori;
|
||||
t_vec2 distance;
|
||||
} t_dda;
|
||||
|
||||
/**
|
||||
* @brief Function used to cast all the rays
|
||||
*
|
||||
* @param dda The address of the t_dda struct
|
||||
* @param map The map as a char **
|
||||
* @param map_coord The coordinate of the player on the map_grid
|
||||
*/
|
||||
void while_dda(t_dda (*dda)[800], char **map, t_player *player);
|
||||
typedef struct s_ray
|
||||
{
|
||||
t_vec2 pos;
|
||||
float tan;
|
||||
float angle;
|
||||
t_vec2 offset;
|
||||
float distance;
|
||||
} t_ray;
|
||||
|
||||
/// NEED TO COMBINE THOSE IF NOT USEFULL TO SEPARATE
|
||||
/**
|
||||
* @brief Function used to get the distance from the player of all rays
|
||||
*
|
||||
* @param dda The address of the t_dda struct
|
||||
*/
|
||||
float *dist_dda(t_dda dda[WINDOW_X / RAY_SIZE]);
|
||||
void dda_algo(t_player *play, t_render *render);
|
||||
|
||||
/**
|
||||
* @brief Function used to get the size of the line to be printed on the screen
|
||||
*
|
||||
* @param dda The array of the all the distance to the wall of the rays
|
||||
*/
|
||||
uint16_t *line_dda(float *wall_dist);
|
||||
|
||||
uint16_t *dda(t_player *player, char **map);
|
||||
#endif
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/11 16:38:40 by adjoly #+# #+# */
|
||||
/* Updated: 2024/10/24 11:38:56 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/10/28 14:08:09 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -21,10 +21,34 @@
|
||||
# include <stddef.h>
|
||||
# include <stdio.h>
|
||||
|
||||
# include "dda.h"
|
||||
# include "settings.h"
|
||||
# include "parsing.h"
|
||||
# include "typedef.h"
|
||||
|
||||
# include "vectwo.h"
|
||||
|
||||
# include "../parsing.h"
|
||||
|
||||
typedef struct s_map
|
||||
{
|
||||
char **arr;
|
||||
char p_side;
|
||||
t_coord p_spawnpoint;
|
||||
t_coord size;
|
||||
} t_map;
|
||||
|
||||
typedef struct s_render
|
||||
{
|
||||
t_map *world;
|
||||
void *mlx;
|
||||
void *win;
|
||||
void *texture[4];
|
||||
} t_render;
|
||||
|
||||
typedef struct s_player
|
||||
{
|
||||
t_vec2 coord;
|
||||
t_coord map_coords;
|
||||
double direction;
|
||||
} t_player;
|
||||
|
||||
/**
|
||||
* @brief This function is used to handle keypress
|
||||
@ -36,13 +60,6 @@
|
||||
*/
|
||||
int key_hook(int key, void *param);
|
||||
|
||||
/**
|
||||
* @brief This function is used to create an image with the player position
|
||||
*
|
||||
* @param cub The address of a t_cub struct filled with mlx data and other
|
||||
* thing
|
||||
*/
|
||||
void get_player_image(t_cub *cub);
|
||||
|
||||
/**
|
||||
* @brief This function is here to change the direction of the player
|
||||
@ -56,21 +73,4 @@ void get_player_image(t_cub *cub);
|
||||
*/
|
||||
void change_direction(double speed, bool clockwise, t_player *player);
|
||||
|
||||
/**
|
||||
* @brief Function used to draw a square
|
||||
*
|
||||
* @param cub The adress of a t_cub struct
|
||||
* @param coord The coordinate of the printed square
|
||||
* @param size The size of the printed square
|
||||
* @param color The color of the printed square
|
||||
*/
|
||||
void draw_square(t_cub *cub, t_coord coord, uint16_t size, int color);
|
||||
|
||||
/**
|
||||
* @brief Function used to draw the map
|
||||
*
|
||||
* @param cub The address of the t_cub struct
|
||||
*/
|
||||
void print_map(t_cub *cub);
|
||||
|
||||
#endif
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/04 14:06:39 by adjoly #+# #+# */
|
||||
/* Updated: 2024/10/23 11:18:38 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/10/28 14:04:25 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -21,11 +21,13 @@
|
||||
# define D_KEY 7
|
||||
|
||||
# define WHITE 0xFFFFFFFF
|
||||
# define DEG_TO_RAD 0.0174533
|
||||
|
||||
# define WINDOW_Y 900
|
||||
# define WINDOW_X 1600
|
||||
# define PLAYER_ROT_SPEED (2 * M_PI) / 128
|
||||
# define PLAYER_SPEED 3
|
||||
# define MAP_CHUNK_SIZE 64
|
||||
# define CHUNK_SIZE 64
|
||||
# define RAY_SIZE 2
|
||||
# define FOV ( 60 * (M_PI / 180) )
|
||||
|
||||
|
@ -1,68 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* typedef.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/04 14:28:24 by adjoly #+# #+# */
|
||||
/* Updated: 2024/10/23 14:33:33 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STRUCT_H
|
||||
# define STRUCT_H
|
||||
|
||||
# include <stdbool.h>
|
||||
# include "parsing.h"
|
||||
|
||||
/**
|
||||
* @brief Enum for the wall side that has been hit
|
||||
*/
|
||||
typedef enum s_wall_side
|
||||
{
|
||||
HORIZONTAL,
|
||||
VERTICAL
|
||||
} t_wall_side;
|
||||
|
||||
typedef struct s_coord_f
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
} t_coord_f;
|
||||
|
||||
typedef struct s_step
|
||||
{
|
||||
char x;
|
||||
char y;
|
||||
} t_step;
|
||||
|
||||
typedef struct s_player
|
||||
{
|
||||
t_coord coords;
|
||||
t_coord map_coords;
|
||||
double direction;
|
||||
} t_player;
|
||||
|
||||
typedef struct s_cub
|
||||
{
|
||||
void *mlx;
|
||||
void *win;
|
||||
void *sprites;
|
||||
void *img;
|
||||
char **map;
|
||||
t_player player;
|
||||
} t_cub;
|
||||
|
||||
|
||||
typedef struct s_dda
|
||||
{
|
||||
t_coord_f ray_dir;
|
||||
t_coord_f side_dist;
|
||||
t_coord_f delta_dist;
|
||||
t_step step;
|
||||
t_wall_side wall_side;
|
||||
bool wall_hit;
|
||||
} t_dda;
|
||||
|
||||
#endif
|
@ -1,18 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* constant.h :+: :+: :+: */
|
||||
/* vectwo.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/04 16:39:48 by adjoly #+# #+# */
|
||||
/* Updated: 2024/10/04 16:40:10 by adjoly ### ########.fr */
|
||||
/* Created: 2024/10/28 13:32:14 by adjoly #+# #+# */
|
||||
/* Updated: 2024/10/28 14:24:56 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef CONSTANT_H
|
||||
# define CONSTANT_H
|
||||
#ifndef VECTWO_H
|
||||
# define VECTWO_H
|
||||
|
||||
# define WHITE 0xFFFFFFFF
|
||||
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);
|
||||
#endif
|
Reference in New Issue
Block a user