DEBOGAGE
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/13 20:02:36 by yantoine #+# #+# */
|
||||
/* Updated: 2025/02/17 19:53:54 by yantoine ### ########.fr */
|
||||
/* Updated: 2025/02/17 21:55:55 by yantoine ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -14,13 +14,15 @@
|
||||
# define MINIRT_H
|
||||
|
||||
# include <math.h>
|
||||
#include "mlx.h"
|
||||
# include <stdbool.h>
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
# include <fcntl.h>
|
||||
# include "get_next_line.h"
|
||||
# include "libft.h"
|
||||
# include "float.h"
|
||||
# include "mlx.h"
|
||||
|
||||
// ----- Taille ecran ----
|
||||
# define WIDTH 320
|
||||
@@ -34,83 +36,6 @@
|
||||
# define MAX_AMBIENT 1
|
||||
# define MAX_CAMERA 1
|
||||
|
||||
// ----- Minilibx
|
||||
typedef struct s_app
|
||||
{
|
||||
void *mlx;
|
||||
void *win;
|
||||
void *img;
|
||||
int *pixels;
|
||||
int bpp;
|
||||
int size_line;
|
||||
int endian;
|
||||
int win_width;
|
||||
int win_height;
|
||||
int key_w;
|
||||
int key_s;
|
||||
int key_a;
|
||||
int key_d;
|
||||
int key_left;
|
||||
int key_right;
|
||||
int key_up;
|
||||
int key_down;
|
||||
float move_speed;
|
||||
float rot_speed;
|
||||
float mouse_sens;
|
||||
t_vec3 cam_pos;
|
||||
t_vec3 cam_dir;
|
||||
t_vec3 right;
|
||||
t_vec3 cam_up;
|
||||
float fov;
|
||||
float yaw;
|
||||
float pitch;
|
||||
} t_app;
|
||||
|
||||
|
||||
// ----- Calcul
|
||||
|
||||
typedef struct s_calc
|
||||
{
|
||||
t_vec3 oc;
|
||||
float a;
|
||||
float b;
|
||||
float c;
|
||||
float disc;
|
||||
float sqrtDisc;
|
||||
float t0;
|
||||
float t1;
|
||||
float t;
|
||||
t_vec3 hitPoint;
|
||||
t_vec3 d;
|
||||
t_vec3 v;
|
||||
float d_dot_v;
|
||||
float oc_dot_v;
|
||||
t_vec3 d_perp;
|
||||
t_vec3 oc_perp;
|
||||
float t_side;
|
||||
float y;
|
||||
float t_cap;
|
||||
float t_bot;
|
||||
float t_top;
|
||||
t_vec3 p;
|
||||
t_vec3 cp;
|
||||
float dist;
|
||||
float t_final;
|
||||
float proj;
|
||||
t_vec3 n;
|
||||
float ndc_x;
|
||||
float ndc_y;
|
||||
float aspect;
|
||||
float scale;
|
||||
float screen_x;
|
||||
float screen_y;
|
||||
t_vec3 ray_dir;
|
||||
t_vec3 color;
|
||||
unsigned char r;
|
||||
unsigned char g;
|
||||
unsigned char b;
|
||||
} t_calc;
|
||||
|
||||
// ----- Espace 3d
|
||||
typedef struct s_vec3
|
||||
{
|
||||
@@ -159,8 +84,8 @@ typedef struct s_light
|
||||
|
||||
typedef struct s_ambient
|
||||
{
|
||||
float ambient_ratio;
|
||||
t_vec3 ambient_color;
|
||||
float ratio;
|
||||
t_vec3 color;
|
||||
} t_ambient;
|
||||
|
||||
typedef struct s_camera
|
||||
@@ -183,13 +108,88 @@ typedef struct s_scene
|
||||
int numSpheres;
|
||||
int numPlanes;
|
||||
int numCylinders;
|
||||
int numCamera;
|
||||
int numLights;
|
||||
int numAmbient;
|
||||
const char *line_if_exit;
|
||||
const int fd_if_exit;
|
||||
const char **token_if_exit;
|
||||
char *line_if_exit;
|
||||
char **token_if_exit;
|
||||
int fd_if_exit;
|
||||
} t_scene;
|
||||
|
||||
// ----- Minilibx
|
||||
typedef struct s_app
|
||||
{
|
||||
void *mlx;
|
||||
void *win;
|
||||
void *img;
|
||||
int *pixels;
|
||||
int bpp;
|
||||
int size_line;
|
||||
int endian;
|
||||
int win_width;
|
||||
int win_height;
|
||||
int key_w;
|
||||
int key_s;
|
||||
int key_a;
|
||||
int key_d;
|
||||
int key_left;
|
||||
int key_right;
|
||||
int key_up;
|
||||
int key_down;
|
||||
float move_speed;
|
||||
float rot_speed;
|
||||
float mouse_sens;
|
||||
t_vec3 cam_pos;
|
||||
t_vec3 cam_dir;
|
||||
t_vec3 right;
|
||||
t_vec3 cam_up;
|
||||
float fov;
|
||||
float yaw;
|
||||
float pitch;
|
||||
} t_app;
|
||||
|
||||
|
||||
// ----- Calcul
|
||||
typedef struct s_calc
|
||||
{
|
||||
t_vec3 oc;
|
||||
float a;
|
||||
float b;
|
||||
float c;
|
||||
float disc;
|
||||
float sqrtDisc;
|
||||
float t0;
|
||||
float t1;
|
||||
float t;
|
||||
t_vec3 hitPoint;
|
||||
t_vec3 d;
|
||||
t_vec3 v;
|
||||
float d_dot_v;
|
||||
float oc_dot_v;
|
||||
t_vec3 d_perp;
|
||||
t_vec3 oc_perp;
|
||||
float t_side;
|
||||
float y;
|
||||
float t_cap;
|
||||
float t_bot;
|
||||
float t_top;
|
||||
t_vec3 p;
|
||||
t_vec3 cp;
|
||||
float dist;
|
||||
float t_final;
|
||||
float proj;
|
||||
t_vec3 n;
|
||||
float ndc_x;
|
||||
float ndc_y;
|
||||
float aspect;
|
||||
float scale;
|
||||
float screen_x;
|
||||
float screen_y;
|
||||
t_ray ray;
|
||||
t_vec3 ray_dir;
|
||||
t_vec3 color;
|
||||
} t_calc;
|
||||
|
||||
// Calcul de vecteur
|
||||
t_vec3 vec3_add(t_vec3 a, t_vec3 b);
|
||||
t_vec3 vec3_sub(t_vec3 a, t_vec3 b);
|
||||
@@ -203,29 +203,32 @@ t_vec3 vec3_mul(t_vec3 a, t_vec3 b);
|
||||
// Config de scene
|
||||
t_scene create_scene(void);
|
||||
t_scene load_config(const char *filename);
|
||||
t_scene parsing_ambiant(const char *line, t_scene scene);
|
||||
t_scene parsing_camera(const char *line, t_scene scene);
|
||||
t_scene parsing_light(const char *line, t_scene scene);
|
||||
t_scene parsing_sphere(const char *line, t_scene scene);
|
||||
t_scene parsing_plane(const char *line, t_scene scene);
|
||||
t_scene parsing_cylindre(const char *line, t_scene scene);
|
||||
t_scene parsing_ambiant(t_scene scene);
|
||||
t_scene parsing_camera(t_scene scene);
|
||||
t_scene parsing_light(t_scene scene);
|
||||
t_scene parsing_sphere(t_scene scene);
|
||||
t_scene parsing_plane(t_scene scene);
|
||||
t_scene parsing_cylindre(t_scene scene);
|
||||
t_vec3 parse_color(const char *token, t_scene scene);
|
||||
t_vec3 parse_vector(const char *token, t_scene scene);
|
||||
t_vec3 parse_vector_normalize(const char *token, t_scene scene);
|
||||
|
||||
|
||||
// Parsing utils
|
||||
inline char **get_tokens_secure(t_scene scene, const int numObject, const int numObjectMax, const int supposed_nb_token);
|
||||
char **get_tokens_secure(t_scene scene, const int numObject, const int numObjectMax, const int supposed_nb_token);
|
||||
|
||||
// Check
|
||||
inline int check_tokens(char **tokens, const int to_test, int expected);
|
||||
inline void check_if_max(t_scene scene, const int to_test, const int max);
|
||||
int check_tokens(char **tokens, int expected);
|
||||
void check_if_max(t_scene scene, const int to_test, const int max);
|
||||
|
||||
// Intersection
|
||||
float intersectCylinder(Ray ray, Cylinder cy, t_vec3 *hitNormal);
|
||||
float intersectPlane(Ray ray, Plane p, t_vec3 *hitNormal);
|
||||
float intersectSphere(Ray ray, Sphere s, t_vec3 *hitNormal);
|
||||
bool isInShadow(t_vec3 hitPoint, t_vec3 lightPos);
|
||||
float intersectCylinder(t_ray ray, t_cylinder cy, t_vec3 *hitNormal);
|
||||
float intersectPlane(t_ray ray, t_plane p, t_vec3 *hitNormal);
|
||||
float intersectSphere(t_ray ray, t_sphere s, t_vec3 *hitNormal);
|
||||
bool isInShadow(t_vec3 hitPoint, t_vec3 lightPos, t_scene scene);
|
||||
bool intersectObjects(t_ray ray, float *tMin, t_vec3 *hitNormal, t_vec3 *objColor, t_scene scene);
|
||||
t_vec3 calcLighting(t_vec3 hitPoint, t_vec3 hitNormal, t_vec3 objColor, t_scene scene);
|
||||
t_vec3 trace(t_ray ray, t_scene scene);
|
||||
|
||||
// Peripherique
|
||||
int key_press(int keycode, t_app *app);
|
||||
@@ -234,6 +237,12 @@ int mouse_move(int x, int y, t_app *app);
|
||||
|
||||
// Render
|
||||
void update_camera(t_app *app);
|
||||
void render_scene(t_app *app);
|
||||
int update_frame(t_app *app);
|
||||
void render_scene(t_app *app, t_scene scene);
|
||||
int update_frame(t_app *app, t_scene scene);
|
||||
|
||||
// Array
|
||||
int ft_arraylen(char **array);
|
||||
void ft_free_array(char **array);
|
||||
// Conversion
|
||||
float ft_atof(char *str);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user