Skip to content

Commit 4795c90

Browse files
committed
Add const keyword
1 parent 526a6e0 commit 4795c90

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+447
-558
lines changed

Makefile

-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ SRC_DIR = src
2121
OBJ_DIR = obj
2222

2323
SUB_DIRS = debug \
24-
display \
2524
event \
26-
math_utils \
2725
parsing \
2826
rendering \
2927
struct \

include/minirt.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: mboivin <mboivin@student.42.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2020/07/20 13:47:22 by mboivin #+# #+# */
9-
/* Updated: 2020/10/24 01:26:36 by mboivin ### ########.fr */
9+
/* Updated: 2021/07/11 16:20:32 by mboivin ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -26,10 +26,9 @@
2626
# include "minirt_env.h"
2727
# include "minirt_events.h"
2828
# include "minirt_render.h"
29-
# include "minirt_math_utils.h"
3029
# include "minirt_parsing.h"
31-
# include "minirt_save.h"
32-
# include "minirt_exit.h"
30+
# include "minirt_save_bmp.h"
31+
# include "minirt_utils.h"
3332
# include "minirt_debug.h"
3433

3534
#endif

include/minirt_env.h

+18-18
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: mboivin <mboivin@student.42.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2020/07/20 13:47:22 by mboivin #+# #+# */
9-
/* Updated: 2020/10/24 01:21:23 by mboivin ### ########.fr */
9+
/* Updated: 2021/07/11 16:23:09 by mboivin ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -144,42 +144,42 @@ typedef struct s_minirt
144144
** Global render settings
145145
*/
146146

147-
void create_resolution(t_res *res);
148-
void create_ambient(t_amb *ambient);
147+
void create_resolution(t_res *res);
148+
void create_ambient(t_amb *ambient);
149149

150150
/*
151151
** Camera
152152
*/
153153

154-
t_camera *malloc_cam(t_minirt *env);
155-
void append_camera(t_camera **cams, t_camera *new_cam);
156-
void delete_cameras(t_camera **cams);
154+
t_camera *malloc_cam(t_minirt *env);
155+
void append_camera(t_camera **cams, t_camera *new_cam);
156+
void delete_cameras(t_camera **cams);
157157

158158
/*
159159
** Point light
160160
*/
161161

162-
t_light *malloc_light(t_minirt *en);
163-
void append_light(t_light **lights, t_light *new_light);
164-
void delete_lights(t_light **lights);
162+
t_light *malloc_light(t_minirt *en);
163+
void append_light(t_light **lights, t_light *new_light);
164+
void delete_lights(t_light **lights);
165165

166166
/*
167167
** Image
168168
*/
169169

170-
t_image create_image(t_minirt *env);
171-
t_image *malloc_image(t_minirt *env);
172-
void destroy_image(void *mlx_ptr, t_image to_destroy);
173-
void free_image(void *mlx_ptr, t_image *to_free);
174-
void append_image(t_image **imgs, t_image *new_img);
175-
void delete_images(void *mlx_ptr, t_image **imgs);
176-
void create_circular_img_list(t_image *imgs);
170+
t_image create_image(t_minirt *env);
171+
t_image *malloc_image(t_minirt *env);
172+
void destroy_image(void *mlx_ptr, t_image to_destroy);
173+
void free_image(void *mlx_ptr, t_image *to_free);
174+
void append_image(t_image **imgs, t_image *new_img);
175+
void delete_images(void *mlx_ptr, t_image **imgs);
176+
void create_circular_img_list(t_image *imgs);
177177

178178
/*
179179
** miniRT controler
180180
*/
181181

182-
void init_minirt(t_minirt *env, char *title);
183-
void quit_minirt(t_minirt *env);
182+
void init_minirt(t_minirt *env, char *title);
183+
void quit_minirt(t_minirt *env);
184184

185185
#endif

include/minirt_math_utils.h

-22
This file was deleted.

include/minirt_objects.h

+39-39
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: mboivin <mboivin@student.42.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2020/07/23 00:58:03 by mboivin #+# #+# */
9-
/* Updated: 2020/10/18 13:43:03 by mboivin ### ########.fr */
9+
/* Updated: 2021/07/11 16:29:56 by mboivin ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -17,14 +17,14 @@
1717
** Object identifiers
1818
*/
1919

20-
typedef enum e_objid
20+
typedef enum e_obj_id
2121
{
2222
SPHERE,
2323
PLANE,
2424
SQUARE,
2525
CYLINDER,
2626
TRIANGLE
27-
} t_objid;
27+
} t_obj_id;
2828

