aboutsummaryrefslogtreecommitdiff
path: root/vendor/libftm/src/mat4
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/libftm/src/mat4')
-rw-r--r--vendor/libftm/src/mat4/ftm_mat4init_frustum.c27
-rw-r--r--vendor/libftm/src/mat4/ftm_mat4init_frustum_sym.c26
-rw-r--r--vendor/libftm/src/mat4/ftm_mat4init_perspective.c25
-rw-r--r--vendor/libftm/src/mat4/ftm_mat4init_proj.c0
-rw-r--r--vendor/libftm/src/mat4/ftm_mat4rotate.c6
5 files changed, 81 insertions, 3 deletions
diff --git a/vendor/libftm/src/mat4/ftm_mat4init_frustum.c b/vendor/libftm/src/mat4/ftm_mat4init_frustum.c
new file mode 100644
index 0000000..1ba30b2
--- /dev/null
+++ b/vendor/libftm/src/mat4/ftm_mat4init_frustum.c
@@ -0,0 +1,27 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ftm_mat4init_frustum.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/05/12 15:37:26 by charles #+# #+# */
+/* Updated: 2020/05/12 17:29:53 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libftm_mat4.h"
+
+t_ftmmat4 *ftm_mat4init_frustum(t_ftmmat4 *mat4, t_ftmfrustum *frustum)
+{
+ ftm_mat4init_fill(mat4, 0.0);
+
+ ftm_mat4set(mat4, 0, 0, (2.0 * frustum->near) / (frustum->right - frustum->left));
+ ftm_mat4set(mat4, 1, 1, (2.0 * frustum->near) / (frustum->top - frustum->bottom));
+ ftm_mat4set(mat4, 2, 2, (-(frustum->far + frustum->near)) / (frustum->far - frustum->near));
+ ftm_mat4set(mat4, 0, 2, (frustum->right + frustum->left) / (frustum->right - frustum->left));
+ ftm_mat4set(mat4, 1, 2, (frustum->top + frustum->bottom) / (frustum->top - frustum->bottom));
+ ftm_mat4set(mat4, 2, 3, (-2.0 * frustum->far * frustum->near) / (frustum->far - frustum->near));
+ ftm_mat4set(mat4, 3, 2, -1.0);
+ return (mat4);
+}
diff --git a/vendor/libftm/src/mat4/ftm_mat4init_frustum_sym.c b/vendor/libftm/src/mat4/ftm_mat4init_frustum_sym.c
new file mode 100644
index 0000000..2763765
--- /dev/null
+++ b/vendor/libftm/src/mat4/ftm_mat4init_frustum_sym.c
@@ -0,0 +1,26 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ftm_mat4init_frustum_sym.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/05/12 15:47:45 by charles #+# #+# */
+/* Updated: 2020/05/12 17:21:06 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libftm_mat4.h"
+
+t_ftmmat4 *ftm_mat4init_frustum_sym(t_ftmmat4 *mat4, t_ftmfrustum_sym *frustum)
+{
+ t_ftmfrustum f;
+
+ f.right = frustum->width / 2;
+ f.left = -f.right;
+ f.top = frustum->height / 2;
+ f.bottom = -f.top;
+ f.near = frustum->near;
+ f.far = frustum->far;
+ return (ftm_mat4init_frustum(mat4, &f));
+}
diff --git a/vendor/libftm/src/mat4/ftm_mat4init_perspective.c b/vendor/libftm/src/mat4/ftm_mat4init_perspective.c
new file mode 100644
index 0000000..f04b39e
--- /dev/null
+++ b/vendor/libftm/src/mat4/ftm_mat4init_perspective.c
@@ -0,0 +1,25 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ftm_mat4init_perspective.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/05/12 16:54:49 by charles #+# #+# */
+/* Updated: 2020/05/12 19:07:45 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libftm_mat4.h"
+
+t_ftmmat4 *ftm_mat4init_perspective(t_ftmmat4 *mat4, float fov, float aspect_ratio,
+ float near, float far)
+{
+ t_ftmfrustum_sym frustum;
+
+ frustum.near = near;
+ frustum.far = far;
+ frustum.width = 2.0 * (near / tanf(M_PI_2 - (fov / 2.0)));
+ frustum.height = frustum.width / aspect_ratio;
+ return (ftm_mat4init_frustum_sym(mat4, &frustum));
+}
diff --git a/vendor/libftm/src/mat4/ftm_mat4init_proj.c b/vendor/libftm/src/mat4/ftm_mat4init_proj.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/vendor/libftm/src/mat4/ftm_mat4init_proj.c
diff --git a/vendor/libftm/src/mat4/ftm_mat4rotate.c b/vendor/libftm/src/mat4/ftm_mat4rotate.c
index 0a39c16..6d0432e 100644
--- a/vendor/libftm/src/mat4/ftm_mat4rotate.c
+++ b/vendor/libftm/src/mat4/ftm_mat4rotate.c
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/05/12 11:44:18 by charles #+# #+# */
-/* Updated: 2020/05/12 14:05:18 by charles ### ########.fr */
+/* Updated: 2020/05/12 17:07:23 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -46,8 +46,8 @@ t_ftmmat4 *ftm_mat4rotate(t_ftmmat4 *mat4, float theta, t_ftmvec3 *axis)
x = axis->v[0];
y = axis->v[1];
z = axis->v[2];
- sin_t = sin(theta);
- cos_t = cos(theta);
+ sin_t = sinf(theta);
+ cos_t = cosf(theta);
ftm_mat4init_fill(&rot, 0.0);
ftm_mat4set(&rot, 0, 0, cos_t + x * x * (1 - cos_t));
ftm_mat4set(&rot, 1, 0, y * x * (1 - cos_t) + z * sin_t);