Implement .rt and args parsing, move test scene
authorLukas Jiriste <ljiriste@student.42prague.com>
Thu, 28 Nov 2024 16:58:18 +0000 (17:58 +0100)
committerLukas Jiriste <ljiriste@student.42prague.com>
Thu, 28 Nov 2024 17:04:36 +0000 (18:04 +0100)
Add rt_grammar and rt_parsing_table as they describe the grammar used to
parse the .rt file. Their contents are available to he program through
the file parsing_info.h where they are encoded (using xxd -i).

The test_scene is added for testing as the "default scene" had to be
erased from main for parsing to be enabled.

Other changes involve the parsing implementation directly.

Makefile
inc/miniRT.h
inc/parsing_info.h [new file with mode: 0644]
inc/vec3.h
rt_grammar [new file with mode: 0644]
rt_parsing_table [new file with mode: 0644]
src/main.c
src/parsing.c [new file with mode: 0644]
src/vec3.c
test_scene.rt [new file with mode: 0644]

index f3cf1bba71d2ba855ed49b28e64525e5dce4780e..eeff37207a44a6a13aa585ef224f0923e7bbe098 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -22,6 +22,7 @@ SRCDIR := src
 
 SOURCES :=     main.c                          \
                        scene.c                         \
+                       parsing.c                       \
                        vec3.c                          \
 
 SOURCES := $(addprefix $(SRCDIR)/, $(SOURCES))
index 3ccfb8c045382951f16bc2bf1ed594a36263d0a3..650c6db4a2bbd504abcb6c7006d923cc3fa37734 100644 (file)
@@ -119,5 +119,7 @@ typedef struct s_session
 }                      t_session;
 
 t_color        trace_ray(const t_ray *ray, const t_scene *scene);
+t_color        color_sRGB_to_lin(t_color_sRGB sRGB);
+int            parse_args(int argc, char **argv, t_session *s);
 
 #endif // MINIRT_H
