SOURCES := main.c \
scene.c \
+ vec3.c \
SOURCES := $(addprefix $(SRCDIR)/, $(SOURCES))
#ifndef MINIRT_H
# define MINIRT_H
+# include "vec3.h"
# include "libft.h"
-typedef struct s_vector_3d
-{
- double x;
- double y;
- double z;
-} t_vec3;
-
typedef t_vec3 t_color;
typedef struct s_color_sRGB
--- /dev/null
+#ifndef VEC3_H
+# define VEC3_H
+
+typedef struct s_vector_3d
+{
+ double x;
+ double y;
+ double z;
+} t_vec3;
+
+t_vec3 vec_add(t_vec3 v, t_vec3 u);
+t_vec3 vec_diff(t_vec3 v, t_vec3 u);
+t_vec3 vec_real_mul(t_vec3 vec, double real);
+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);
+
+#endif // VEC3_H
+#include "vec3.h"
#include "miniRT.h"
#include "libft.h"
#include <math.h>
return (sqrt(base_radius * base_radius + height * height / 4));
}
-t_vec3 vec_add(t_vec3 v, t_vec3 u)
-{
- t_vec3 res;
-
- res.x = v.x + u.x;
- res.y = v.y + u.y;
- res.z = v.z + u.z;
- return (res);
-}
-
-t_vec3 vec_diff(t_vec3 v, t_vec3 u)
-{
- t_vec3 res;
-
- res.x = v.x - u.x;
- res.y = v.y - u.y;
- res.z = v.z - u.z;
- return (res);
-}
-
-t_vec3 vec_real_mul(t_vec3 vec, double real)
-{
- t_vec3 res;
-
- res.x = real * vec.x;
- res.y = real * vec.y;
- res.z = real * vec.z;
- return (res);
-}
-
-double vec_scalar_mul(t_vec3 v, t_vec3 u)
-{
- return (v.x * u.x + v.y * u.y + v.z * u.z);
-}
-
-t_vec3 vec_elwise_mul(t_vec3 v, t_vec3 u)
-{
- t_vec3 res;
-
- res.x = v.x * u.x;
- res.y = v.y * u.y;
- res.z = v.z * u.z;
- return (res);
-}
-
-double vec_norm(t_vec3 vec)
-{
- return (sqrt(vec_scalar_mul(vec, vec)));
-}
-
double dist_point_from_line(const t_ray *ray, t_vec3 point)
{
t_vec3 start;
--- /dev/null
+#include "vec3.h"
+#include <math.h>
+
+t_vec3 vec_add(t_vec3 v, t_vec3 u)
+{
+ t_vec3 res;
+
+ res.x = v.x + u.x;
+ res.y = v.y + u.y;
+ res.z = v.z + u.z;
+ return (res);
+}
+
+t_vec3 vec_diff(t_vec3 v, t_vec3 u)
+{
+ t_vec3 res;
+
+ res.x = v.x - u.x;
+ res.y = v.y - u.y;
+ res.z = v.z - u.z;
+ return (res);
+}
+
+t_vec3 vec_real_mul(t_vec3 vec, double real)
+{
+ t_vec3 res;
+
+ res.x = real * vec.x;
+ res.y = real * vec.y;
+ res.z = real * vec.z;
+ return (res);
+}
+
+double vec_scalar_mul(t_vec3 v, t_vec3 u)
+{
+ return (v.x * u.x + v.y * u.y + v.z * u.z);
+}
+
+t_vec3 vec_elwise_mul(t_vec3 v, t_vec3 u)
+{
+ t_vec3 res;
+
+ res.x = v.x * u.x;
+ res.y = v.y * u.y;
+ res.z = v.z * u.z;
+ return (res);
+}
+
+t_vec3 vec_vec_mul(t_vec3 v, t_vec3 u)
+{
+ t_vec3 res;
+
+ res.x = v.y * u.z - v.z * u.y;
+ res.y = v.z * u.x - v.x * u.z;
+ res.z = v.x * u.y - v.y * u.x;
+ return (res);
+}
+
+double vec_norm(t_vec3 vec)
+{
+ return (sqrt(vec_scalar_mul(vec, vec)));
+}