Skip to content

Commit e035feb

Browse files
🧹 cleanup: Merge with parser
2 parents 6251a3f + fe71f11 commit e035feb

21 files changed

Lines changed: 445 additions & 72 deletions

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ SRCS = $(addprefix $(SRCS_PATH), \
125125
11-Parser/Parse_plane_utils.c \
126126
11-Parser/Parse_sphere.c \
127127
11-Parser/Parse_cylinder.c \
128+
11-Parser/Parse_pattern.c \
129+
11-Parser/Parse_pattern_utils.c \
128130
11-Parser/Parser_utils.c \
129131
11-Parser/Parser.c \
130132
11-Parser/Validations.c \

includes/Canvas.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: cnatanae <cnatanae@student.42sp.org.br> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/11/11 14:43:44 by cnatanae #+# #+# */
9-
/* Updated: 2025/02/08 14:34:18 by cnatanae ### ########.fr */
9+
/* Updated: 2025/02/08 16:25:49 by cnatanae ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

includes/Light_and_Shading.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
/* ::: :::::::: */
44
/* Light_and_Shading.h :+: :+: :+: */
55
/* +:+ +:+ +:+ */
6-
/* By: cnatanae <cnatanae@student.42sp.org.br> +#+ +:+ +#+ */
6+
/* By: tmalheir <tmalheir@student.42.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/12/06 13:52:08 by tmalheir #+# #+# */
9-
/* Updated: 2025/01/22 14:15:24 by cnatanae ### ########.fr */
9+
/* Updated: 2025/02/07 15:50:10 by tmalheir ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

includes/Parser.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: cnatanae <cnatanae@student.42sp.org.br> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2025/01/22 14:57:54 by tmalheir #+# #+# */
9-
/* Updated: 2025/02/07 13:25:42 by cnatanae ### ########.fr */
9+
/* Updated: 2025/02/08 16:25:57 by cnatanae ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -58,6 +58,13 @@ void calculate_rotation_angles(double *norm, double *x, double *z);
5858
bool parse_cylinder(char *line, t_world *world);
5959
void set_cylinder(t_obj **cl, char **info);
6060

61+
bool parse_pattern(char *line, t_world *world);
62+
bool check_pattern(char *str1, char *str2);
63+
bool check_obj_pattern(char *str, t_world *world, t_obj *obj);
64+
bool parse_transformations(char *str1, char *str2, char *str3);
65+
void insert_into_pattern_list(t_pat_lst **lst, t_pat_lst *pat);
66+
t_matrix get_transf(double *scl, double *rot, double *trns);
67+
6168
bool parse_color(char *str);
6269
double *normalize_rgb_to_double(char *str);
6370
bool is_int(char *str);
@@ -66,6 +73,4 @@ bool in_range_int(char *str);
6673
bool parse_pos(char *str);
6774
double *pos_to_double(char *str);
6875

69-
bool parse_sphere(char *line, t_world *world);
70-
7176
#endif

includes/Scenes.h

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: cnatanae <cnatanae@student.42sp.org.br> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2025/01/02 08:15:09 by cnatanae #+# #+# */
9-
/* Updated: 2025/02/07 17:24:40 by cnatanae ### ########.fr */
9+
/* Updated: 2025/02/08 16:26:11 by cnatanae ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -43,18 +43,26 @@ typedef struct s_lights
4343
struct s_lights *prev;
4444
} t_lights;
4545

46+
typedef struct s_pattern_list
47+
{
48+
t_pattern pattern;
49+
struct s_pattern_list *next;
50+
struct s_pattern_list *prev;
51+
} t_pat_lst;
52+
4653
typedef struct s_scene
4754
{
48-
t_colors ambient;
49-
int has_ambient;
50-
double *camera_from;
51-
double *camera_to;
52-
int has_camera;
53-
t_colors light;
54-
double *light_pos;
55-
int has_light;
56-
bool save_img;
57-
char *file_name;
55+
t_colors ambient;
56+
int has_ambient;
57+
double *camera_from;
58+
double *camera_to;
59+
int has_camera;
60+
t_colors light;
61+
double *light_pos;
62+
int has_light;
63+
bool save_img;
64+
char *file_name;
65+
t_pat_lst *pat_lst;
5866
} t_scene;
5967

6068
typedef struct s_camera

main_for_tests.c

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#include "MiniRT.h"
2+
3+
int main(int argc, char **argv)
4+
{
5+
t_world *world;
6+
t_paint paint;
7+
t_camera cam;
8+
mlx_t *mlx;
9+
mlx_image_t *image;
10+
11+
world = parser(argc, argv);
12+
13+
t_pool_set *set = get_pool();
14+
15+
// sp1
16+
t_obj *sp1= (t_obj *)alloc_pool(sizeof(t_obj), set->the_pool);
17+
init_shape(SPHERE, &sp1->shape);
18+
sp1->shape->material.color = create_color(0.3, 0, 1);
19+
insert_into_obj_list(&world->obj_lst, sp1);
20+
21+
// sp2
22+
t_obj *sp2= (t_obj *)alloc_pool(sizeof(t_obj), set->the_pool);
23+
init_shape(SPHERE, &sp2->shape);
24+
sp2->shape->material.color = create_color(0.3, 0, 1);
25+
insert_into_obj_list(&world->obj_lst, sp2);
26+
27+
// sp3
28+
t_obj *sp3= (t_obj *)alloc_pool(sizeof(t_obj), set->the_pool);
29+
init_shape(SPHERE, &sp3->shape);
30+
sp3->shape->material.color = create_color(0.3, 0, 1);
31+
sp3->shape->material.pattern = stripe_pattern(create_color(1, 1, 1), create_color(1, 0, 0));
32+
set_pattern_transf(&sp3->shape->material.pattern, scale(.1, .1, .1));
33+
insert_into_obj_list(&world->obj_lst, sp3);
34+
35+
// pl1
36+
t_obj *pl1= (t_obj *)alloc_pool(sizeof(t_obj), set->the_pool);
37+
init_shape(PLANE, &pl1->shape);
38+
pl1->shape->material.color = create_color(0.3, 0, 1);
39+
insert_into_obj_list(&world->obj_lst, pl1);
40+
41+
// pl2
42+
t_obj *pl2= (t_obj *)alloc_pool(sizeof(t_obj), set->the_pool);
43+
init_shape(PLANE, &pl2->shape);
44+
pl2->shape->material.color = create_color(0.3, 0, 1);
45+
insert_into_obj_list(&world->obj_lst, pl2);
46+
47+
// pl3
48+
t_obj *pl3= (t_obj *)alloc_pool(sizeof(t_obj), set->the_pool);
49+
init_shape(PLANE, &pl3->shape);
50+
pl3->shape->material.color = create_color(0.3, 0, 1);
51+
insert_into_obj_list(&world->obj_lst, pl3);
52+
53+
// pl4
54+
t_obj *pl4= (t_obj *)alloc_pool(sizeof(t_obj), set->the_pool);
55+
init_shape(PLANE, &pl4->shape);
56+
pl4->shape->material.color = create_color(0.3, 0, 1);
57+
insert_into_obj_list(&world->obj_lst, pl4);
58+
59+
// LIGHT SRC 1
60+
t_pt_light light_1 = pt_light(point(5, -5, -5), create_color(1, 1, 1));
61+
insert_into_light_list(&world->lights_lst, light_1);
62+
63+
// LIGHT SRC 2
64+
t_pt_light light_2 = pt_light(point(5, -5, -5), create_color(0, 0, 1));
65+
insert_into_light_list(&world->lights_lst, light_2);
66+
67+
// LIGHT SRC 3
68+
t_pt_light light_3 = pt_light(point(5, -5, -5), create_color(0, 0, 1));
69+
insert_into_light_list(&world->lights_lst, light_3);
70+
71+
// CAM CONFIG
72+
cam = camera(WIDHT, HEIGHT, 3.14159 / 3);
73+
cam.transform = view_transform(point(0, 1.5, -5), point(0, 1, 0), vector(0, 1, 0));
74+
75+
// RENDER
76+
printf("test1\n");
77+
paint = render_canva(cam, world);
78+
printf("test2\n");
79+
80+
mlx_set_setting(MLX_STRETCH_IMAGE, true);
81+
mlx = mlx_init(cam.hsize, cam.vsize, "PT8", true);
82+
image = canva2image(paint, mlx);
83+
printf("test3\n");
84+
85+
mlx_image_to_window(mlx, image, 0, 0);
86+
87+
mlx_loop(mlx);
88+
mlx_terminate(mlx);
89+
quit(0);
90+
}
91+
92+
// int main(int argc, char **argv)
93+
// {
94+
// t_world *world;
95+
// t_paint paint;
96+
// mlx_t *mlx;
97+
// mlx_image_t *image;
98+
99+
// world = parser(argc, argv);
100+
101+
// // printf("sphere pos X[%f]Y[%f]Z[%f], colors R[%f]G[%f]B[%f], radius[%f]\n", ((t_sp *)(world->obj_lst->shape->obj))->src[X], \
102+
// // ((t_sp *)(world->obj_lst->shape->obj))->src[Y], \
103+
// // ((t_sp *)(world->obj_lst->shape->obj))->src[Z], \
104+
// // world->obj_lst->shape->material.color.red, \
105+
// // world->obj_lst->shape->material.color.green, \
106+
// // world->obj_lst->shape->material.color.blue, \
107+
// // ((t_sp *)(world->obj_lst->shape->obj))->radius);
108+
109+
// // printf("light pos X[%f]Y[%f]Z[%f], colors R[%f]G[%f]B[%f]\n", world->lights_lst->light_src.pos[X], \
110+
// // world->lights_lst->light_src.pos[Y], \
111+
// // world->lights_lst->light_src.pos[Z], \
112+
// // world->lights_lst->light_src.intens.red, \
113+
// // world->lights_lst->light_src.intens.green, \
114+
// // world->lights_lst->light_src.intens.blue);
115+
116+
// printf("cam [%f], [%f]", world->camera.hsize, world->camera.vsize);
117+
118+
// // RENDER
119+
// printf("test1\n");
120+
// paint = render_canva(world->camera, world);
121+
// printf("test2\n");
122+
123+
// mlx_set_setting(MLX_STRETCH_IMAGE, true);
124+
// mlx = mlx_init(world->camera.hsize, world->camera.vsize, "teste", true);
125+
// image = canva2image(paint, mlx);
126+
// printf("test3\n");
127+
128+
// mlx_image_to_window(mlx, image, 0, 0);
129+
130+
// mlx_loop(mlx);
131+
// mlx_terminate(mlx);
132+
// quit(0);
133+
// }

scenes/basic/1_sphere_pink.rt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,10 @@ sp 3,1,0 1 255,51,255
1818

1919
# Plane normal
2020
# position direction color
21-
pl 0,-1,0 0,1,0 200,200,200
21+
pl 0,0,0 0,1,0 200,200,200
22+
23+
# Pattern
24+
# name type color_a color_b scale rotation translation
25+
p gradient gradient 127,127,127 178,178,178 0.1,0.1,0.1 0,45,0 0,0,0
26+
p ring ring 127,127,127 178,178,178 0.1,0.1,0.1 0,45,0 0,0,1
27+
p checkers checkers 127,127,127 178,178,178 0.1,0.1,0.1 0,0,0 0,0,1

scenes/bonus/base_file.rt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ L 0,4.0,3.0 1 255,255,255
2121
# transparent | 1.0 | 0.0 | 1.0 |
2222
# reflective | 1.0 | 0.0 | 1.0 |
2323
# name reflectivity transparency refractive_index
24-
m some_material 1 1 1.5
24+
# m some_material 1 1 1.5
2525

2626
## PATTERN
2727
# name | type | color_a in RGB [0,255]) | color_b in RGB [0,255]) | scale (x,y,z) [0,1.0] | rotation em graus (x,y,z) | translation (x,y,z)
@@ -30,26 +30,26 @@ m some_material 1 1 1.5
3030
p gradient gradient 127,127,127 178,178,178 0.1,0.1,0.1 0,45,0 0,0,0
3131
p ring ring 127,127,127 178,178,178 0.1,0.1,0.1 0,45,0 0,0,1
3232
p checkers checkers 127,127,127 178,178,178 0.1,0.1,0.1 0,0,0 0,0,1
33-
p stripe stripe 127,127,127 178,178,178 0.1,0.1,0.1 0,0,0 0,0,1
33+
# p stripe stripe 127,127,127 178,178,178 0.1,0.1,0.1 0,0,0 0,0,1
3434

3535
## SPHERE
3636
# (origin point | diameter [>0] | color in RGB [0,255])
3737
# position diam color
38-
sp 0,1.1,0 2.0 216,56,136 default checkers
38+
sp 0,1.1,0 2.0 216,56,136 checkers
3939

4040
## PLANE
4141
# (origin point | orientation [-1.0,1.0] | color in RGB [0,255])
4242
# position normal color
43-
pl 0,0,0 0,1.0,0 140,118,206 default stripe
43+
pl 0,0,0 0,1.0,0 140,118,206 checkers
4444

4545
## CYLINDER
4646
# (origin point | orientation [-1.0,1.0] | diameter [>0] | height [>0] | color in RGB [0,255])
4747
# position normal diam height color
48-
cy -2.2,0,1.4 0,1.0,0 0.4 1.4 255,204,0 default gradient
48+
cy -2.2,0,1.4 0,1.0,0 0.4 1.4 255,204,0 gradient
4949
cy 0.8,0.3,2.0 1.0,0,0 0.4 1.0 255,204,0
5050

5151
## CONE
5252
# (origin point | orientation [-1.0,1.0] | diameter [>0] | height [>0] | color in RGB [0,255])
5353
# position normal diam height color
54-
cy -2.2,0,1.4 0,1.0,0 0.4 1.4 255,204,0 default ring
54+
cy -2.2,0,1.4 0,1.0,0 0.4 1.4 255,204,0 ring
5555
cy 0.8,0.3,2.0 1.0,0,0 0.4 1.0 255,204,0

scenes/bonus/complex_scene_checker.rt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ C 0,1.5,-6 0,0,1 70
1111
# Light
1212
# <coordinates: x,y,z> <brightness: 0-1> <color:red,green,blue>
1313
L -10,10,-10 0.5 255,255,255
14-
L 10,10,-10 0.5 255,255,255
15-
L 0,10,-10 0.5 255,255,255
14+
# L 10,10,-10 0.5 255,255,255
15+
# L 0,10,-10 0.5 255,255,255
1616

1717
# Pattern
1818
# name type color_a color_b scale rotation translation
@@ -26,7 +26,7 @@ sp -1.5,0.33,-0.75 0.6 255,204,26
2626

2727
# Cone
2828
# <coordinates: x,y,z> <orientation: x,y,z> <diameter: >= 0> <height: >= 0> <color:red,green,blue>
29-
cn 3.5,1.0,1 1,0,0 1.5 1.5 40,220,55
29+
# cn 3.5,1.0,1 1,0,0 1.5 1.5 40,220,55
3030

3131
# Cylinder
3232
# <coordinates: x,y,z> <orientation: x,y,z> <diameter: >= 0> <height: >= 0> <color:red,green,blue>
@@ -38,10 +38,10 @@ cy -4,0.6,1.6 0,0,1 1.2 2 122,23,230
3838
# Optional parameters: <pattern_type: checkered, striped_at> <origin: x,y,z> <color:red,green,blue>
3939

4040
# Floor
41-
pl 0,0,0 0,1,0 0,0,0 default checkers
41+
pl 0,0,0 0,1,0 0,0,0 checkers
4242
# Right wall
43-
pl 10,0,0 1,0,0 0,0,0 default checkers
43+
pl 10,0,0 1,0,0 0,0,0 checkers
4444
# Left wall
45-
pl -10,0,0 1,0,0 0,0,0 default checkers
45+
pl -10,0,0 1,0,0 0,0,0 checkers
4646
# Backdrop
47-
pl 0,0,30 0,0,1 0,0,0 default checkers
47+
pl 0,0,30 0,0,1 0,0,0 checkers

scenes/bonus/test_material.rt

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,13 @@
33
A 0.1 255,255,255
44

55
# Camera
6-
# position direction fov // arrumar parser da camera
6+
# position direction fov
77
C 0,1,-12 0,0,1 70
88

99
# Light
1010
# position intensity color
1111
L 0,20,-10 1 255,255,255
12-
L 0,-20,-10 1 255,255,255
13-
14-
# Material
15-
# default, glass, transparent, reflective
16-
# name reflectivity transparency refractive_index
17-
m bomdia 0 1 1.5
12+
# L 0,-20,-10 1 255,255,255
1813

1914
# Pattern
2015
# name type color_a color_b scale rotation translation
@@ -23,15 +18,15 @@ p ring ring 127,127,127 178,178,178 0.1,0.1,0.1
2318
p checkers checkers 127,127,127 178,178,178 0.1,0.1,0.1 0,0,0 0,0,1
2419

2520
# Plane normal
26-
# position direction color material pattern
27-
pl 0,-2,0 0,1,0 255,0,0 default checkers
28-
# pl 0,1,0 0,0,1 255,255,255
21+
# position direction color pattern
22+
pl 0,-2,0 0,1,0 255,0,0 checkers
23+
pl 0,1,0 0,0,1 255,255,255
2924

3025
# Sphere
31-
# position radius color material pattern
32-
# sp 0,0,0 2 255,255,255 default checkers
33-
# sp 10,0,0 2 255,255,255 default checkers
26+
# position radius color pattern
27+
sp 0,0,0 2 255,255,255 checkers
28+
sp 10,0,0 2 255,255,255 checkers
3429

3530
# Cone normal
36-
# position direction radius altura color material pattern
37-
cn 0,0,0 0,1,1 0.5 1.5 0,0,255 transparent gradient
31+
# position direction radius altura color pattern
32+
# cn 0,0,0 0,1,1 0.5 1.5 0,0,255 gradient

0 commit comments

Comments
 (0)