aboutsummaryrefslogtreecommitdiff
path: root/mons_math/include
diff options
context:
space:
mode:
Diffstat (limited to 'mons_math/include')
-rw-r--r--mons_math/include/mons_math/mat2.h39
-rw-r--r--mons_math/include/mons_math/mat3.h41
-rw-r--r--mons_math/include/mons_math/mat4.h57
-rw-r--r--mons_math/include/mons_math/matrix.h8
-rw-r--r--mons_math/include/mons_math/quat.h44
-rw-r--r--mons_math/include/mons_math/util.h8
-rw-r--r--mons_math/include/mons_math/vec2.h46
-rw-r--r--mons_math/include/mons_math/vec3.h56
-rw-r--r--mons_math/include/mons_math/vec4.h53
-rw-r--r--mons_math/include/mons_math/vector.h8
10 files changed, 360 insertions, 0 deletions
diff --git a/mons_math/include/mons_math/mat2.h b/mons_math/include/mons_math/mat2.h
new file mode 100644
index 0000000..b1a8ca0
--- /dev/null
+++ b/mons_math/include/mons_math/mat2.h
@@ -0,0 +1,39 @@
+#ifndef MONS_MAT2_H
+#define MONS_MAT2_H
+
+#include "mons_math/vec2.h"
+
+typedef struct mons_mat2 {
+ mons_vec2 m1;
+ mons_vec2 m2;
+} mons_mat2;
+
+mons_mat2 mons_mat2_add(mons_mat2 a, mons_mat2 b);
+void mons_mat2_add_inplace(mons_mat2 *a, mons_mat2 b);
+
+mons_mat2 mons_mat2_mul_f(mons_mat2 a, float b);
+mons_mat2 mons_mat2_mul_i(mons_mat2 a, int b);
+mons_mat2 mons_mat2_mul(mons_mat2 a, mons_mat2 b);
+
+void mons_mat2_mul_f_inplace(mons_mat2 *a, float b);
+void mons_mat2_mul_i_inplace(mons_mat2 *a, int b);
+
+mons_mat2 mons_mat2_inverse(mons_mat2 a);
+void mons_mat2_inverse_inplace(mons_mat2 *a);
+
+mons_mat2 mons_mat2_transpose(mons_mat2 a);
+void mons_mat2_transpose_inplace(mons_mat2 *a);
+
+mons_vec2 mons_mat2_n1(mons_mat2 a);
+mons_vec2 mons_mat2_n2(mons_mat2 a);
+
+float mons_mat2_determinant(mons_mat2 a);
+mons_mat2 mons_mat2_adjoint(mons_mat2 a);
+mons_mat2 mons_mat2_inverse(mons_mat2 a);
+
+extern const mons_mat2 MONS_MAT2_ZERO;
+extern const mons_mat2 MONS_MAT2_IDENTITY;
+
+int mons_mat2_equal(mons_mat2 a, mons_mat2 b);
+
+#endif
diff --git a/mons_math/include/mons_math/mat3.h b/mons_math/include/mons_math/mat3.h
new file mode 100644
index 0000000..9ca4a64
--- /dev/null
+++ b/mons_math/include/mons_math/mat3.h
@@ -0,0 +1,41 @@
+#ifndef MONS_MAT3_H
+#define MONS_MAT3_H
+
+#include "mons_math/vec3.h"
+
+typedef struct mons_mat3 {
+ mons_vec3 m1;
+ mons_vec3 m2;
+ mons_vec3 m3;
+} mons_mat3;
+
+mons_mat3 mons_mat3_add(mons_mat3 a, mons_mat3 b);
+void mons_mat3_add_inplace(mons_mat3 *a, mons_mat3 b);
+
+mons_mat3 mons_mat3_mul_f(mons_mat3 a, float b);
+mons_mat3 mons_mat3_mul_i(mons_mat3 a, int b);
+mons_mat3 mons_mat3_mul(mons_mat3 a, mons_mat3 b);
+
+void mons_mat3_mul_f_inplace(mons_mat3 *a, float b);
+void mons_mat3_mul_i_inplace(mons_mat3 *a, int b);
+
+mons_mat3 mons_mat3_inverse(mons_mat3 a);
+
+mons_mat3 mons_mat3_transpose(mons_mat3 a);
+void mons_mat3_transpose_inplace(mons_mat3 *a);
+
+mons_vec3 mons_mat3_n1(mons_mat3 a);
+mons_vec3 mons_mat3_n2(mons_mat3 a);
+mons_vec3 mons_mat3_n3(mons_mat3 a);
+
+float mons_mat3_determinant(mons_mat3 a);
+mons_mat3 mons_mat3_minor(mons_mat3 a);
+mons_mat3 mons_mat3_cofactor(mons_mat3 a);
+mons_mat3 mons_mat3_adjoint(mons_mat3 a);
+
+extern const mons_mat3 MONS_MAT3_ZERO;
+extern const mons_mat3 MONS_MAT3_IDENTITY;
+
+int mons_mat3_equal(mons_mat3 a, mons_mat3 b);
+
+#endif
diff --git a/mons_math/include/mons_math/mat4.h b/mons_math/include/mons_math/mat4.h
new file mode 100644
index 0000000..0b949fe
--- /dev/null
+++ b/mons_math/include/mons_math/mat4.h
@@ -0,0 +1,57 @@
+#ifndef MONS_MATH_MATRIX_H
+#define MONS_MATH_MATRIX_H
+
+#include "mons_math/vec4.h"
+
+typedef struct mons_mat4 {
+ mons_vec4 m1;
+ mons_vec4 m2;
+ mons_vec4 m3;
+ mons_vec4 m4;
+} mons_mat4;
+
+mons_mat4 mons_mat4_add(mons_mat4 a, mons_mat4 b);
+void mons_mat4_add_inplace(mons_mat4 *a, mons_mat4 b);
+
+mons_mat4 mons_mat4_mul_f(mons_mat4 a, float b);
+mons_mat4 mons_mat4_mul_i(mons_mat4 a, int b);
+mons_mat4 mons_mat4_mul(mons_mat4 a, mons_mat4 b);
+void mons_mat4_mul_inplace(mons_mat4 *a, mons_mat4 b);
+
+void mons_mat4_mul_f_inplace(mons_mat4 *a, float b);
+void mons_mat4_mul_i_inplace(mons_mat4 *a, int b);
+
+mons_mat4 mons_mat4_inverse(mons_mat4 a);
+
+mons_mat4 mons_mat4_transpose(mons_mat4 a);
+void mons_mat4_transpose_inplace(mons_mat4 *a);
+
+mons_vec4 mons_mat4_n1(mons_mat4 a);
+mons_vec4 mons_mat4_n2(mons_mat4 a);
+mons_vec4 mons_mat4_n3(mons_mat4 a);
+mons_vec4 mons_mat4_n4(mons_mat4 a);
+
+float mons_mat4_determinant(mons_mat4 a);
+
+extern const mons_mat4 MONS_MAT4_ZERO;
+extern const mons_mat4 MONS_MAT4_IDENTITY;
+
+int mons_mat4_equal(mons_mat4 a, mons_mat4 b);
+
+void mons_mat4_print(mons_mat4 mat);
+
+#define MONS_MAT4_ZERO {\
+ { 0, 0, 0, 0 },\
+ { 0, 0, 0, 0 },\
+ { 0, 0, 0, 0 },\
+ { 0, 0, 0, 0 },\
+}
+
+#define MONS_MAT4_IDENTITY {\
+ { 1, 0, 0, 0 },\
+ { 0, 1, 0, 0 },\
+ { 0, 0, 1, 0 },\
+ { 0, 0, 0, 1 },\
+}
+
+#endif
diff --git a/mons_math/include/mons_math/matrix.h b/mons_math/include/mons_math/matrix.h
new file mode 100644
index 0000000..48fdec6
--- /dev/null
+++ b/mons_math/include/mons_math/matrix.h
@@ -0,0 +1,8 @@
+#ifndef MONS_MATRIX_H
+#define MONS_MATRIX_H
+
+#include "mat2.h"
+#include "mat3.h"
+#include "mat4.h"
+
+#endif
diff --git a/mons_math/include/mons_math/quat.h b/mons_math/include/mons_math/quat.h
new file mode 100644
index 0000000..353d7bb
--- /dev/null
+++ b/mons_math/include/mons_math/quat.h
@@ -0,0 +1,44 @@
+#ifndef MONS_QUAT_H
+#define MONS_QUAT_H
+
+struct mons_vec3;
+
+typedef struct mons_quat {
+ float x;
+ float y;
+ float z;
+ float w;
+} mons_quat;
+
+mons_quat mons_quat_from_axis_angle(struct mons_vec3 axis, float angle);
+
+mons_quat mons_quat_mul(mons_quat a, mons_quat b);
+
+void mons_quat_mul_inplace(mons_quat *a, mons_quat b);
+
+mons_quat mons_quat_mul_f(mons_quat a, float b);
+
+void mons_quat_mul_f_inplace(mons_quat *a, float b);
+
+mons_quat mons_quat_mul_i(mons_quat a, int b);
+
+void mons_quat_mul_i_inplace(mons_quat *a, int b);
+
+struct mons_mat4 mons_quat_to_mat4(mons_quat a);
+
+mons_quat mons_quat_normalize(mons_quat a);
+
+void mons_quat_normalize_inplace(mons_quat *a);
+
+struct mons_vec3 mons_quat_transform_vec3(mons_quat quat, struct mons_vec3 vec);
+
+mons_quat mons_quat_conjugate(mons_quat quat);
+
+mons_quat mons_quat_looking_at(struct mons_vec3 eye, struct mons_vec3 target, struct mons_vec3 up);
+
+void mons_quat_print(mons_quat quat);
+
+#define MONS_QUAT_IDENTITY (mons_quat) { 0, 0, 0, 1 }
+
+#endif
+
diff --git a/mons_math/include/mons_math/util.h b/mons_math/include/mons_math/util.h
new file mode 100644
index 0000000..5218243
--- /dev/null
+++ b/mons_math/include/mons_math/util.h
@@ -0,0 +1,8 @@
+#ifndef MONS_MATH_UTIL_H
+#define MONS_MATH_UTIL_H
+
+#define MONS_FLOAT_EQUAL_EPSILON 0.0001f;
+
+int mons_float_approx_equal(float a, float b);
+
+#endif
diff --git a/mons_math/include/mons_math/vec2.h b/mons_math/include/mons_math/vec2.h
new file mode 100644
index 0000000..3fb405d
--- /dev/null
+++ b/mons_math/include/mons_math/vec2.h
@@ -0,0 +1,46 @@
+#ifndef MONS_VEC2_H
+#define MONS_VEC2_H
+
+typedef struct mons_vec2 {
+ float x;
+ float y;
+} mons_vec2;
+
+mons_vec2 mons_vec2_add(mons_vec2 a, mons_vec2 b);
+void mons_vec2_add_inplace(mons_vec2 *a, mons_vec2 b);
+
+mons_vec2 mons_vec2_sub(mons_vec2 a, mons_vec2 b);
+void mons_vec2_sub_inplace(mons_vec2 *a, mons_vec2 b);
+
+mons_vec2 mons_vec2_mul_f(mons_vec2 a, float b);
+mons_vec2 mons_vec2_mul_i(mons_vec2 a, int b);
+float mons_vec2_dot(mons_vec2 a, mons_vec2 b);
+
+void mons_vec2_mul_f_inplace(mons_vec2 *a, float b);
+void mons_vec2_mul_i_inplace(mons_vec2 *a, int b);
+
+mons_vec2 mons_vec2_div_f(mons_vec2 a, float b);
+mons_vec2 mons_vec2_div_i(mons_vec2 a, int b);
+void mons_vec2_div_f_inplace(mons_vec2 *a, float b);
+void mons_vec2_div_i_inplace(mons_vec2 *a, int b);
+
+float mons_vec2_len(mons_vec2 a);
+float mons_vec2_len_squared(mons_vec2 a);
+
+struct mons_vec3 mons_vec2_extend(mons_vec2 a);
+
+int mons_vec2_equal(mons_vec2 a, mons_vec2 b);
+mons_vec2 mons_vec2_negate(mons_vec2 a);
+void mons_vec2_negate_inplace(mons_vec2 *a);
+
+mons_vec2 mons_vec2_normalize(mons_vec2 a);
+void mons_vec2_normalize_inplace(mons_vec2 *a);
+
+#define MONS_VEC2_ZERO (mons_vec2) { 0, 0 }
+#define MONS_VEC2_ONE (mons_vec2) { 1, 1 }
+#define MONS_VEC2_X (mons_vec2) { 1, 0 }
+#define MONS_VEC2_Y (mons_vec2) { 0, 1 }
+#define MONS_VEC2_NEG_X (mons_vec2) {-1,0}
+#define MONS_VEC2_NEG_Y (mons_vec2) {0,-1}
+
+#endif
diff --git a/mons_math/include/mons_math/vec3.h b/mons_math/include/mons_math/vec3.h
new file mode 100644
index 0000000..6b37410
--- /dev/null
+++ b/mons_math/include/mons_math/vec3.h
@@ -0,0 +1,56 @@
+#ifndef MONS_VEC3_H
+#define MONS_VEC3_H
+
+typedef struct mons_vec3 {
+ float x;
+ float y;
+ float z;
+} mons_vec3;
+
+mons_vec3 mons_vec3_add(mons_vec3 a, mons_vec3 b);
+void mons_vec3_add_inplace(mons_vec3 *a, mons_vec3 b);
+
+mons_vec3 mons_vec3_sub(mons_vec3 a, mons_vec3 b);
+void mons_vec3_sub_inplace(mons_vec3 *a, mons_vec3 b);
+
+mons_vec3 mons_vec3_mul_memberwise(mons_vec3 a, mons_vec3 b);
+void mons_vec3_mul_memberwise_inplace(mons_vec3 *a, mons_vec3 b);
+mons_vec3 mons_vec3_mul_f(mons_vec3 a, float b);
+mons_vec3 mons_vec3_mul_i(mons_vec3 a, int b);
+float mons_vec3_dot(mons_vec3 a, mons_vec3 b);
+
+void mons_vec3_mul_f_inplace(mons_vec3 *a, float b);
+void mons_vec3_mul_i_inplace(mons_vec3 *a, int b);
+
+mons_vec3 mons_vec3_div_f(mons_vec3 a, float b);
+mons_vec3 mons_vec3_div_i(mons_vec3 a, int b);
+void mons_vec3_div_f_inplace(mons_vec3 *a, float b);
+void mons_vec3_div_i_inplace(mons_vec3 *a, int b);
+
+mons_vec3 mons_vec3_cross(mons_vec3 a, mons_vec3 b);
+
+float mons_vec3_len(mons_vec3 a);
+float mons_vec3_len_squared(mons_vec3 a);
+
+struct mons_vec2 mons_vec3_truncate(mons_vec3 a);
+struct mons_vec4 mons_vec3_extend(mons_vec3 a);
+
+int mons_vec3_equal(mons_vec3 a, mons_vec3 b);
+mons_vec3 mons_vec3_negate(mons_vec3 a);
+void mons_vec3_negate_inplace(mons_vec3 *a);
+
+mons_vec3 mons_vec3_normalize(mons_vec3 a);
+void mons_vec3_normalize_inplace(mons_vec3 *a);
+
+void mons_vec3_print(mons_vec3 vec);
+
+#define MONS_VEC3_ZERO (mons_vec3) { 0, 0, 0 }
+#define MONS_VEC3_ONE (mons_vec3) { 1, 1, 1 }
+#define MONS_VEC3_X (mons_vec3) { 1, 0, 0 }
+#define MONS_VEC3_Y (mons_vec3) { 0, 1, 0 }
+#define MONS_VEC3_Z (mons_vec3) { 0, 0, 1 }
+#define MONS_VEC3_NEG_X (mons_vec3) {-1,0,0}
+#define MONS_VEC3_NEG_Y (mons_vec3) {0,-1,0}
+#define MONS_VEC3_NEG_Z (mons_vec3) {0,0,-1}
+
+#endif
diff --git a/mons_math/include/mons_math/vec4.h b/mons_math/include/mons_math/vec4.h
new file mode 100644
index 0000000..24a2d8f
--- /dev/null
+++ b/mons_math/include/mons_math/vec4.h
@@ -0,0 +1,53 @@
+#ifndef MONS_MATH_VEC4_H
+#define MONS_MATH_VEC4_H
+
+typedef struct mons_vec4 {
+ float x;
+ float y;
+ float z;
+ float w;
+} mons_vec4;
+
+mons_vec4 mons_vec4_add(mons_vec4 a, mons_vec4 b);
+void mons_vec4_add_inplace(mons_vec4 *a, mons_vec4 b);
+
+mons_vec4 mons_vec4_sub(mons_vec4 a, mons_vec4 b);
+void mons_vec4_sub_inplace(mons_vec4 *a, mons_vec4 b);
+
+mons_vec4 mons_vec4_mul_f(mons_vec4 a, float b);
+mons_vec4 mons_vec4_mul_i(mons_vec4 a, int b);
+float mons_vec4_dot(mons_vec4 a, mons_vec4 b);
+
+void mons_vec4_mul_f_inplace(mons_vec4 *a, float b);
+void mons_vec4_mul_i_inplace(mons_vec4 *a, int b);
+
+mons_vec4 mons_vec4_div_f(mons_vec4 a, float b);
+mons_vec4 mons_vec4_div_i(mons_vec4 a, int b);
+void mons_vec4_div_f_inplace(mons_vec4 *a, float b);
+void mons_vec4_div_i_inplace(mons_vec4 *a, int b);
+
+float mons_vec4_len(mons_vec4 a);
+float mons_vec4_len_squared(mons_vec4 a);
+
+struct mons_vec3 mons_vec4_truncate(mons_vec4 a);
+
+int mons_vec4_equal(mons_vec4 a, mons_vec4 b);
+mons_vec4 mons_vec4_negate(mons_vec4 a);
+void mons_vec4_negate_inplace(mons_vec4 *a);
+mons_vec4 mons_vec4_normalize(mons_vec4 a);
+void mons_vec4_normalize_inplace(mons_vec4 *a);
+
+void mons_vec4_print(mons_vec4 vec);
+
+#define MONS_VEC4_ZERO (mons_vec4) { 0, 0, 0, 0 }
+#define MONS_VEC4_ONE (mons_vec4) { 1, 1, 1, 1 }
+#define MONS_VEC4_X (mons_vec4) { 1, 0, 0, 0 }
+#define MONS_VEC4_Y (mons_vec4) { 0, 1, 0, 0 }
+#define MONS_VEC4_Z (mons_vec4) { 0, 0, 1, 0 }
+#define MONS_VEC4_W (mons_vec4) { 0, 0, 0, 1 }
+#define MONS_VEC4_NEG_X (mons_vec4) {-1,0,0,0}
+#define MONS_VEC4_NEG_Y (mons_vec4) {0,-1,0,0}
+#define MONS_VEC4_NEG_Z (mons_vec4) {0,0,-1,0}
+#define MONS_VEC4_NEG_W (mons_vec4) {0,0,0,-1}
+
+#endif
diff --git a/mons_math/include/mons_math/vector.h b/mons_math/include/mons_math/vector.h
new file mode 100644
index 0000000..2576d26
--- /dev/null
+++ b/mons_math/include/mons_math/vector.h
@@ -0,0 +1,8 @@
+#ifndef MONS_VECTOR_H
+#define MONS_VECTOR_H
+
+#include "vec2.h"
+#include "vec3.h"
+#include "vec4.h"
+
+#endif