2929
/*
3030
** Object list
@@ -36,7 +36,7 @@ typedef enum e_objid
3636

3737
typedef struct s_obj
3838
{
39-
t_objid id;
39+
t_obj_id id;
4040
void *data;
4141
struct s_obj *next;
4242
} t_obj;
@@ -49,12 +49,12 @@ typedef struct s_obj
4949
** vcolor: R,G,B colors in range [0.0,1.0]
5050
*/
5151

52-
typedef struct s_sphere
52+
typedef struct s_sphere
5353
{
54-
t_vec3 center;
55-
double radius;
56-
t_vcolor vcolor;
57-
} t_sphere;
54+
t_vec3 center;
55+
double radius;
56+
t_vcolor vcolor;
57+
} t_sphere;
5858

5959
/*
6060
** Plane
@@ -64,12 +64,12 @@ typedef struct s_sphere
6464
** vcolor: R,G,B colors in range [0.0,1.0]
6565
*/
6666

67-
typedef struct s_plane
67+
typedef struct s_plane
6868
{
69-
t_vec3 center;
70-
t_vec3 dir;
71-
t_vcolor vcolor;
72-
} t_plane;
69+
t_vec3 center;
70+
t_vec3 dir;
71+
t_vcolor vcolor;
72+
} t_plane;
7373

7474
/*
7575
** Square
@@ -80,13 +80,13 @@ typedef struct s_plane
8080
** vcolor: R,G,B colors in range [0.0,1.0]
8181
*/
8282

83-
typedef struct s_square
83+
typedef struct s_square
8484
{
85-
t_vec3 center;
86-
t_vec3 dir;
87-
double side;
88-
t_vcolor vcolor;
89-
} t_square;
85+
t_vec3 center;
86+
t_vec3 dir;
87+
double side;
88+
t_vcolor vcolor;
89+
} t_square;
9090

9191
/*
9292
** Cylinder
@@ -99,15 +99,15 @@ typedef struct s_square
9999
** vcolor: R,G,B colors in range [0.0,1.0]
100100
*/
101101

102-
typedef struct s_cyl
102+
typedef struct s_cyl
103103
{
104-
t_vec3 base1;
105-
t_vec3 base2;
106-
t_vec3 dir;
107-
double radius;
108-
double height;
109-
t_vcolor vcolor;
110-
} t_cyl;
104+
t_vec3 base1;
105+
t_vec3 base2;
106+
t_vec3 dir;
107+
double radius;
108+
double height;
109+
t_vcolor vcolor;
110+
} t_cyl;
111111

112112
/*
113113
** Cylinder
@@ -118,17 +118,17 @@ typedef struct s_cyl
118118
** vcolor: R,G,B colors in range [0.0,1.0]
119119
*/
120120

121-
typedef struct s_tri
121+
typedef struct s_tri
122122
{
123-
t_vec3 vertex1;
124-
t_vec3 vertex2;
125-
t_vec3 vertex3;
126-
t_vec3 normal;
127-
t_vcolor vcolor;
128-
} t_tri;
129-
130-
t_obj *create_obj(void *shape_data, t_objid shape_id);
131-
void append_obj(t_obj **objs, t_obj *new_obj);
132-
void delete_objs(t_obj **objs);
123+
t_vec3 vertex1;
124+
t_vec3 vertex2;
125+
t_vec3 vertex3;
126+
t_vec3 normal;
127+
t_vcolor vcolor;
128+
} t_tri;
129+
130+
t_obj *create_obj(void *shape_data, t_obj_id shape_id);
131+
void append_obj(t_obj **objs, t_obj *new_obj);
132+
void delete_objs(t_obj **objs);
133133

134134
#endif

include/minirt_parsing.h

+24-24
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: mboivin <mboivin@student.42.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2020/07/22 15:00:17 by mboivin #+# #+# */
9-
/* Updated: 2020/10/18 13:47:38 by mboivin ### ########.fr */
9+
/* Updated: 2021/07/11 16:30:27 by mboivin ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -26,48 +26,48 @@ typedef struct s_parsers
2626
t_pars_func func;
2727
} t_parsers;
2828

29-
void parse_scene(t_minirt *env, const char *filepath);
29+
void parse_scene(t_minirt *env, const char *filename);
3030

3131
/*
3232
** Global render settings
3333
*/
3434

