Skip to content

Commit 27d0c0d

Browse files
author
Loic Mohin
committed
Merge branch 'master' of github.com:TheTerror-coder/miniRT
2 parents 3efd866 + 62d8bc6 commit 27d0c0d

File tree

9 files changed

+109
-75
lines changed

9 files changed

+109
-75
lines changed

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# By: TheTerror <jfaye@student.42lyon.fr> +#+ +:+ +#+ #
77
# +#+#+#+#+#+ +#+ #
88
# Created: 2023/08/17 16:29:00 by TheTerror #+# #+# #
9-
# Updated: 2024/02/12 18:03:46 by TheTerror ### ########lyon.fr #
9+
# Updated: 2024/02/13 14:03:02 by TheTerror ### ########lyon.fr #
1010
# #
1111
# **************************************************************************** #
1212

@@ -35,6 +35,7 @@ MLX_OBJ_OPTIONS = -I/usr/include -Imlx_linux -O3
3535
MLX_LINK_OPTIONS = -Lmlx_linux -lmlx_Linux -L/usr/lib -Imlx_linux -lXext -lX11 -lm -lz
3636
RM = rm -rf
3737

38+
3839
SRC_GRAPHIC_TOOLS = $(addprefix $(GRAPHIC_TOOLS_PATH), events.c mlx_utils.c)
3940
SRC_INTERS = $(addprefix $(INTERS_PATH), ray_sphere.c ray_plane.c ray_cylinder.c ray_cylinder_utils.c cy_extremities.c)
4041
SRC_MATHTOOLS = $(addprefix $(MATHTOOLS_PATH), converts.c vectors.c subtractions.c products.c \
@@ -69,6 +70,11 @@ mlx :
6970
$(NAME) : $(OBJ) $(INCLUDE)
7071
$(CC) $(CFLAGS) $(OBJ) $(LIBFT_LIB) $(MLX_LINK_OPTIONS) -o $@
7172

73+
norm :
74+
files=$$(ls --hide=mlx_linux); norminette $$files
75+
norminette :
76+
files=$$(ls --hide=mlx_linux); norminette $$files
77+
7278
mk_objdir :
7379
@mkdir -p $(OBJ_PATH)
7480

inters/cy_extremities.c

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,20 @@
66
/* By: TheTerror <jfaye@student.42lyon.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/02/04 14:38:21 by TheTerror #+# #+# */
9-
/* Updated: 2024/02/11 13:47:28 by TheTerror ### ########lyon.fr */
9+
/* Updated: 2024/02/13 14:28:03 by TheTerror ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

1313
#include "inters.h"
1414

15-
typedef struct s_consts
16-
{
17-
t_coord pt_ph;
18-
double t;
19-
double norm_phpi;
20-
double c1;
21-
double c2;
22-
double c3;
23-
double c4;
24-
double c5;
25-
double c6;
26-
int x;
27-
} t_consts;
28-
29-
t_bool inter_extremitie(t_ray *ray, t_cy *cy, t_vec *axis_dir, t_consts *vars);
30-
t_bool compute_pt_ph(t_cy *cy, t_vec *axis_dir, t_consts *vars);
31-
t_bool compute_lenght_t(t_ray *ray, t_cy *cy, t_consts *vars);
32-
t_bool compute_norm_vec_phpi(t_ray *ray, t_consts *vars);
15+
t_bool inter_extremitie(t_ray *ray, t_cy *cy, t_vec *axis_dir, t_cyvars *vars);
16+
t_bool compute_pt_ph(t_cy *cy, t_vec *axis_dir, t_cyvars *vars);
17+
t_bool compute_lenght_t(t_ray *ray, t_cy *cy, t_cyvars *vars);
18+
t_bool compute_norm_vec_phpi(t_ray *ray, t_cyvars *vars);
3319

3420
t_bool ray_inter_cy_extremities(t_ray *ray, t_cy *cy, int x)
3521
{
36-
t_consts vars;
22+
t_cyvars vars;
3723
t_vec axis_dir;
3824
int fdbk;
3925

@@ -46,7 +32,7 @@ t_bool ray_inter_cy_extremities(t_ray *ray, t_cy *cy, int x)
4632
return (fdbk);
4733
}
4834

49-
t_bool inter_extremitie(t_ray *ray, t_cy *cy, t_vec *axis_dir, t_consts *vars)
35+
t_bool inter_extremitie(t_ray *ray, t_cy *cy, t_vec *axis_dir, t_cyvars *vars)
5036
{
5137
compute_pt_ph(cy, axis_dir, vars);
5238
compute_lenght_t(ray, cy, vars);
@@ -62,15 +48,15 @@ t_bool inter_extremitie(t_ray *ray, t_cy *cy, t_vec *axis_dir, t_consts *vars)
6248
return (__FALSE);
6349
}
6450

65-
t_bool compute_pt_ph(t_cy *cy, t_vec *axis_dir, t_consts *vars)
51+
t_bool compute_pt_ph(t_cy *cy, t_vec *axis_dir, t_cyvars *vars)
6652
{
6753
vars->pt_ph.x = cy->o.x + (cy->h / 2) * axis_dir->x;
6854
vars->pt_ph.y = cy->o.y + (cy->h / 2) * axis_dir->y;
6955
vars->pt_ph.z = cy->o.z + (cy->h / 2) * axis_dir->z;
7056
return (__TRUE);
7157
}
7258

73-
t_bool compute_lenght_t(t_ray *ray, t_cy *cy, t_consts *vars)
59+
t_bool compute_lenght_t(t_ray *ray, t_cy *cy, t_cyvars *vars)
7460
{
7561
double num;
7662
double denom;
@@ -92,7 +78,7 @@ t_bool compute_lenght_t(t_ray *ray, t_cy *cy, t_consts *vars)
9278
return (__TRUE);
9379
}
9480

95-
t_bool compute_norm_vec_phpi(t_ray *ray, t_consts *vars)
81+
t_bool compute_norm_vec_phpi(t_ray *ray, t_cyvars *vars)
9682
{
9783
vars->norm_phpi = sqrt(__sq(vars->t * ray->dir.x + vars->c1) \
9884
+ __sq(vars->t * ray->dir.y + vars->c2) + __sq(vars->t \

inters/inters.h

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: TheTerror <jfaye@student.42lyon.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/08/23 20:21:23 by TheTerror #+# #+# */
9-
/* Updated: 2024/02/11 14:41:25 by TheTerror ### ########lyon.fr */
9+
/* Updated: 2024/02/13 14:27:12 by TheTerror ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -15,6 +15,45 @@
1515

1616
# include "../minirt.h"
1717

18+
/*
19+
cy_extremities.c struct tools
20+
*/
21+
typedef struct s_ray_cy_extremities_variables
22+
{
23+
t_coord pt_ph;
24+
double t;
25+
double norm_phpi;
26+
double c1;
27+
double c2;
28+
double c3;
29+
double c4;
30+
double c5;
31+
double c6;
32+
int x;
33+
} t_cyvars;
34+
35+
/*
36+
ray_sphere.c struct variables
37+
*/
38+
typedef struct s_ray_sphere_vars
39+
{
40+
double a;
41+
double b;
42+
double c;
43+
double delta;
44+
double s1;
45+
double s2;
46+
} t_spvars;
47+
48+
typedef struct s_ray_plane_variables
49+
{
50+
t_vec p_ro;
51+
t_coord ray_o;
52+
double num;
53+
double denom;
54+
double length;
55+
} t_plvars;
56+
1857
t_bool ray_inter_sp(t_ray *ray, t_sp *sp, int x);
1958
t_bool ray_inter_pl(t_ray *ray, t_pl *pl, int x);
2059
t_bool assess_color(t_ray *ray, double len_found);

inters/ray_plane.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,17 @@
66
/* By: TheTerror <jfaye@student.42lyon.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/08/23 21:27:05 by TheTerror #+# #+# */
9-
/* Updated: 2024/02/11 14:17:38 by TheTerror ### ########lyon.fr */
9+
/* Updated: 2024/02/13 14:29:12 by TheTerror ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

1313
#include "inters.h"
14-
#include "limits.h"
1514

16-
typedef struct s_localvars
17-
{
18-
t_vec p_ro;
19-
t_coord ray_o;
20-
double num;
21-
double denom;
22-
double length;
23-
} t_lvars;
24-
25-
t_bool ray_inter_pl_op(t_ray *ray, t_pl *pl, t_lvars *vars, int x);
15+
t_bool ray_inter_pl_op(t_ray *ray, t_pl *pl, t_plvars *vars, int x);
2616

2717
/*
28-
t_vec p_ro; // vector between the given point of the plane and the ray origin
18+
t_vec p_ro; // vector between the given point of the plane and
19+
the ray origin
2920
t_coord ray_o; // ray origin
3021
double num; // numerator
3122
double denom; // denominator
@@ -34,7 +25,7 @@ t_bool ray_inter_pl_op(t_ray *ray, t_pl *pl, t_lvars *vars, int x);
3425

3526
t_bool ray_inter_pl(t_ray *ray, t_pl *pl, int x)
3627
{
37-
t_lvars vars;
28+
t_plvars vars;
3829

3930
vars.ray_o.x = ray->o.x;
4031
vars.ray_o.y = ray->o.y;
@@ -60,7 +51,7 @@ t_bool ray_inter_pl(t_ray *ray, t_pl *pl, int x)
6051
return (ray_inter_pl_op(ray, pl, &vars, x));
6152
}
6253

63-
t_bool ray_inter_pl_op(t_ray *ray, t_pl *pl, t_lvars *vars, int x)
54+
t_bool ray_inter_pl_op(t_ray *ray, t_pl *pl, t_plvars *vars, int x)
6455
{
6556
vars->length = vars->num / vars->denom;
6657
if (assess_color(ray, vars->length))

inters/ray_sphere.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,12 @@
66
/* By: TheTerror <jfaye@student.42lyon.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/08/23 20:19:01 by TheTerror #+# #+# */
9-
/* Updated: 2024/02/11 14:56:56 by TheTerror ### ########lyon.fr */
9+
/* Updated: 2024/02/13 14:28:29 by TheTerror ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

1313
#include "inters.h"
1414

15-
typedef struct s_localvars
16-
{
17-
double a;
18-
double b;
19-
double c;
20-
double delta;
21-
double s1;
22-
double s2;
23-
} t_lvars;
24-
2515
double ray_inter_sp_op(t_ray *ray, t_sp *sp);
2616

2717
t_bool ray_inter_sp(t_ray *ray, t_sp *sp, int x)
@@ -62,7 +52,7 @@ t_bool assess_color(t_ray *ray, double len_found)
6252

6353
double ray_inter_sp_op(t_ray *ray, t_sp *sp)
6454
{
65-
t_lvars vars;
55+
t_spvars vars;
6656

6757
vars.a = __sq(ray->dir.x) + __sq(ray->dir.y) + __sq(ray->dir.z);
6858
vars.b = 2.00 * ray->dir.x * (ray->o.x - sp->o.x) + \

libft/libft.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: TheTerror <jfaye@student.42lyon.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2022/12/05 13:35:39 by TheTerror #+# #+# */
9-
/* Updated: 2024/02/12 18:00:50 by TheTerror ### ########lyon.fr */
9+
/* Updated: 2024/02/13 14:12:19 by TheTerror ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -250,7 +250,8 @@ void ft_putchar_fd(char c, int fd);
250250
** s: The string to output.
251251
** fd: The file descriptor on which to write.
252252
** DESCRIPTION
253-
** Outputs the string ’s’ to the given file descriptor, followed by a newline.
253+
** Outputs the string ’s’ to the given file descriptor,
254+
** followed by a newline.
254255
** RETURN VALUE
255256
** None
256257
*/

libft/various/ft_atod.c

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,19 @@
66
/* By: TheTerror <jfaye@student.42lyon.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/08/19 21:19:02 by TheTerror #+# #+# */
9-
/* Updated: 2024/02/12 18:01:43 by TheTerror ### ########lyon.fr */
9+
/* Updated: 2024/02/13 14:34:54 by TheTerror ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

13-
#include "../libft.h"
13+
#include "local_tools.h"
1414

15-
typedef struct s_tools
16-
{
17-
unsigned int i;
18-
int sign;
19-
double dec;
20-
double val;
21-
double exp_sign;
22-
double n;
23-
} t_tools;
24-
25-
t_bool init_skip_optional(t_tools *x, const char *nptr);
26-
t_bool decimal_sequence(t_tools *x, const char *nptr);
27-
t_bool optional_exponent(t_tools *x, const char *nptr);
15+
t_bool init_skip_optional(t_atod_vars *x, const char *nptr);
16+
t_bool decimal_sequence(t_atod_vars *x, const char *nptr);
17+
t_bool optional_exponent(t_atod_vars *x, const char *nptr);
2818

2919
double ft_atod(const char *nptr)
3020
{
31-
t_tools x;
21+
t_atod_vars x;
3222

3323
if (init_skip_optional(&x, nptr))
3424
return (x.val);
@@ -37,7 +27,7 @@ double ft_atod(const char *nptr)
3727
return (x.val * x.sign);
3828
}
3929

40-
t_bool init_skip_optional(t_tools *x, const char *nptr)
30+
t_bool init_skip_optional(t_atod_vars *x, const char *nptr)
4131
{
4232
x->i = 0;
4333
x->val = 0;
@@ -62,7 +52,7 @@ t_bool init_skip_optional(t_tools *x, const char *nptr)
6252
return (__FALSE);
6353
}
6454

65-
t_bool decimal_sequence(t_tools *x, const char *nptr)
55+
t_bool decimal_sequence(t_atod_vars *x, const char *nptr)
6656
{
6757
while (nptr[x->i] >= '0' && nptr[x->i] <= '9')
6858
{
@@ -86,7 +76,7 @@ t_bool decimal_sequence(t_tools *x, const char *nptr)
8676
return (__FALSE);
8777
}
8878

89-
t_bool optional_exponent(t_tools *x, const char *nptr)
79+
t_bool optional_exponent(t_atod_vars *x, const char *nptr)
9080
{
9181
size_t power;
9282

libft/various/local_tools.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* local_tools.h :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: TheTerror <jfaye@student.42lyon.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2024/02/13 14:06:01 by TheTerror #+# #+# */
9+
/* Updated: 2024/02/13 14:34:21 by TheTerror ### ########lyon.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#ifndef LOCAL_TOOLS_H
14+
# define LOCAL_TOOLS_H
15+
16+
# include "../libft.h"
17+
18+
/*
19+
ft_atod() struct including all util variables
20+
*/
21+
typedef struct s_atod_variables
22+
{
23+
unsigned int i;
24+
int sign;
25+
double dec;
26+
double val;
27+
double exp_sign;
28+
double n;
29+
} t_atod_vars;
30+
31+
#endif

scenes/exemple.rt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
A 0.2 255,0255,0255
22

3-
C 0,0,0 0,0,-1 50
3+
C 0,0,0 0,0,-1 180
44

55
L 5,0,-50 0.8 0,0,255
66

0 commit comments

Comments
 (0)