aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/shader.c12
-rw-r--r--vendor/libftm/inc/libftm_mat.h39
-rw-r--r--vendor/libftm/inc/libftm_vec.h (renamed from vendor/libftm/inc/libftm_vec3.h)34
-rw-r--r--vendor/libftm/inc/libftm_vec4.h30
-rw-r--r--vendor/libftm/src/mat/ftm_matadd.c30
-rw-r--r--vendor/libftm/src/mat/ftm_matat.c (renamed from vendor/libftm/src/vec4/ftm_vec4dot.c)15
-rw-r--r--vendor/libftm/src/mat/ftm_matdestroy.c (renamed from vendor/libftm/src/vec3/ftm_vec3sub.c)16
-rw-r--r--vendor/libftm/src/mat/ftm_matmul.c (renamed from vendor/libftm/src/vec3/ftm_vec3scale.c)14
-rw-r--r--vendor/libftm/src/mat/ftm_matmulvec.c37
-rw-r--r--vendor/libftm/src/mat/ftm_matnew.c29
-rw-r--r--vendor/libftm/src/mat/ftm_matscale.c (renamed from vendor/libftm/src/vec4/ftm_vec4add.c)24
-rw-r--r--vendor/libftm/src/mat/ftm_matsub.c30
-rw-r--r--vendor/libftm/src/vec/ftm_vecadd.c28
-rw-r--r--vendor/libftm/src/vec/ftm_veccross.c (renamed from vendor/libftm/src/vec3/ftm_vec3cross.c)21
-rw-r--r--vendor/libftm/src/vec/ftm_vecdestroy.c19
-rw-r--r--vendor/libftm/src/vec/ftm_vecdot.c (renamed from vendor/libftm/src/vec3/ftm_vec3dot.c)24
-rw-r--r--vendor/libftm/src/vec/ftm_vecnew.c28
-rw-r--r--vendor/libftm/src/vec/ftm_vecscale.c (renamed from vendor/libftm/src/vec3/ftm_vec3add.c)21
-rw-r--r--vendor/libftm/src/vec/ftm_vecsub.c28
-rw-r--r--vendor/libftm/src/vec4/ftm_vec4scale.c22
-rw-r--r--vendor/libftm/src/vec4/ftm_vec4sub.c22
21 files changed, 377 insertions, 146 deletions
diff --git a/src/shader.c b/src/shader.c
index 4934dcd..2e12a3e 100644
--- a/src/shader.c
+++ b/src/shader.c
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/05/11 09:35:54 by charles #+# #+# */
-/* Updated: 2020/05/11 10:54:14 by charles ### ########.fr */
+/* Updated: 2020/05/11 12:25:16 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -62,3 +62,13 @@ unsigned int shader_new(void)
GL_CALL(glDeleteShader(shader_fragment));
return (program);
}
+
+/* static int shader_uniform_location(unsigned int shader, const char *name) */
+/* { */
+/* int location; */
+/* */
+/* GL_CALL(location = glGetUniformLocation(shader, name)); */
+/* return (location); */
+/* } */
+
+/* void shader_uniform_matrix4( */
diff --git a/vendor/libftm/inc/libftm_mat.h b/vendor/libftm/inc/libftm_mat.h
new file mode 100644
index 0000000..63679bb
--- /dev/null
+++ b/vendor/libftm/inc/libftm_mat.h
@@ -0,0 +1,39 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* libftm_mat.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/05/11 12:50:40 by charles #+# #+# */
+/* Updated: 2020/05/11 13:28:55 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef LIBFTM_MAT_H
+# define LIBFTM_MAT_H
+
+# include <stddef.h>
+# include <stdlib.h>
+# include "libftm_vec.h"
+
+typedef struct s_ftmmat
+{
+ float *m;
+ struct
+ {
+ size_t x;
+ size_t y;
+ } shape;
+} t_ftmmat;
+
+t_ftmmat *ftm_matnew(size_t y, size_t x);
+void ftm_matdestroy(t_ftmmat *mat);
+t_ftmmat *ftm_matadd(t_ftmmat *dst, t_ftmmat *other);
+t_ftmmat *ftm_matsub(t_ftmmat *dst, t_ftmmat *other);
+t_ftmmat *ftm_matscale(t_ftmmat *dst, float scalar);
+t_ftmmat *ftm_matmul(t_ftmmat *dst, t_ftmmat *other);
+t_ftmvec *ftm_matmulvec(t_ftmmat *mat, t_ftmvec *dst);
+float ftm_matat(t_ftmmat *mat, size_t y, size_t x);
+
+#endif
diff --git a/vendor/libftm/inc/libftm_vec3.h b/vendor/libftm/inc/libftm_vec.h
index fc86dcb..805cb25 100644
--- a/vendor/libftm/inc/libftm_vec3.h
+++ b/vendor/libftm/inc/libftm_vec.h
@@ -1,31 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* libftm_vec3.h :+: :+: :+: */
+/* libftm_vec.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/05/09 20:38:30 by charles #+# #+# */
-/* Updated: 2020/05/09 21:12:05 by charles ### ########.fr */
+/* Created: 2020/05/11 13:27:54 by charles #+# #+# */
+/* Updated: 2020/05/11 13:28:27 by charles ### ########.fr */
/* */
/* ************************************************************************** */
-#ifndef LIBFTM_VEC3_H
-# define LIBFTM_VEC3_H
+#ifndef LIBFTM_VEC_H
+# define LIBFTM_VEC_H
+
+# include <stdlib.h>
+# include <stddef.h>
/*
-** \brief 3 component vector [x, y, z]
+** \brief component vector [x, y, z]
*/
-typedef struct
+typedef struct s_ftmvec
{
- float v[3];
-} t_ftmvec3;
+ float *v;
+ size_t size;
+} t_ftmvec;
-t_ftmvec3 *ftm_vec3add(t_ftmvec3 *dst, t_ftmvec3 *other);
-t_ftmvec3 *ftm_vec3sub(t_ftmvec3 *dst, t_ftmvec3 *other);
-float ftm_vec3dot(t_ftmvec3 *a, t_ftmvec3 *b);
-void ftm_vec3cross(t_ftmvec3 *dst, t_ftmvec3 *a, t_ftmvec3 *b);
-t_ftmvec3 *ftm_vec3scale(t_ftmvec3 *dst, float scalar);
+t_ftmvec *ftm_vecnew(size_t size);
+void ftm_vecdestroy(t_ftmvec *vec);
+t_ftmvec *ftm_vecadd(t_ftmvec *dst, t_ftmvec *other);
+t_ftmvec *ftm_vecsub(t_ftmvec *dst, t_ftmvec *other);
+float ftm_vecdot(t_ftmvec *a, t_ftmvec *b);
+t_ftmvec *ftm_veccross(t_ftmvec *a, t_ftmvec *b);
+t_ftmvec *ftm_vecscale(t_ftmvec *dst, float scalar);
#endif
diff --git a/vendor/libftm/inc/libftm_vec4.h b/vendor/libftm/inc/libftm_vec4.h
deleted file mode 100644
index e89bd89..0000000
--- a/vendor/libftm/inc/libftm_vec4.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* libftm.h :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/05/09 20:48:30 by charles #+# #+# */
-/* Updated: 2020/05/09 21:11:12 by charles ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#ifndef LIBFTM_VEC4_H
-# define LIBFTM_VEC4_H
-
-/*
-** \brief 4 component vector [x, y, z, w]
-*/
-
-typedef struct
-{
- float v[4];
-} t_ftmvec4;
-
-t_ftmvec4 *ftm_vec4add(t_ftmvec4 *dst, t_ftmvec4 *other);
-t_ftmvec4 *ftm_vec4sub(t_ftmvec4 *dst, t_ftmvec4 *other);
-float ftm_vec4dot(t_ftmvec4 *a, t_ftmvec4 *b);
-t_ftmvec4 *ftm_vec4scale(t_ftmvec4 *dst, float scalar);
-
-#endif
diff --git a/vendor/libftm/src/mat/ftm_matadd.c b/vendor/libftm/src/mat/ftm_matadd.c
new file mode 100644
index 0000000..97352a3
--- /dev/null
+++ b/vendor/libftm/src/mat/ftm_matadd.c
@@ -0,0 +1,30 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ftm_matadd.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/05/11 12:56:00 by charles #+# #+# */
+/* Updated: 2020/05/11 13:06:50 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libftm_mat.h"
+
+t_ftmmat *ftm_matadd(t_ftmmat *dst, t_ftmmat *other)
+{
+ size_t i;
+ size_t size;
+
+ if (dst->shape.x != other->shape.x || dst->shape.y != other->shape.y)
+ return (NULL);
+ size = dst->shape.x * dst->shape.y;
+ i = 0;
+ while (i < size)
+ {
+ dst->m[i] += other->m[i];
+ i++;
+ }
+ return (dst);
+}
diff --git a/vendor/libftm/src/vec4/ftm_vec4dot.c b/vendor/libftm/src/mat/ftm_matat.c
index dc8864a..0c77ced 100644
--- a/vendor/libftm/src/vec4/ftm_vec4dot.c
+++ b/vendor/libftm/src/mat/ftm_matat.c
@@ -1,21 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ftm_vec4dot.c :+: :+: :+: */
+/* ftm_matat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/05/09 21:06:09 by charles #+# #+# */
-/* Updated: 2020/05/09 21:15:32 by charles ### ########.fr */
+/* Created: 2020/05/11 13:11:34 by charles #+# #+# */
+/* Updated: 2020/05/11 13:27:17 by charles ### ########.fr */
/* */
/* ************************************************************************** */
-#include "libftm_vec4.h"
+#include "libftm_mat.h"
-float ftm_vec4dot(t_ftmvec4 *a, t_ftmvec4 *b)
+float ftm_matat(t_ftmmat *mat, size_t y, size_t x)
{
- return (a->v[0] * b->v[0] +
- a->v[1] * b->v[1] +
- a->v[2] * b->v[2] +
- a->v[3] * b->v[3]);
+ return (mat->m[y * mat->shape.x + x]);
}
diff --git a/vendor/libftm/src/vec3/ftm_vec3sub.c b/vendor/libftm/src/mat/ftm_matdestroy.c
index 880acbc..4d39270 100644
--- a/vendor/libftm/src/vec3/ftm_vec3sub.c
+++ b/vendor/libftm/src/mat/ftm_matdestroy.c
@@ -1,21 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ftm_vec3sub.c :+: :+: :+: */
+/* ftm_matdestroy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/05/09 20:57:33 by charles #+# #+# */
-/* Updated: 2020/05/09 21:14:20 by charles ### ########.fr */
+/* Created: 2020/05/11 12:56:00 by charles #+# #+# */
+/* Updated: 2020/05/11 12:59:41 by charles ### ########.fr */
/* */
/* ************************************************************************** */
-#include "libftm_vec3.h"
+#include "libftm_mat.h"
-t_ftmvec3 *ftm_vec3sub(t_ftmvec3 *dst, t_ftmvec3 *other)
+void ftm_matdestroy(t_ftmmat *mat)
{
- dst->v[0] -= other->v[0];
- dst->v[1] -= other->v[1];
- dst->v[2] -= other->v[2];
- return (dst);
+ free(mat->m);
+ free(mat);
}
diff --git a/vendor/libftm/src/vec3/ftm_vec3scale.c b/vendor/libftm/src/mat/ftm_matmul.c
index 8782675..0d26a20 100644
--- a/vendor/libftm/src/vec3/ftm_vec3scale.c
+++ b/vendor/libftm/src/mat/ftm_matmul.c
@@ -1,21 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ftm_vec3scale.c :+: :+: :+: */
+/* ftm_matmul.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/05/09 21:00:32 by charles #+# #+# */
-/* Updated: 2020/05/09 21:14:10 by charles ### ########.fr */
+/* Created: 2020/05/11 12:56:00 by charles #+# #+# */
+/* Updated: 2020/05/11 13:27:08 by charles ### ########.fr */
/* */
/* ************************************************************************** */
-#include "libftm_vec3.h"
+#include "libftm_mat.h"
-t_ftmvec3 *ftm_vec3scale(t_ftmvec3 *dst, float scalar)
+t_ftmmat *ftm_matmul(t_ftmmat *dst, t_ftmmat *other)
{
- dst->v[0] *= scalar;
- dst->v[1] *= scalar;
- dst->v[2] *= scalar;
+ (void)other;
return (dst);
}
diff --git a/vendor/libftm/src/mat/ftm_matmulvec.c b/vendor/libftm/src/mat/ftm_matmulvec.c
new file mode 100644
index 0000000..48af456
--- /dev/null
+++ b/vendor/libftm/src/mat/ftm_matmulvec.c
@@ -0,0 +1,37 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ftm_matmulvec.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/05/11 12:56:00 by charles #+# #+# */
+/* Updated: 2020/05/11 13:18:10 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libftm_mat.h"
+
+t_ftmvec *ftm_matmulvec(t_ftmmat *mat, t_ftmvec *dst)
+{
+ size_t i;
+ t_ftmmat *tmp;
+
+ if ((tmp = ftm_matnew(dst->size, 1)) == NULL)
+ return (NULL);
+ i = 0;
+ while (i < dst->size)
+ {
+ tmp->m[i] = dst->v[i];
+ i++;
+ }
+ if (ftm_matmul(tmp, mat) == NULL)
+ return (NULL);
+ i = 0;
+ while (i < dst->size)
+ {
+ dst->v[i] = tmp->m[i];
+ i++;
+ }
+ return (dst);
+}
diff --git a/vendor/libftm/src/mat/ftm_matnew.c b/vendor/libftm/src/mat/ftm_matnew.c
new file mode 100644
index 0000000..c7ddb36
--- /dev/null
+++ b/vendor/libftm/src/mat/ftm_matnew.c
@@ -0,0 +1,29 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ftm_matnew.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/05/11 12:56:00 by charles #+# #+# */
+/* Updated: 2020/05/11 13:13:27 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libftm_mat.h"
+
+t_ftmmat *ftm_matnew(size_t y, size_t x)
+{
+ t_ftmmat *mat;
+
+ if ((mat = malloc(sizeof(t_ftmmat))) == NULL)
+ return (NULL);
+ if ((mat->m = malloc(sizeof(float) * x * y)) == NULL)
+ {
+ free(mat);
+ return (NULL);
+ }
+ mat->shape.y = y;
+ mat->shape.x = x;
+ return (mat);
+}
diff --git a/vendor/libftm/src/vec4/ftm_vec4add.c b/vendor/libftm/src/mat/ftm_matscale.c
index bf8ef1d..8347e1a 100644
--- a/vendor/libftm/src/vec4/ftm_vec4add.c
+++ b/vendor/libftm/src/mat/ftm_matscale.c
@@ -1,22 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ftm_vec4add.c :+: :+: :+: */
+/* ftm_matscale.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/05/09 20:45:59 by charles #+# #+# */
-/* Updated: 2020/05/09 21:15:07 by charles ### ########.fr */
+/* Created: 2020/05/11 12:56:00 by charles #+# #+# */
+/* Updated: 2020/05/11 13:07:25 by charles ### ########.fr */
/* */
/* ************************************************************************** */
-#include "libftm_vec4.h"
+#include "libftm_mat.h"
-t_ftmvec4 *ftm_vec4add(t_ftmvec4 *dst, t_ftmvec4 *other)
+t_ftmmat *ftm_matscale(t_ftmmat *dst, float scalar)
{
- dst->v[0] += other->v[0];
- dst->v[1] += other->v[1];
- dst->v[2] += other->v[2];
- dst->v[3] += other->v[3];
+ size_t i;
+ size_t size;
+
+ size = dst->shape.x * dst->shape.y;
+ i = 0;
+ while (i < size)
+ {
+ dst->m[i] *= scalar;
+ i++;
+ }
return (dst);
}
diff --git a/vendor/libftm/src/mat/ftm_matsub.c b/vendor/libftm/src/mat/ftm_matsub.c
new file mode 100644
index 0000000..54ad900
--- /dev/null
+++ b/vendor/libftm/src/mat/ftm_matsub.c
@@ -0,0 +1,30 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ftm_matsub.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/05/11 12:56:00 by charles #+# #+# */
+/* Updated: 2020/05/11 13:06:43 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libftm_mat.h"
+
+t_ftmmat *ftm_matsub(t_ftmmat *dst, t_ftmmat *other)
+{
+ size_t i;
+ size_t size;
+
+ if (dst->shape.x != other->shape.x || dst->shape.y != other->shape.y)
+ return (NULL);
+ size = dst->shape.x * dst->shape.y;
+ i = 0;
+ while (i < size)
+ {
+ dst->m[i] -= other->m[i];
+ i++;
+ }
+ return (dst);
+}
diff --git a/vendor/libftm/src/vec/ftm_vecadd.c b/vendor/libftm/src/vec/ftm_vecadd.c
new file mode 100644
index 0000000..e776d21
--- /dev/null
+++ b/vendor/libftm/src/vec/ftm_vecadd.c
@@ -0,0 +1,28 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ftm_vecadd.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/05/11 12:39:47 by charles #+# #+# */
+/* Updated: 2020/05/11 12:39:49 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libftm_vec.h"
+
+t_ftmvec *ftm_vecadd(t_ftmvec *dst, t_ftmvec *other)
+{
+ size_t i;
+
+ if (dst->size != other->size)
+ return (NULL);
+ i = 0;
+ while (i < dst->size)
+ {
+ dst->v[i] += other->v[i];
+ i++;
+ }
+ return (dst);
+}
diff --git a/vendor/libftm/src/vec3/ftm_vec3cross.c b/vendor/libftm/src/vec/ftm_veccross.c
index c27534e..48dda5f 100644
--- a/vendor/libftm/src/vec3/ftm_vec3cross.c
+++ b/vendor/libftm/src/vec/ftm_veccross.c
@@ -1,26 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ftm_vec3cross.c :+: :+: :+: */
+/* ftm_veccross.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/05/09 21:20:41 by charles #+# #+# */
-/* Updated: 2020/05/09 21:25:44 by charles ### ########.fr */
+/* Updated: 2020/05/11 12:43:33 by charles ### ########.fr */
/* */
/* ************************************************************************** */
-#include "libftm_vec3.h"
+#include "libftm_vec.h"
/*
-** s1 = a2 * b3 - a3 * b2
-** s2 = a3 * b1 - a1 * b3
-** s3 = a1 * b2 - a2 * b1
+** s1 = a2 * b - a * b2
+** s2 = a * b1 - a1 * b
+** s = a1 * b2 - a2 * b1
*/
-void ftm_vec3cross(t_ftmvec3 *dst, t_ftmvec3 *a, t_ftmvec3 *b)
+t_ftmvec *ftm_veccross(t_ftmvec *a, t_ftmvec *b)
{
+ t_ftmvec *dst;
+
+ if (a->size != 3 || b->size != 3)
+ return (NULL);
+ if ((dst = ftm_vecnew(3)) == NULL)
+ return (NULL);
dst->v[0] = a->v[1] * b->v[2] - a->v[2] * b->v[1];
dst->v[1] = a->v[2] * b->v[0] - a->v[0] * b->v[2];
dst->v[2] = a->v[0] * b->v[1] - a->v[1] * b->v[0];
+ return (dst);
}
diff --git a/vendor/libftm/src/vec/ftm_vecdestroy.c b/vendor/libftm/src/vec/ftm_vecdestroy.c
new file mode 100644
index 0000000..38caf23
--- /dev/null
+++ b/vendor/libftm/src/vec/ftm_vecdestroy.c
@@ -0,0 +1,19 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ftm_vecdestroy.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/05/11 12:46:01 by charles #+# #+# */
+/* Updated: 2020/05/11 12:49:39 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libftm_vec.h"
+
+void ftm_vecdestroy(t_ftmvec *vec)
+{
+ free(vec->v);
+ free(vec);
+}
diff --git a/vendor/libftm/src/vec3/ftm_vec3dot.c b/vendor/libftm/src/vec/ftm_vecdot.c
index 5d67ce6..c2f03f0 100644
--- a/vendor/libftm/src/vec3/ftm_vec3dot.c
+++ b/vendor/libftm/src/vec/ftm_vecdot.c
@@ -1,20 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ftm_vec3dot.c :+: :+: :+: */
+/* ftm_vecdot.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/05/09 21:06:09 by charles #+# #+# */
-/* Updated: 2020/05/09 21:14:44 by charles ### ########.fr */
+/* Updated: 2020/05/11 12:48:12 by charles ### ########.fr */
/* */
/* ************************************************************************** */
-#include "libftm_vec3.h"
+#include "libftm_vec.h"
-float ftm_vec3dot(t_ftmvec3 *a, t_ftmvec3 *b)
+float ftm_vecdot(t_ftmvec *a, t_ftmvec *b)
{
- return (a->v[0] * b->v[0] +
- a->v[1] * b->v[1] +
- a->v[2] * b->v[2]);
+ size_t i;
+ float total;
+
+ if (a->size != b->size)
+ return (0.0);
+ total = 0.0;
+ i = 0;
+ while (i < a->size)
+ {
+ total += a->v[i] * b->v[i];
+ i++;
+ }
+ return (total);
}
diff --git a/vendor/libftm/src/vec/ftm_vecnew.c b/vendor/libftm/src/vec/ftm_vecnew.c
new file mode 100644
index 0000000..422b01d
--- /dev/null
+++ b/vendor/libftm/src/vec/ftm_vecnew.c
@@ -0,0 +1,28 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ftm_vecnew.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/05/11 12:44:38 by charles #+# #+# */
+/* Updated: 2020/05/11 12:49:30 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libftm_vec.h"
+
+t_ftmvec *ftm_vecnew(size_t size)
+{
+ t_ftmvec *dst;
+
+ if ((dst = malloc(sizeof(t_ftmvec))) == NULL)
+ return (NULL);
+ if ((dst->v = malloc(sizeof(float) * size)) == NULL)
+ {
+ free(dst);
+ return (NULL);
+ }
+ dst->size = size;
+ return (dst);
+}
diff --git a/vendor/libftm/src/vec3/ftm_vec3add.c b/vendor/libftm/src/vec/ftm_vecscale.c
index 9b5bd09..508a245 100644
--- a/vendor/libftm/src/vec3/ftm_vec3add.c
+++ b/vendor/libftm/src/vec/ftm_vecscale.c
@@ -1,21 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ftm_vec3add.c :+: :+: :+: */
+/* ftm_vecscale.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/05/09 20:35:59 by charles #+# #+# */
-/* Updated: 2020/05/09 21:14:12 by charles ### ########.fr */
+/* Created: 2020/05/11 12:41:11 by charles #+# #+# */
+/* Updated: 2020/05/11 12:48:43 by charles ### ########.fr */
/* */
/* ************************************************************************** */
-#include "libftm_vec3.h"
+#include "libftm_vec.h"
-t_ftmvec3 *ftm_vec3add(t_ftmvec3 *dst, t_ftmvec3 *other)
+t_ftmvec *ftm_vecscale(t_ftmvec *dst, float scalar)
{
- dst->v[0] += other->v[0];
- dst->v[1] += other->v[1];
- dst->v[2] += other->v[2];
+ size_t i;
+
+ i = 0;
+ while (i < dst->size)
+ {
+ dst->v[i] *= scalar;
+ i++;
+ }
return (dst);
}
diff --git a/vendor/libftm/src/vec/ftm_vecsub.c b/vendor/libftm/src/vec/ftm_vecsub.c
new file mode 100644
index 0000000..0ac8ae1
--- /dev/null
+++ b/vendor/libftm/src/vec/ftm_vecsub.c
@@ -0,0 +1,28 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ftm_vecsub.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/05/11 12:39:42 by charles #+# #+# */
+/* Updated: 2020/05/11 12:49:58 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libftm_vec.h"
+
+t_ftmvec *ftm_vecsub(t_ftmvec *dst, t_ftmvec *other)
+{
+ size_t i;
+
+ if (dst->size != other->size)
+ return (NULL);
+ i = 0;
+ while (i < dst->size)
+ {
+ dst->v[i] -= other->v[i];
+ i++;
+ }
+ return (dst);
+}
diff --git a/vendor/libftm/src/vec4/ftm_vec4scale.c b/vendor/libftm/src/vec4/ftm_vec4scale.c
deleted file mode 100644
index ddff937..0000000
--- a/vendor/libftm/src/vec4/ftm_vec4scale.c
+++ /dev/null
@@ -1,22 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ftm_vec4scale.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/05/09 21:00:42 by charles #+# #+# */
-/* Updated: 2020/05/09 21:15:21 by charles ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "libftm_vec4.h"
-
-t_ftmvec4 *ftm_vec4scale(t_ftmvec4 *dst, float scalar)
-{
- dst->v[0] *= scalar;
- dst->v[1] *= scalar;
- dst->v[2] *= scalar;
- dst->v[3] *= scalar;
- return (dst);
-}
diff --git a/vendor/libftm/src/vec4/ftm_vec4sub.c b/vendor/libftm/src/vec4/ftm_vec4sub.c
deleted file mode 100644
index 8082ddd..0000000
--- a/vendor/libftm/src/vec4/ftm_vec4sub.c
+++ /dev/null
@@ -1,22 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ftm_vec4sub.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/05/09 20:57:43 by charles #+# #+# */
-/* Updated: 2020/05/09 21:15:13 by charles ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "libftm_vec4.h"
-
-t_ftmvec4 *ftm_vec4sub(t_ftmvec4 *dst, t_ftmvec4 *other)
-{
- dst->v[0] -= other->v[0];
- dst->v[1] -= other->v[1];
- dst->v[2] -= other->v[2];
- dst->v[3] -= other->v[3];
- return (dst);
-}