35-
void get_resolution(t_minirt *env, char **input);
36-
void get_ambient(t_minirt *env, char **input);
35+
void get_resolution(t_minirt *env, char **input);
36+
void get_ambient(t_minirt *env, char **input);
3737

3838
/*
3939
** Camera and light
4040
*/
4141

42-
void get_camera(t_minirt *env, char **input);
43-
void get_light(t_minirt *env, char **input);
42+
void get_camera(t_minirt *env, char **input);
43+
void get_light(t_minirt *env, char **input);
4444

4545
/*
4646
** Objects
4747
*/
4848

49-
void add_obj_to_render(t_minirt *env, void *to_add, t_objid obj_id);
50-
void get_sphere(t_minirt *env, char **input);
51-
void get_plane(t_minirt *env, char **input);
52-
void get_square(t_minirt *env, char **input);
53-
void get_cylinder(t_minirt *env, char **input);
54-
void get_triangle(t_minirt *env, char **input);
49+
void add_obj_to_render(t_minirt *env, void *to_add, t_obj_id obj_id);
50+
void get_sphere(t_minirt *env, char **input);
51+
void get_plane(t_minirt *env, char **input);
52+
void get_square(t_minirt *env, char **input);
53+
void get_cylinder(t_minirt *env, char **input);
54+
void get_triangle(t_minirt *env, char **input);
5555

5656
/*
5757
** Parsing utils
5858
*/
5959

60-
int get_integer(t_minirt *env, char **input);
61-
double get_double(t_minirt *env, char **input);
62-
t_vcolor get_color(t_minirt *env, char **input);
63-
t_vec3 get_vec3(t_minirt *env, char **input);
64-
bool ft_vec3_range(t_vec3 vec, double start, double end);
65-
void skip_blank(char **s);
66-
int skip_separator(char **s, int sep);
67-
void skip_digits(char **s);
68-
void skip_double(t_minirt *env, char **s);
69-
void check_max_display(t_minirt *env);
70-
void check_null_vector(t_vec3 *to_check, t_vec3 default_vec);
71-
void check_null_light(t_vcolor *vcolor, double *ratio);
60+
int get_integer(t_minirt *env, char **input);
61+
double get_double(t_minirt *env, char **input);
62+
t_vcolor get_color(t_minirt *env, char **input);
63+
t_vec3 get_vec3(t_minirt *env, char **input);
64+
bool ft_vec3_range(t_vec3 vec, double start, double end);
65+
void skip_blank(char **s);
66+
int skip_separator(char **s, int sep);
67+
void skip_digits(char **s);
68+
void skip_double(t_minirt *env, char **s);
69+
void check_max_display(t_minirt *env);
70+
void check_null_vector(t_vec3 *to_check, t_vec3 default_vec);
71+
void check_null_light(t_vcolor *vcolor, double *ratio);
7272

7373
#endif

include/minirt_render.h

+12-4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
/* By: mboivin <mboivin@student.42.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2020/07/21 21:32:25 by mboivin #+# #+# */
9-
/* Updated: 2020/10/18 13:50:38 by mboivin ### ########.fr */
9+
/* Updated: 2021/07/11 16:31:19 by mboivin ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

1313
#ifndef MINIRT_RENDER_H
1414
# define MINIRT_RENDER_H
1515

16-
void render(t_minirt *env, bool to_bmp);
16+
void render(t_minirt *env, bool save_to_bmp);
1717

1818
/*
1919
** Set ray
@@ -42,8 +42,16 @@ t_vec3 get_quad_coef(t_vec3 dir, t_vec3 oc, double radius);
4242
bool get_quad_roots(double *root1, double *root2, t_vec3 quad_coef);
4343
t_vec3 get_hit_point(t_vec3 origin, double t, t_vec3 dir);
4444
void get_obj_color(t_obj *hit_obj, t_ray *ray);
45-
double get_specular(
46-
t_ray *ray, t_light *light, t_vec3 light_dir, double angle);
45+
double get_specular(t_ray *ray, t_light *light, t_vec3 light_dir, double angle);
46+
47+
/*
48+
** Get normal
49+
*/
50+
51+
void get_obj_normal(t_obj *hit_obj, t_ray *ray, t_vec3 hit_p);
52+
t_vec3 get_sphere_normal(t_sphere *sphere, t_vec3 hit_p);
53+
t_vec3 get_triangle_normal(t_tri *tri);
54+
t_vec3 get_cylinder_normal(t_cyl *cylinder, t_vec3 hit_p);
4755

4856
/*
4957
** Put pixel to image

0 commit comments

Comments
 (0)