diff --git a/inc/parsing_info.h b/inc/parsing_info.h
new file mode 100644 (file)
index 0000000..32497fd
--- /dev/null
@@ -0,0 +1,291 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   parsing_info.h                                     :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2024/11/28 12:31:54 by ljiriste          #+#    #+#             */
+/*   Updated: 2024/11/28 16:28:12 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#ifndef PARSING_INFO_H
+# define PARSING_INFO_H
+
+static char g_grammar[628] = {
+  0x73, 0x63, 0x65, 0x6e, 0x65, 0x20, 0x2d, 0x3e, 0x20, 0x27, 0x27, 0x0a,
+  0x73, 0x63, 0x65, 0x6e, 0x65, 0x20, 0x2d, 0x3e, 0x20, 0x73, 0x63, 0x65,
+  0x6e, 0x65, 0x20, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x0a, 0x65,
+  0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x2d, 0x3e, 0x20, 0x61, 0x6d,
+  0x62, 0x69, 0x65, 0x6e, 0x74, 0x5f, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x0a,
+  0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x2d, 0x3e, 0x20, 0x63,
+  0x61, 0x6d, 0x65, 0x72, 0x61, 0x0a, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e,
+  0x74, 0x20, 0x2d, 0x3e, 0x20, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x0a, 0x65,
+  0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x2d, 0x3e, 0x20, 0x73, 0x70,
+  0x68, 0x65, 0x72, 0x65, 0x0a, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74,
+  0x20, 0x2d, 0x3e, 0x20, 0x70, 0x6c, 0x61, 0x6e, 0x65, 0x0a, 0x65, 0x6c,
+  0x65, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x2d, 0x3e, 0x20, 0x63, 0x79, 0x6c,
+  0x69, 0x6e, 0x64, 0x65, 0x72, 0x0a, 0x61, 0x6d, 0x62, 0x69, 0x65, 0x6e,
+  0x74, 0x5f, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x20, 0x2d, 0x3e, 0x20, 0x41,
+  0x20, 0x69, 0x6e, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x74, 0x79, 0x20, 0x72,
+  0x67, 0x62, 0x0a, 0x63, 0x61, 0x6d, 0x65, 0x72, 0x61, 0x20, 0x2d, 0x3e,
+  0x20, 0x43, 0x20, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74,
+  0x65, 0x73, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x20, 0x66, 0x69,
+  0x65, 0x6c, 0x64, 0x5f, 0x6f, 0x66, 0x5f, 0x76, 0x69, 0x65, 0x77, 0x0a,
+  0x6c, 0x69, 0x67, 0x68, 0x74, 0x20, 0x2d, 0x3e, 0x20, 0x4c, 0x20, 0x63,
+  0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x20, 0x69,
+  0x6e, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x74, 0x79, 0x0a, 0x6c, 0x69, 0x67,
+  0x68, 0x74, 0x20, 0x2d, 0x3e, 0x20, 0x4c, 0x20, 0x63, 0x6f, 0x6f, 0x72,
+  0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x20, 0x69, 0x6e, 0x74, 0x65,
+  0x6e, 0x73, 0x69, 0x74, 0x79, 0x20, 0x72, 0x67, 0x62, 0x0a, 0x73, 0x70,
+  0x68, 0x65, 0x72, 0x65, 0x20, 0x2d, 0x3e, 0x20, 0x53, 0x50, 0x20, 0x63,
+  0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x20, 0x64,
+  0x69, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x20, 0x72, 0x67, 0x62, 0x0a,
+  0x70, 0x6c, 0x61, 0x6e, 0x65, 0x20, 0x2d, 0x3e, 0x20, 0x50, 0x4c, 0x20,
+  0x63, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x20,
+  0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x20, 0x72, 0x67, 0x62, 0x0a, 0x63,
+  0x79, 0x6c, 0x69, 0x6e, 0x64, 0x65, 0x72, 0x20, 0x2d, 0x3e, 0x20, 0x43,
+  0x59, 0x20, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65,
+  0x73, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x20, 0x64, 0x69, 0x61,
+  0x6d, 0x65, 0x74, 0x65, 0x72, 0x20, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74,
+  0x20, 0x72, 0x67, 0x62, 0x0a, 0x69, 0x6e, 0x74, 0x65, 0x6e, 0x73, 0x69,
+  0x74, 0x79, 0x20, 0x2d, 0x3e, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x0a,
+  0x72, 0x67, 0x62, 0x20, 0x2d, 0x3e, 0x20, 0x49, 0x4e, 0x54, 0x20, 0x43,
+  0x4f, 0x4d, 0x4d, 0x41, 0x20, 0x49, 0x4e, 0x54, 0x20, 0x43, 0x4f, 0x4d,
+  0x4d, 0x41, 0x20, 0x49, 0x4e, 0x54, 0x0a, 0x63, 0x6f, 0x6f, 0x72, 0x64,
+  0x69, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x20, 0x2d, 0x3e, 0x20, 0x76, 0x65,
+  0x63, 0x74, 0x6f, 0x72, 0x0a, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x20,
+  0x2d, 0x3e, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x43, 0x4f, 0x4d,
+  0x4d, 0x41, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x43, 0x4f, 0x4d,
+  0x4d, 0x41, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x0a, 0x66, 0x69, 0x65,
+  0x6c, 0x64, 0x5f, 0x6f, 0x66, 0x5f, 0x76, 0x69, 0x65, 0x77, 0x20, 0x2d,
+  0x3e, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x0a, 0x64, 0x69, 0x61, 0x6d,
+  0x65, 0x74, 0x65, 0x72, 0x20, 0x2d, 0x3e, 0x20, 0x66, 0x6c, 0x6f, 0x61,
+  0x74, 0x0a, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x20, 0x2d, 0x3e, 0x20,
+  0x66, 0x6c, 0x6f, 0x61, 0x74, 0x0a, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20,
+  0x2d, 0x3e, 0x20, 0x49, 0x4e, 0x54, 0x0a, 0x66, 0x6c, 0x6f, 0x61, 0x74,
+  0x20, 0x2d, 0x3e, 0x20, 0x49, 0x4e, 0x54, 0x20, 0x44, 0x4f, 0x54, 0x20,
+  0x49, 0x4e, 0x54, 0x0a
+};
+
+static char g_parsing_table[2586] = {
+  0x53, 0x74, 0x61, 0x74, 0x65, 0x3b, 0x44, 0x4f, 0x54, 0x3b, 0x43, 0x4f,
+  0x4d, 0x4d, 0x41, 0x3b, 0x49, 0x4e, 0x54, 0x3b, 0x43, 0x59, 0x3b, 0x50,
+  0x4c, 0x3b, 0x53, 0x50, 0x3b, 0x4c, 0x3b, 0x43, 0x3b, 0x41, 0x3b, 0x24,
+  0x3b, 0x73, 0x63, 0x65, 0x6e, 0x65, 0x3b, 0x65, 0x6c, 0x65, 0x6d, 0x65,
+  0x6e, 0x74, 0x3b, 0x61, 0x6d, 0x62, 0x69, 0x65, 0x6e, 0x74, 0x5f, 0x6c,
+  0x69, 0x67, 0x68, 0x74, 0x3b, 0x63, 0x61, 0x6d, 0x65, 0x72, 0x61, 0x3b,
+  0x6c, 0x69, 0x67, 0x68, 0x74, 0x3b, 0x73, 0x70, 0x68, 0x65, 0x72, 0x65,
+  0x3b, 0x70, 0x6c, 0x61, 0x6e, 0x65, 0x3b, 0x63, 0x79, 0x6c, 0x69, 0x6e,
+  0x64, 0x65, 0x72, 0x3b, 0x69, 0x6e, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x74,
+  0x79, 0x3b, 0x72, 0x67, 0x62, 0x3b, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x69,
+  0x6e, 0x61, 0x74, 0x65, 0x73, 0x3b, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72,
+  0x3b, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x5f, 0x6f, 0x66, 0x5f, 0x76, 0x69,
+  0x65, 0x77, 0x3b, 0x64, 0x69, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x3b,
+  0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x3b, 0x66, 0x6c, 0x6f, 0x61, 0x74,
+  0x0a, 0x30, 0x3b, 0x3b, 0x3b, 0x3b, 0x72, 0x30, 0x3b, 0x72, 0x30, 0x3b,
+  0x72, 0x30, 0x3b, 0x72, 0x30, 0x3b, 0x72, 0x30, 0x3b, 0x72, 0x30, 0x3b,
+  0x72, 0x30, 0x3b, 0x31, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
+  0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x0a, 0x31, 0x3b, 0x3b, 0x3b,
+  0x3b, 0x73, 0x32, 0x3b, 0x73, 0x32, 0x37, 0x3b, 0x73, 0x33, 0x31, 0x3b,
+  0x73, 0x33, 0x35, 0x3b, 0x73, 0x34, 0x33, 0x3b, 0x73, 0x35, 0x31, 0x3b,
+  0x61, 0x63, 0x63, 0x3b, 0x3b, 0x35, 0x35, 0x3b, 0x35, 0x36, 0x3b, 0x35,
+  0x37, 0x3b, 0x35, 0x38, 0x3b, 0x35, 0x39, 0x3b, 0x36, 0x30, 0x3b, 0x36,
+  0x31, 0x3b, 0x3b, 0x3b, 0x3b, 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3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x0a, 0x36,
+  0x31, 0x3b, 0x3b, 0x3b, 0x3b, 0x72, 0x37, 0x3b, 0x72, 0x37, 0x3b, 0x72,
+  0x37, 0x3b, 0x72, 0x37, 0x3b, 0x72, 0x37, 0x3b, 0x72, 0x37, 0x3b, 0x72,
+  0x37, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
+  0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x0a
+};
+
+#endif // PARSING_INFO_H
index 787b8062f456f9269f74fc15d70c0dfe6ee96811..28aeaf8aedf13e6a66d0bbebcc1bff2ff34fa56b 100644 (file)
@@ -15,5 +15,6 @@ double        vec_scalar_mul(t_vec3 v, t_vec3 u);
 t_vec3 vec_elwise_mul(t_vec3 v, t_vec3 u);
 t_vec3 vec_vec_mul(t_vec3 v, t_vec3 u);
 double vec_norm(t_vec3 vec);
+t_vec3 vec_normalize(t_vec3 vec);
 
 #endif // VEC3_H
diff --git a/rt_grammar b/rt_grammar
new file mode 100644 (file)
index 0000000..72be4e1
--- /dev/null
@@ -0,0 +1,24 @@
+scene -> ''
+scene -> scene element
+element -> ambient_light
+element -> camera
+element -> light
+element -> sphere
+element -> plane
+element -> cylinder
+ambient_light -> A intensity rgb
+camera -> C coordinates vector field_of_view
+light -> L coordinates intensity
+light -> L coordinates intensity rgb
+sphere -> SP coordinates diameter rgb
+plane -> PL coordinates vector rgb
+cylinder -> CY coordinates vector diameter height rgb
+intensity -> float
+rgb -> INT COMMA INT COMMA INT
+coordinates -> vector
+vector -> float COMMA float COMMA float
+field_of_view -> float
+diameter -> float
+height -> float
+float -> INT
+float -> INT DOT INT
diff --git a/rt_parsing_table b/rt_parsing_table
new file mode 100644 (file)
index 0000000..9e75d0a
--- /dev/null
@@ -0,0 +1,63 @@
+State;DOT;COMMA;INT;CY;PL;SP;L;C;A;$;scene;element;ambient_light;camera;light;sphere;plane;cylinder;intensity;rgb;coordinates;vector;field_of_view;diameter;height;float
+0;;;;r0;r0;r0;r0;r0;r0;r0;1;;;;;;;;;;;;;;;
+1;;;;s2;s27;s31;s35;s43;s51;acc;;55;56;57;58;59;60;61;;;;;;;;
+2;;;s3;;;;;;;;;;;;;;;;;;6;26;;;;21
+3;s4;r22;;;;;;;;;;;;;;;;;;;;;;;;
+4;;;s5;;;;;;;;;;;;;;;;;;;;;;;
+5;;r23;;;;;;;;;;;;;;;;;;;;;;;;
+6;;;s3;;;;;;;;;;;;;;;;;;;7;;;;21
+7;;;s8;;;;;;;;;;;;;;;;;;;;;11;;20
+8;s9;;r22;;;;;;;;;;;;;;;;;;;;;;;
+9;;;s10;;;;;;;;;;;;;;;;;;;;;;;
+10;;;r23;;;;;;;;;;;;;;;;;;;;;;;
+11;;;s8;;;;;;;;;;;;;;;;;;;;;;12;19
+12;;;s13;;;;;;;;;;;;;;;;;18;;;;;;
+13;;s14;;;;;;;;;;;;;;;;;;;;;;;;
+14;;;s15;;;;;;;;;;;;;;;;;;;;;;;
+15;;s16;;;;;;;;;;;;;;;;;;;;;;;;
+16;;;s17;;;;;;;;;;;;;;;;;;;;;;;
+17;;;;r16;r16;r16;r16;r16;r16;r16;;;;;;;;;;;;;;;;
+18;;;;r14;r14;r14;r14;r14;r14;r14;;;;;;;;;;;;;;;;
+19;;;r21;;;;;;;;;;;;;;;;;;;;;;;
+20;;;r20;;;;;;;;;;;;;;;;;;;;;;;
+21;;s22;;;;;;;;;;;;;;;;;;;;;;;;
+22;;;s3;;;;;;;;;;;;;;;;;;;;;;;23
+23;;s24;;;;;;;;;;;;;;;;;;;;;;;;
+24;;;s8;;;;;;;;;;;;;;;;;;;;;;;25
+25;;;r18;;;;;;;;;;;;;;;;;;;;;;;
+26;;;r17;;;;;;;;;;;;;;;;;;;;;;;
+27;;;s3;;;;;;;;;;;;;;;;;;28;26;;;;21
+28;;;s3;;;;;;;;;;;;;;;;;;;29;;;;21
+29;;;s13;;;;;;;;;;;;;;;;;30;;;;;;
+30;;;;r13;r13;r13;r13;r13;r13;r13;;;;;;;;;;;;;;;;
+31;;;s3;;;;;;;;;;;;;;;;;;32;26;;;;21
+32;;;s8;;;;;;;;;;;;;;;;;;;;;33;;20
+33;;;s13;;;;;;;;;;;;;;;;;34;;;;;;
+34;;;;r12;r12;r12;r12;r12;r12;r12;;;;;;;;;;;;;;;;
+35;;;s3;;;;;;;;;;;;;;;;;;36;26;;;;21
+36;;;s37;;;;;;;;;;;;;;;;40;;;;;;;42
+37;s38;;r22;r22;r22;r22;r22;r22;r22;r22;;;;;;;;;;;;;;;;
+38;;;s39;;;;;;;;;;;;;;;;;;;;;;;
+39;;;r23;r23;r23;r23;r23;r23;r23;r23;;;;;;;;;;;;;;;;
+40;;;s13;r10;r10;r10;r10;r10;r10;r10;;;;;;;;;;41;;;;;;
+41;;;;r11;r11;r11;r11;r11;r11;r11;;;;;;;;;;;;;;;;
+42;;;r15;r15;r15;r15;r15;r15;r15;r15;;;;;;;;;;;;;;;;
+43;;;s3;;;;;;;;;;;;;;;;;;44;26;;;;21
+44;;;s3;;;;;;;;;;;;;;;;;;;45;;;;21
+45;;;s46;;;;;;;;;;;;;;;;;;;;49;;;50
+46;s47;;;r22;r22;r22;r22;r22;r22;r22;;;;;;;;;;;;;;;;
+47;;;s48;;;;;;;;;;;;;;;;;;;;;;;
+48;;;;r23;r23;r23;r23;r23;r23;r23;;;;;;;;;;;;;;;;
+49;;;;r9;r9;r9;r9;r9;r9;r9;;;;;;;;;;;;;;;;
+50;;;;r19;r19;r19;r19;r19;r19;r19;;;;;;;;;;;;;;;;
+51;;;s8;;;;;;;;;;;;;;;;52;;;;;;;54
+52;;;s13;;;;;;;;;;;;;;;;;53;;;;;;
+53;;;;r8;r8;r8;r8;r8;r8;r8;;;;;;;;;;;;;;;;
+54;;;r15;;;;;;;;;;;;;;;;;;;;;;;
+55;;;;r1;r1;r1;r1;r1;r1;r1;;;;;;;;;;;;;;;;
+56;;;;r2;r2;r2;r2;r2;r2;r2;;;;;;;;;;;;;;;;
+57;;;;r3;r3;r3;r3;r3;r3;r3;;;;;;;;;;;;;;;;
+58;;;;r4;r4;r4;r4;r4;r4;r4;;;;;;;;;;;;;;;;
+59;;;;r5;r5;r5;r5;r5;r5;r5;;;;;;;;;;;;;;;;
+60;;;;r6;r6;r6;r6;r6;r6;r6;;;;;;;;;;;;;;;;
+61;;;;r7;r7;r7;r7;r7;r7;r7;;;;;;;;;;;;;;;;
index 68f1aa498d32f19b4b981efef5abfbf411909a6a..68e389107f48a87b23099e9d0cd7a7982007f486 100644 (file)
@@ -192,77 +192,23 @@ void      cleanup(t_session *s)
 
 void   set_defaults(t_session *s)
 {
-       t_camera        cam;
-       t_light         light;
-       t_object        object;
-
        s->img.width = 1920;
        s->img.height = 1011;
        ft_vec_init(&s->scene.objects, sizeof(t_object));
        ft_vec_init(&s->scene.lights, sizeof(t_light));
        ft_vec_init(&s->scene.cameras, sizeof(t_camera));
-       light.color.x = 1;
-       light.color.y = 0;
-       light.color.z = 0;
-       light.position.x = 3;
-       light.position.y = 0;
-       light.position.z = 0;
-       light.brightness = 0.4;
-       ft_vec_append(&s->scene.lights, &light);
-       light.color.x = 0;
-       light.color.z = 1;
-       light.position.y = 1;
-       ft_vec_append(&s->scene.lights, &light);
-       cam.position.x = 0;
-       cam.position.y = 0;
-       cam.position.z = 0;
-       cam.orientation.x = 1;
-       cam.orientation.y = 0;
-       cam.orientation.z = 0;
-       cam.up_direction.x = 0;
-       cam.up_direction.y = 0;
-       cam.up_direction.z = 1;
-       cam.field_of_view = 1.5;
-       ft_vec_append(&s->scene.cameras, &cam);
-       object.object.sphere.color.x = 1;
-       object.object.sphere.color.y = 1;
-       object.object.sphere.color.z = 1;
-       object.object.sphere.center.x = 3;
-       object.object.sphere.center.y = 0.5;
-       object.object.sphere.center.z = -0.7;
-       object.object.sphere.radius = 0.3;
-       object.type = SPHERE;
-       ft_vec_append(&s->scene.objects, &object);
-       object.type = PLANE;
-       object.object.plane.color.x = 1;
-       object.object.plane.color.y = 1;
-       object.object.plane.color.z = 1;
-       object.object.plane.point.x = 0;
-       object.object.plane.point.y = 0;
-       object.object.plane.point.z = -1;
-       object.object.plane.normal.x = 0;
-       object.object.plane.normal.y = 0;
-       object.object.plane.normal.z = 1;
-       ft_vec_append(&s->scene.objects, &object);
-       s->scene.current_camera = ft_vec_caccess(&s->scene.cameras, 0);
-       s->scene.ambient_light.color.x = 1;
-       s->scene.ambient_light.color.y = 1;
-       s->scene.ambient_light.color.z = 1;
-       s->scene.ambient_light.brightness = 0.01;
 }
 
-int    main(void)
+int    main(int argc, char **argv)
 {
        t_session       s;
 
        set_defaults(&s);
-       /*
        if (parse_args(argc, argv, &s))
        {
-               print_help();
+               //print_help();
                return (1);
        }
-       */
        init_session(&s);
        mlx_hook(s.win, KeyPress, KeyPressMask, handle_key_press, &s);
        mlx_hook(s.win, ButtonPress, ButtonPressMask, handle_mouse_press, &s);
