diff options
Diffstat (limited to 'vendor/libftm/src')
| -rw-r--r-- | vendor/libftm/src/ftm_radian.c | 18 | ||||
| -rw-r--r-- | vendor/libftm/src/mat4/ftm_mat4get.c | 18 | ||||
| -rw-r--r-- | vendor/libftm/src/mat4/ftm_mat4init_eye.c | 23 | ||||
| -rw-r--r-- | vendor/libftm/src/mat4/ftm_mat4init_fill.c | 26 | ||||
| -rw-r--r-- | vendor/libftm/src/mat4/ftm_mat4mul.c | 40 | ||||
| -rw-r--r-- | vendor/libftm/src/mat4/ftm_mat4rotate.c | 70 | ||||
| -rw-r--r-- | vendor/libftm/src/mat4/ftm_mat4scale.c | 25 | ||||
| -rw-r--r-- | vendor/libftm/src/mat4/ftm_mat4set.c | 19 | ||||
| -rw-r--r-- | vendor/libftm/src/mat4/ftm_mat4translate.c | 25 | ||||
| -rw-r--r-- | vendor/libftm/src/vec3/ftm_vec3init.c | 21 |
10 files changed, 285 insertions, 0 deletions
diff --git a/vendor/libftm/src/ftm_radian.c b/vendor/libftm/src/ftm_radian.c new file mode 100644 index 0000000..6e1e380 --- /dev/null +++ b/vendor/libftm/src/ftm_radian.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ftm_radian.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/05/12 11:08:29 by charles #+# #+# */ +/* Updated: 2020/05/12 11:19:17 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libftm.h" + +float ftm_radian(float degree) +{ + return ((degree / 180.0) * M_PI); +} diff --git a/vendor/libftm/src/mat4/ftm_mat4get.c b/vendor/libftm/src/mat4/ftm_mat4get.c new file mode 100644 index 0000000..3223788 --- /dev/null +++ b/vendor/libftm/src/mat4/ftm_mat4get.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ftm_mat4get.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/05/12 13:54:08 by charles #+# #+# */ +/* Updated: 2020/05/12 13:54:09 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libftm_mat4.h" + +float ftm_mat4get(t_ftmmat4 *mat4, size_t y, size_t x) +{ + return (mat4->m[y * 4 + x]); +} diff --git a/vendor/libftm/src/mat4/ftm_mat4init_eye.c b/vendor/libftm/src/mat4/ftm_mat4init_eye.c new file mode 100644 index 0000000..d32f075 --- /dev/null +++ b/vendor/libftm/src/mat4/ftm_mat4init_eye.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ftm_mat4init_eye.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/05/12 11:10:44 by charles #+# #+# */ +/* Updated: 2020/05/12 12:17:21 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libftm_mat4.h" + +t_ftmmat4 *ftm_mat4init_eye(t_ftmmat4 *mat4, float x) +{ + ftm_mat4init_fill(mat4, 0.0); + ftm_mat4set(mat4, 0, 0, x); + ftm_mat4set(mat4, 1, 1, x); + ftm_mat4set(mat4, 2, 2, x); + ftm_mat4set(mat4, 3, 3, x); + return (mat4); +} diff --git a/vendor/libftm/src/mat4/ftm_mat4init_fill.c b/vendor/libftm/src/mat4/ftm_mat4init_fill.c new file mode 100644 index 0000000..d7b0b3a --- /dev/null +++ b/vendor/libftm/src/mat4/ftm_mat4init_fill.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ftm_mat4init_fill.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/05/12 12:16:59 by charles #+# #+# */ +/* Updated: 2020/05/12 12:18:01 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libftm_mat4.h" + +t_ftmmat4 *ftm_mat4init_fill(t_ftmmat4 *mat4, float x) +{ + size_t i; + + i = 0; + while (i < 4 * 4) + { + mat4->m[i] = x; + i++; + } + return (mat4); +} diff --git a/vendor/libftm/src/mat4/ftm_mat4mul.c b/vendor/libftm/src/mat4/ftm_mat4mul.c new file mode 100644 index 0000000..553e47c --- /dev/null +++ b/vendor/libftm/src/mat4/ftm_mat4mul.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ftm_mat4mul.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/05/12 11:22:20 by charles #+# #+# */ +/* Updated: 2020/05/12 14:03:19 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libftm_mat4.h" + +static float st_dot(t_ftmmat4 *a, t_ftmmat4 *b, int y, int x) +{ + return (ftm_mat4get(a, y, 0) * ftm_mat4get(b, 0, x) + + ftm_mat4get(a, y, 1) * ftm_mat4get(b, 1, x) + + ftm_mat4get(a, y, 2) * ftm_mat4get(b, 2, x) + + ftm_mat4get(a, y, 3) * ftm_mat4get(b, 3, x)); +} + +t_ftmmat4 *ftm_mat4mul(t_ftmmat4 *dst, t_ftmmat4 *other) +{ + t_ftmmat4 tmp; + int i; + int j; + + i = -1; + while (++i < 4) + { + j = -1; + while (++j < 4) + ftm_mat4set(&tmp, i, j, st_dot(dst, other, i, j)); + } + i = -1; + while (++i < 4 * 4) + dst->m[i] = tmp.m[i]; + return (dst); +} diff --git a/vendor/libftm/src/mat4/ftm_mat4rotate.c b/vendor/libftm/src/mat4/ftm_mat4rotate.c new file mode 100644 index 0000000..0a39c16 --- /dev/null +++ b/vendor/libftm/src/mat4/ftm_mat4rotate.c @@ -0,0 +1,70 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ftm_mat4rotate.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* 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 */ +/* */ +/* ************************************************************************** */ + +#include "libftm_mat4.h" + +/* +** Rotation axis/vector [x, y, z] +** +** 1st column: +** | cos(θ) + x^2 (1 − cos(θ)) | +** | y x (1 − cos(θ)) + z sin(θ) | +** | z x (1 − cos(θ)) − y sin(θ) | +** | 0 | +** +** 2nd column: +** | x y (1 − cos(θ)) − z sin(θ) | +** | cos(θ) + y^2 (1 − cos(θ)) | +** | z y (1 − cos(θ)) + x sin(θ) | +** | 0 | +** +** 3rd column: +** | x z (1 − cos(θ)) + y sin(θ) | +** | y z (1 − cos(θ)) − x sin(θ) | +** | cos(θ) + z^2 (1 − cos(θ)) | +** | 0 | +*/ + +t_ftmmat4 *ftm_mat4rotate(t_ftmmat4 *mat4, float theta, t_ftmvec3 *axis) +{ + float x; + float y; + float z; + float sin_t; + float cos_t; + t_ftmmat4 rot; + + x = axis->v[0]; + y = axis->v[1]; + z = axis->v[2]; + sin_t = sin(theta); + cos_t = cos(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); + ftm_mat4set(&rot, 2, 0, z * x * (1 - cos_t) + y * sin_t); + ftm_mat4set(&rot, 3, 0, 0.0); + + ftm_mat4set(&rot, 0, 1, x * y * (1 - cos_t) - z * sin_t); + ftm_mat4set(&rot, 1, 1, cos_t + y * y * (1 - cos_t)); + ftm_mat4set(&rot, 2, 1, z * y * (1 - cos_t) + x * sin_t); + ftm_mat4set(&rot, 3, 1, 0); + + ftm_mat4set(&rot, 0, 2, x * z * (1 - cos_t) + y * sin_t); + ftm_mat4set(&rot, 1, 2, y * z * (1 - cos_t) - x * sin_t); + ftm_mat4set(&rot, 2, 2, cos_t + z * z * (1 - cos_t)); + ftm_mat4set(&rot, 3, 2, 0); + + ftm_mat4set(&rot, 3, 3, 1.0); + ftm_mat4mul(mat4, &rot); + return (mat4); +} diff --git a/vendor/libftm/src/mat4/ftm_mat4scale.c b/vendor/libftm/src/mat4/ftm_mat4scale.c new file mode 100644 index 0000000..a278c83 --- /dev/null +++ b/vendor/libftm/src/mat4/ftm_mat4scale.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ftm_mat4scale.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/05/12 11:16:19 by charles #+# #+# */ +/* Updated: 2020/05/12 11:18:38 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libftm_mat4.h" + +t_ftmmat4 *ftm_mat4scale(t_ftmmat4 *mat4, float x, float y, float z) +{ + t_ftmmat4 scale; + + ftm_mat4init_eye(&scale, 1.0); + ftm_mat4set(&scale, 0, 0, x); + ftm_mat4set(&scale, 1, 1, y); + ftm_mat4set(&scale, 2, 2, z); + ftm_mat4mul(mat4, &scale); + return (mat4); +} diff --git a/vendor/libftm/src/mat4/ftm_mat4set.c b/vendor/libftm/src/mat4/ftm_mat4set.c new file mode 100644 index 0000000..55e8125 --- /dev/null +++ b/vendor/libftm/src/mat4/ftm_mat4set.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ftm_mat4set.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/05/12 11:21:20 by charles #+# #+# */ +/* Updated: 2020/05/12 11:21:58 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libftm_mat4.h" + +t_ftmmat4 *ftm_mat4set(t_ftmmat4 *mat4, size_t y, size_t x, float value) +{ + mat4->m[y * 4 + x] = value; + return (mat4); +} diff --git a/vendor/libftm/src/mat4/ftm_mat4translate.c b/vendor/libftm/src/mat4/ftm_mat4translate.c new file mode 100644 index 0000000..38a44d9 --- /dev/null +++ b/vendor/libftm/src/mat4/ftm_mat4translate.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ftm_mat4translate.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/05/12 11:12:21 by charles #+# #+# */ +/* Updated: 2020/05/12 11:19:05 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libftm_mat4.h" + +t_ftmmat4 *ftm_mat4translate(t_ftmmat4 *mat4, float x, float y, float z) +{ + t_ftmmat4 trans; + + ftm_mat4init_eye(&trans, 1.0); + ftm_mat4set(&trans, 0, 3, x); + ftm_mat4set(&trans, 1, 3, y); + ftm_mat4set(&trans, 2, 3, z); + ftm_mat4mul(mat4, &trans); + return (mat4); +} diff --git a/vendor/libftm/src/vec3/ftm_vec3init.c b/vendor/libftm/src/vec3/ftm_vec3init.c new file mode 100644 index 0000000..ff5047c --- /dev/null +++ b/vendor/libftm/src/vec3/ftm_vec3init.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ftm_vec3init.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/05/12 11:19:55 by charles #+# #+# */ +/* Updated: 2020/05/12 11:20:53 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libftm_vec3.h" + +t_ftmvec3 *ftm_vec3init(t_ftmvec3 *vec3, float x, float y, float z) +{ + vec3->v[0] = x; + vec3->v[1] = y; + vec3->v[2] = z; + return (vec3); +} |