diff --git a/src/parsing.c b/src/parsing.c
new file mode 100644 (file)
index 0000000..a24272a
--- /dev/null
@@ -0,0 +1,386 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   parsing.c                                          :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2024/11/28 12:34:20 by ljiriste          #+#    #+#             */
+/*   Updated: 2024/11/28 17:56:14 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "parsing_info.h"
+#include "miniRT.h"
+#include "libft.h"
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+const char     *extract_keyword(const char *line, size_t *i)
+{
+       if (line[*i + 1] == '\0' || ft_isspace(line[*i + 1]))
+       {
+               if (line[*i] == 'A')
+                       return ("A");
+               if (line[*i] == 'C')
+                       return ("C");
+               if (line[*i] == 'L')
+                       return ("L");
+       }
+       else if (line[*i + 2] == '\0' || ft_isspace(line[*i + 2]))
+       {
+               ++*i;
+               if (!ft_strncmp(line + *i - 1, "cy", 2))
+                       return ("CY");
+               if (!ft_strncmp(line + *i - 1, "pl", 2))
+                       return ("PL");
+               if (!ft_strncmp(line + *i - 1, "sp", 2))
+                       return ("SP");
+       }
+       return (NULL);
+}
+
+char   *extract_int(const char *line, size_t *i)
+{
+       size_t  j;
+
+       j = *i;
+       while (ft_isdigit(line[*i]) || line[*i] == '-')
+               ++*i;
+       return (ft_strndup(line + j, ((*i)--) - j));
+}
+
+void   free_token(void *v_token)
+{
+       t_token *token;
+
+       token = v_token;
+       free(token->str);
+       return ;
+}
+
+int    tokenize_line(const char *line, t_vec *tokens)
+{
+       size_t  i;
+       t_token token;
+
+       i = 0;
+       while (line[i])
+       {
+               token.str = NULL;
+               while (ft_isspace(line[i]))
+                       ++i;
+               if (!line[i])
+                       break ;
+               if (line[i] == '.')
+                       token.type = "DOT";
+               else if (line[i] == ',')
+                       token.type = "COMMA";
+               else if (ft_isdigit(line[i]) || line[i] == '-')
+               {
+                       token.type = "INT";
+                       token.str = extract_int(line, &i);
+                       if (!token.str)
+                               return (1);
+               }
+               else
+               {
+                       token.type = (char *)extract_keyword(line, &i);
+                       if (!token.type)
+                               return (1);
+               }
+               if (ft_vec_append(tokens, &token) != success)
+               {
+                       free_token(&token);
+                       return (1);
+               }
+               ++i;
+       }
+       return (0);
+}
+
+int    tokenize(const char *filename, t_vec *tokens)
+{
+       int             fd;
+       char    *line;
+
+       fd = open(filename, O_RDONLY);
+       if (fd < 0)
+               return (1);
+       line = get_next_line(fd);
+       while (line)
+       {
+               if (tokenize_line(line, tokens))
+               {
+                       free(line);
+                       get_next_line(-1);
+                       close(fd);
+                       return (1);
+               }
+               free(line);
+               line = get_next_line(fd);
+       }
+       close(fd);
+       return (0);
+}
+
+int    node_to_int(const t_parse_tree_node *int_node)
+{
+       return (ft_atoi(int_node->token.str));
+}
+
+double node_to_double(const t_parse_tree_node *double_node)
+{
+       int                     whole;
+       int                     sign;
+       double          decimal;
+       const char      *str;
+
+       if (double_node->children.size == 1)
+               return (node_to_int(ft_cget_node_child(double_node, 0)));
+       str = ft_cget_node_child(double_node, 0)->token.str;
+       sign = 1;
+       if (str[0] == '-')
+       {
+               sign = -1;
+               ++str;
+       }
+       whole = ft_atoi(str);
+       str = ft_cget_node_child(double_node, 2)->token.str;
+       decimal = ft_atoi(str);
+       while (*str)
+       {
+               decimal /= 10;
+               ++str;
+       }
+       return (sign * (whole + decimal));
+}
+
+t_color        node_to_linear_RGB(const t_parse_tree_node *rgb_node)
+{
+       const t_parse_tree_node *int_node;
+       t_color_sRGB                    color;
+
+       int_node = ft_cget_node_child(rgb_node, 0);
+       color.r = node_to_int(int_node);
+       int_node = ft_cget_node_child(rgb_node, 2);
+       color.g = node_to_int(int_node);
+       int_node = ft_cget_node_child(rgb_node, 4);
+       color.b = node_to_int(int_node);
+       return (color_sRGB_to_lin(color));
+}
+
+t_vec3 node_to_vec3(const t_parse_tree_node *vec3_node)
+{
+       const t_parse_tree_node *double_node;
+       t_vec3                                  res;
+
+       double_node = ft_cget_node_child(vec3_node, 0);
+       res.x = node_to_double(double_node);
+       double_node = ft_cget_node_child(vec3_node, 2);
+       res.y = node_to_double(double_node);
+       double_node = ft_cget_node_child(vec3_node, 4);
+       res.z = node_to_double(double_node);
+       return (res);
+}
+
+void   set_ambient_light(
+                       const t_parse_tree_node *ambient_node, t_ambient_light *ambient)
+{
+       const t_parse_tree_node *intensity_node;
+       const t_parse_tree_node *rgb_node;
+
+       intensity_node = ft_cget_node_child(ambient_node, 1);
+       rgb_node = ft_cget_node_child(ambient_node, 2);
+       ambient->brightness = node_to_double(ft_cget_node_child(intensity_node, 0));
+       ambient->color = node_to_linear_RGB(rgb_node);
+       return ;
+}
+
+int    add_light(const t_parse_tree_node *light_node, t_vec *lights)
+{
+       t_light light;
+
+       light.brightness = node_to_double(ft_cget_node_child(ft_cget_node_child(light_node, 2), 0));
+       light.position = node_to_vec3(ft_cget_node_child(
+                               ft_cget_node_child(light_node, 1), 0));
+       if (light_node->children.size == 4)
+               light.color = node_to_linear_RGB(ft_cget_node_child(light_node, 3));
+       else
+               light.color = (t_color){.x = 1, .y = 1, .z = 1};
+       return (ft_vec_append(lights, &light) != success);
+}
+
+int    add_camera(const t_parse_tree_node *camera_node, t_vec *cameras)
+{
+       t_camera        camera;
+
+       camera.position = node_to_vec3(ft_cget_node_child(
+                               ft_cget_node_child(camera_node, 1), 0));
+       camera.orientation = node_to_vec3(ft_cget_node_child(camera_node, 2));
+       camera.orientation = vec_normalize(camera.orientation);
+       camera.up_direction = (t_vec3){.x = 0, .y = 0, .z = 1};
+       camera.up_direction = vec_vec_mul(camera.orientation, camera.up_direction);
+       if (vec_norm(camera.up_direction) < 1e-3)
+               camera.up_direction = (t_vec3){.x = 0, .y = 1, .z = 0};
+       camera.up_direction = vec_vec_mul(camera.up_direction, camera.orientation);
+       camera.up_direction = vec_normalize(camera.up_direction);
+       camera.field_of_view = node_to_double(ft_cget_node_child(ft_cget_node_child(camera_node, 3), 0));
+       return (ft_vec_append(cameras, &camera) != success);
+}
+
+int    add_plane(const t_parse_tree_node *plane_node, t_vec *objects)
+{
+       t_object        object;
+
+       object.type = PLANE;
+       object.object.plane.point = node_to_vec3(ft_cget_node_child(ft_cget_node_child(plane_node, 1), 0));
+       object.object.plane.normal = node_to_vec3(ft_cget_node_child(plane_node, 2));
+       object.object.plane.color = node_to_linear_RGB(ft_cget_node_child(plane_node, 3));
+       object.object.plane.normal = vec_normalize(object.object.plane.normal);
+       return (ft_vec_append(objects, &object) != success);
+}
+
+int    add_sphere(const t_parse_tree_node *sphere_node, t_vec *objects)
+{
+       t_object        object;
+
+       object.type = SPHERE;
+       object.object.sphere.center = node_to_vec3(ft_cget_node_child(ft_cget_node_child(sphere_node, 1), 0));
+       object.object.sphere.radius = node_to_double(ft_cget_node_child(ft_cget_node_child(sphere_node, 2), 0)) / 2;
+       object.object.sphere.color = node_to_linear_RGB(ft_cget_node_child(sphere_node, 3));
+       return (ft_vec_append(objects, &object) != success);
+}
+
+int    add_cylinder(const t_parse_tree_node *cylinder_node, t_vec *objects)
+{
+       t_object        object;
+
+       object.type = CYLINDER;
+       object.object.cylinder.center = node_to_vec3(ft_cget_node_child(ft_cget_node_child(cylinder_node, 1), 0));
+       object.object.cylinder.rot_axis = node_to_vec3(ft_cget_node_child(cylinder_node, 2));
+       object.object.cylinder.rot_axis = vec_normalize(object.object.cylinder.rot_axis);
+       object.object.cylinder.color = node_to_linear_RGB(ft_cget_node_child(cylinder_node, 5));
+       object.object.cylinder.radius = node_to_double(ft_cget_node_child(ft_cget_node_child(cylinder_node, 3), 0)) / 2;
+       object.object.cylinder.height = node_to_double(ft_cget_node_child(ft_cget_node_child(cylinder_node, 4), 0));
+       object.object.sphere.color = node_to_linear_RGB(ft_cget_node_child(cylinder_node, 5));
+       return (ft_vec_append(objects, &object) != success);
+}
+
+int    add_element_to_scene(const t_parse_tree_node *element, t_scene *scene)
+{
+       const char                              *type;
+       const t_parse_tree_node *specific_element;
+
+       specific_element = ft_cget_node_child(element, 0);
+       type = specific_element->token.type;
+       if (!ft_strcmp(type, "ambient_light"))
+               set_ambient_light(specific_element, &scene->ambient_light);
+       else if (!ft_strcmp(type, "light"))
+       {
+               if (add_light(specific_element, &scene->lights))
+                       return (1);
+       }
+       else if (!ft_strcmp(type, "camera"))
+       {
+               if (add_camera(specific_element, &scene->cameras))
+                       return (1);
+       }
+       else if (!ft_strcmp(type, "sphere"))
+       {
+               if (add_sphere(specific_element, &scene->objects))
+                       return (1);
+       }
+       else if (!ft_strcmp(type, "plane"))
+       {
+               if (add_plane(specific_element, &scene->objects))
+                       return (1);
+       }
+       else if (!ft_strcmp(type, "cylinder"))
+       {
+               if (add_cylinder(specific_element, &scene->objects))
+                       return (1);
+       }
+       return (0);
+}
+
+int    parse_tree_to_scene(const t_parse_tree_node *tree, t_scene *scene)
+{
+       if (tree->children.size == 2)
+       {
+               if (add_element_to_scene(ft_cget_node_child(tree, 1), scene))
+                       return (1);
+               if (parse_tree_to_scene(ft_cget_node_child(tree, 0), scene))
+                       return (1);
+       }
+       return (0);
+}
+
+int    parse_rt_file(const char *filename, t_scene *scene)
+{
+       int                                     res;
+       t_vec                           tokens;
+       t_parsing_table         parsing_table;
+       t_parse_tree_node       *parse_tree;
+
+       res = 1;
+       ft_vec_init(&tokens, sizeof(t_token));
+       if (!tokenize(filename, &tokens))
+       {
+               if (ft_parsing_table_init(&parsing_table) == success
+                       && ft_parsing_table_load_str(&parsing_table, g_parsing_table, g_grammar)
+                       == success)
+               {
+                       parse_tree = ft_parse(&tokens, &parsing_table);
+                       if (parse_tree && !parse_tree_to_scene(parse_tree, scene))
+                               if (scene->cameras.size > 0)
+                               {
+                                       scene->current_camera = ft_vec_caccess(&scene->cameras, 0);
+                                       res = 0;
+                               }
+                       ft_parse_tree_free(parse_tree);
+               }
+               ft_parsing_table_free(&parsing_table);
+       }
+       ft_vec_free(&tokens, free_token);
+       return (res);
+}
+
+static int     parse_arg(char **argv, t_session *s, int *i)
+{
+       if (!ft_strcmp(argv[*i], "-w")
+               && ft_isint(argv[*i + 1]) && ft_atoi(argv[*i + 1]) > 0)
+               s->img.width = ft_atoi(argv[++*i]);
+       else if (!ft_strcmp(argv[*i], "-h")
+               && ft_isint(argv[*i + 1]) && ft_atoi(argv[*i + 1]) > 0)
+               s->img.height = ft_atoi(argv[++*i]);
+       else if (!ft_strcmp(argv[*i], "-f"))
+       {
+               if (parse_rt_file(argv[*i + 1], &s->scene))
+                       return (2);
+       }
+       else
+               return (1);
+       return (0);
+}
+
+int    parse_args(int argc, char **argv, t_session *s)
+{
+       int     i;
+       int     got_file;
+
+       got_file = 0;
+       if (argc % 2 == 0)
+               return (1);
+       i = 1;
+       while (i + 1 < argc)
+       {
+               if (!ft_strcmp(argv[i], "-f"))
+                       got_file = 1;
+               if (parse_arg(argv, s, &i))
+                       return (1);
+               ++i;
+       }
+       return (!got_file);
+}
index 3a0697f4d77efa4505b71b950e12b4ee8c720cc8..c51450246c617056dac4445d8e97c2979e1ea474 100644 (file)
@@ -60,3 +60,8 @@ double        vec_norm(t_vec3 vec)
 {
        return (sqrt(vec_scalar_mul(vec, vec)));
 }
+
+t_vec3 vec_normalize(t_vec3 vec)
+{
+       return (vec_real_mul(vec, vec_norm(vec)));
+}
diff --git a/test_scene.rt b/test_scene.rt
new file mode 100644 (file)
index 0000000..bbdf879
--- /dev/null
@@ -0,0 +1,7 @@
+L 3,0,0 0.4 255,0,0
+L 3,1,0 0.4 0,0,255
+C 0,0,0 1,0,0 90
+sp 3,0.5,-0.7 0.6 255,255,255
+pl 0,0,-1 0,0,1 255,255,255
+cy 3,-0.5,-0.7 0,0,1 0.5 0.6 255,255,255
+A 0.01 255,255,255