summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2023-06-15 15:02:11 -0400
committerrealtradam <[email protected]>2023-06-15 15:02:11 -0400
commit024067ccbf80de1beccbcf2d3a641566c7c45c17 (patch)
tree3317cf61aed4a8786ee8af410ead69a7c62137c9
parent425516a9c53183179c43517f1b6501a790378a05 (diff)
downloadRodeoKit-024067ccbf80de1beccbcf2d3a641566c7c45c17.tar.gz
RodeoKit-024067ccbf80de1beccbcf2d3a641566c7c45c17.zip
some non working progress
-rw-r--r--CMakeLists.txt4
-rw-r--r--include/rodeo/math.h16
-rw-r--r--include/rodeo/math/mat4.h38
-rw-r--r--include/rodeo/math/mat4_t.h20
-rw-r--r--include/rodeo/math/vec2.h53
-rw-r--r--include/rodeo/math/vec2_t.h9
-rw-r--r--include/rodeo/math/vec3.h53
-rw-r--r--include/rodeo/math/vec3_t.h10
-rw-r--r--include/rodeo/math_t.h5
-rw-r--r--src/gfx/irodeo_gfx_t.h9
-rw-r--r--src/gfx/rodeo_gfx.c114
-rw-r--r--src/math/irodeo_math.h16
-rw-r--r--src/math/irodeo_math_t.h1
-rw-r--r--src/math/irodeo_vec2.h14
-rw-r--r--src/math/irodeo_vec3.h15
-rw-r--r--src/math/rodeo_mat4.c132
-rw-r--r--src/math/rodeo_math.c20
-rw-r--r--src/math/rodeo_vec2.c189
-rw-r--r--src/math/rodeo_vec3.c191
19 files changed, 886 insertions, 23 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 60dd94f..d10920a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -14,6 +14,10 @@ add_library(${PROJECT_NAME}
"src/collision/rodeo_collision.c"
"src/gfx/rodeo_gfx.c"
"src/window/rodeo_window.c"
+ "src/math/rodeo_math.c"
+ "src/math/rodeo_vec2.c"
+ "src/math/rodeo_vec3.c"
+ "src/math/rodeo_mat4.c"
)
set_property(TARGET RodeoKit PROPERTY C_STANDARD 99)
diff --git a/include/rodeo/math.h b/include/rodeo/math.h
new file mode 100644
index 0000000..39e9c26
--- /dev/null
+++ b/include/rodeo/math.h
@@ -0,0 +1,16 @@
+#pragma once
+
+// --- internal ---
+// public
+#include "rodeo/math_t.h"
+#include "rodeo/math/vec2.h"
+#include "rodeo/math/vec3.h"
+#include "rodeo/math/mat4.h"
+
+#define mrodeo_math_pi 3.1415927410125732421875f
+
+float
+rodeo_math_radians_to_turns(float radians);
+
+float
+rodeo_math_turns_to_radians(float turns);
diff --git a/include/rodeo/math/mat4.h b/include/rodeo/math/mat4.h
new file mode 100644
index 0000000..5dbc872
--- /dev/null
+++ b/include/rodeo/math/mat4.h
@@ -0,0 +1,38 @@
+#pragma once
+
+// -- internal --
+// public
+#include "rodeo/math/mat4_t.h"
+#include "rodeo/math.h"
+
+rodeo_math_mat4_t
+rodeo_math_mat4_identity(void);
+
+rodeo_math_mat4_t
+rodeo_math_mat4_zero(void);
+
+rodeo_math_mat4_t
+rodeo_math_mat4_transpose(rodeo_math_mat4_t m);
+
+rodeo_math_mat4_t
+rodeo_math_mat4_translate(rodeo_math_mat4_t m, rodeo_math_vec3_t v);
+
+rodeo_math_mat4_t
+rodeo_math_mat4_scale(rodeo_math_mat4_t m, rodeo_math_vec3_t v);
+
+rodeo_math_mat4_t
+rodeo_math_mat4_rotate(rodeo_math_mat4_t m, float turns, rodeo_math_vec3_t v);
+
+rodeo_math_mat4_t
+rodeo_math_mat4_multiply(rodeo_math_mat4_t a, rodeo_math_mat4_t b);
+
+rodeo_math_mat4_t
+rodeo_math_mat4_orthographic(
+ float left,
+ float right,
+ float bottom,
+ float top,
+ float near,
+ float far
+);
+
diff --git a/include/rodeo/math/mat4_t.h b/include/rodeo/math/mat4_t.h
new file mode 100644
index 0000000..2893444
--- /dev/null
+++ b/include/rodeo/math/mat4_t.h
@@ -0,0 +1,20 @@
+#pragma once
+
+
+typedef
+struct
+{
+ float m00, m01, m02, m03;
+ float m10, m11, m12, m13;
+ float m20, m21, m22, m23;
+ float m30, m31, m32, m33;
+}
+rodeo_math_mat4_val_t;
+
+typedef
+union
+{
+ rodeo_math_mat4_val_t val;
+ float raw[4][4];
+}
+rodeo_math_mat4_t;
diff --git a/include/rodeo/math/vec2.h b/include/rodeo/math/vec2.h
new file mode 100644
index 0000000..88d524f
--- /dev/null
+++ b/include/rodeo/math/vec2.h
@@ -0,0 +1,53 @@
+#pragma once
+
+// -- internal --
+// public
+#include "rodeo/math/vec2_t.h"
+
+rodeo_math_vec2_t
+rodeo_math_vec2_zero(void);
+
+rodeo_math_vec2_t
+rodeo_math_vec2_one(void);
+
+float
+rodeo_math_vec2_dot(rodeo_math_vec2_t a, rodeo_math_vec2_t b);
+
+float
+rodeo_math_vec2_cross(rodeo_math_vec2_t a, rodeo_math_vec2_t b);
+
+rodeo_math_vec2_t
+rodeo_math_vec2_add(rodeo_math_vec2_t a, rodeo_math_vec2_t b);
+
+rodeo_math_vec2_t
+rodeo_math_vec2_subtract(rodeo_math_vec2_t a, rodeo_math_vec2_t b);
+
+rodeo_math_vec2_t
+rodeo_math_vec2_multiply(rodeo_math_vec2_t a, rodeo_math_vec2_t b);
+
+rodeo_math_vec2_t
+rodeo_math_vec2_scale(rodeo_math_vec2_t a, float b);
+
+rodeo_math_vec2_t
+rodeo_math_vec2_divide(rodeo_math_vec2_t a, rodeo_math_vec2_t b);
+
+rodeo_math_vec2_t
+rodeo_math_vec2_negate(rodeo_math_vec2_t a);
+
+rodeo_math_vec2_t
+rodeo_math_vec2_normalize(rodeo_math_vec2_t a);
+
+rodeo_math_vec2_t
+rodeo_math_vec2_rotate(rodeo_math_vec2_t a, float turns);
+
+float
+rodeo_math_vec2_distance(rodeo_math_vec2_t a, rodeo_math_vec2_t b);
+
+float
+rodeo_math_vec2_distanceSq(rodeo_math_vec2_t a, rodeo_math_vec2_t b);
+
+rodeo_math_vec2_t
+rodeo_math_vec2_clamp(rodeo_math_vec2_t a, float minimum, float maximum);
+
+rodeo_math_vec2_t
+rodeo_math_vec2_lerp(rodeo_math_vec2_t from, rodeo_math_vec2_t to, float t);
diff --git a/include/rodeo/math/vec2_t.h b/include/rodeo/math/vec2_t.h
new file mode 100644
index 0000000..61b941e
--- /dev/null
+++ b/include/rodeo/math/vec2_t.h
@@ -0,0 +1,9 @@
+#pragma once
+
+typedef
+struct
+{
+ float x;
+ float y;
+}
+rodeo_math_vec2_t;
diff --git a/include/rodeo/math/vec3.h b/include/rodeo/math/vec3.h
new file mode 100644
index 0000000..1b9cd31
--- /dev/null
+++ b/include/rodeo/math/vec3.h
@@ -0,0 +1,53 @@
+#pragma once
+
+// -- internal --
+// public
+#include "rodeo/math/vec3_t.h"
+
+rodeo_math_vec3_t
+rodeo_math_vec3_zero(void);
+
+rodeo_math_vec3_t
+rodeo_math_vec3_one(void);
+
+float
+rodeo_math_vec3_dot(rodeo_math_vec3_t a, rodeo_math_vec3_t b);
+
+float
+rodeo_math_vec3_cross(rodeo_math_vec3_t a, rodeo_math_vec3_t b);
+
+rodeo_math_vec3_t
+rodeo_math_vec3_add(rodeo_math_vec3_t a, rodeo_math_vec3_t b);
+
+rodeo_math_vec3_t
+rodeo_math_vec3_subtract(rodeo_math_vec3_t a, rodeo_math_vec3_t b);
+
+rodeo_math_vec3_t
+rodeo_math_vec3_multiply(rodeo_math_vec3_t a, rodeo_math_vec3_t b);
+
+rodeo_math_vec3_t
+rodeo_math_vec3_scale(rodeo_math_vec3_t a, float b);
+
+rodeo_math_vec3_t
+rodeo_math_vec3_divide(rodeo_math_vec3_t a, rodeo_math_vec3_t b);
+
+rodeo_math_vec3_t
+rodeo_math_vec3_negate(rodeo_math_vec3_t a);
+
+rodeo_math_vec3_t
+rodeo_math_vec3_normalize(rodeo_math_vec3_t a);
+
+rodeo_math_vec3_t
+rodeo_math_vec3_rotate(rodeo_math_vec3_t a, float turns, rodeo_math_vec3_t axis);
+
+float
+rodeo_math_vec3_distance(rodeo_math_vec3_t a, rodeo_math_vec3_t b);
+
+float
+rodeo_math_vec3_distanceSq(rodeo_math_vec3_t a, rodeo_math_vec3_t b);
+
+rodeo_math_vec3_t
+rodeo_math_vec3_clamp(rodeo_math_vec3_t a, float minimum, float maximum);
+
+rodeo_math_vec3_t
+rodeo_math_vec3_lerp(rodeo_math_vec3_t from, rodeo_math_vec3_t to, float t);
diff --git a/include/rodeo/math/vec3_t.h b/include/rodeo/math/vec3_t.h
new file mode 100644
index 0000000..711ad98
--- /dev/null
+++ b/include/rodeo/math/vec3_t.h
@@ -0,0 +1,10 @@
+#pragma once
+
+typedef
+struct
+{
+ float x;
+ float y;
+ float z;
+}
+rodeo_math_vec3_t;
diff --git a/include/rodeo/math_t.h b/include/rodeo/math_t.h
new file mode 100644
index 0000000..9374c2a
--- /dev/null
+++ b/include/rodeo/math_t.h
@@ -0,0 +1,5 @@
+#pragma once
+
+// --- internal ---
+// public
+#include "rodeo/math/vec2_t.h"
diff --git a/src/gfx/irodeo_gfx_t.h b/src/gfx/irodeo_gfx_t.h
index b367e0f..f0cf5e6 100644
--- a/src/gfx/irodeo_gfx_t.h
+++ b/src/gfx/irodeo_gfx_t.h
@@ -3,11 +3,10 @@
// -- internal --
// public
#include "rodeo/gfx_t.h"
+#include "rodeo/math.h"
// -- external --
#include "bgfx/c99/bgfx.h"
-#define CGLM_FORCE_DEPTH_ZERO_TO_ONE
-#include "cglm/mat4.h"
typedef uint16_t irodeo_index_type_t;
@@ -33,8 +32,10 @@ struct
bgfx_uniform_handle_t texture_uniforms[2];
float target_width;
float target_height;
- mat4 view_matrix;
- mat4 proj_matrix;
+ //mat4 view_matrix;
+ //mat4 proj_matrix;
+ rodeo_math_mat4_t view_matrix;
+ rodeo_math_mat4_t proj_matrix;
uint64_t frame_count;
uint32_t frame_limit;
uint32_t frame_start;
diff --git a/src/gfx/rodeo_gfx.c b/src/gfx/rodeo_gfx.c
index 33c4be3..1d2f4ee 100644
--- a/src/gfx/rodeo_gfx.c
+++ b/src/gfx/rodeo_gfx.c
@@ -12,8 +12,6 @@
// -- external --
#include "bgfx/c99/bgfx.h"
-#define CGLM_FORCE_DEPTH_ZERO_TO_ONE
-#include "cglm/cglm.h"
#include "SDL_image.h"
#include "SDL.h" // used for timing, need to replace in this file with BGFX at some point
@@ -196,6 +194,45 @@ rodeo_gfx_deinit(void)
bgfx_shutdown();
}
+void
+irodeo_print_matrix(rodeo_math_mat4_t mat)
+{
+ rodeo_log(
+ rodeo_logLevel_warning,
+ "%.05f, %.05f, %.05f, %.05f",
+ mat.raw[0][0],
+ mat.raw[0][1],
+ mat.raw[0][2],
+ mat.raw[0][3]
+ );
+ rodeo_log(
+ rodeo_logLevel_info,
+ "%.05f, %.05f, %.05f, %.05f",
+ mat.raw[1][0],
+ mat.raw[1][1],
+ mat.raw[1][2],
+ mat.raw[1][3]
+ );
+ rodeo_log(
+ rodeo_logLevel_info,
+ "%.05f, %.05f, %.05f, %.05f",
+ mat.raw[2][0],
+ mat.raw[2][1],
+ mat.raw[2][2],
+ mat.raw[2][3]
+ );
+ rodeo_log(
+ rodeo_logLevel_info,
+ "%.05f, %.05f, %.05f, %.05f",
+ mat.raw[3][0],
+ mat.raw[3][1],
+ mat.raw[3][2],
+ mat.raw[3][3]
+ );
+}
+
+#include "math/irodeo_math.h"
+
void
rodeo_gfx_frame_begin(void)
{
@@ -205,7 +242,9 @@ rodeo_gfx_frame_begin(void)
//glm_lookat(eye, center, up, view);
- glm_mat4_identity(irodeo_gfx_state.view_matrix);
+ mat4 oldway_view_matrix;
+ glm_mat4_identity(oldway_view_matrix);
+ irodeo_gfx_state.view_matrix = rodeo_math_mat4_identity();
//glm_perspective(glm_rad(60.f), 640.f / 480.f, 0.1f, 100.0f, proj);
@@ -231,25 +270,62 @@ rodeo_gfx_frame_begin(void)
// "2" is 1 full screen width, therefore we multiply
// the target and result ratio by 1 for it to be a
// half of the screen size
- vec3 offset = {
- 1 - (1 * (target_width / result_width)), // x
- -(1 - (1 * (target_height / result_height))), // y
+ vec3 oldway_offset = {
+ 1 - (1 * (target_width / result_width)),
+ -(1 - (1 * (target_height / result_height))),
0
};
+ rodeo_math_vec3_t offset = {
+ .x = 1 - (1 * (target_width / result_width)),
+ .y = -(1 - (1 * (target_height / result_height))),
+ .z = 0
+ };
- glm_ortho_rh_zo(
- 0,
- result_width,
- result_height,
- 0,
- -100.0f,
- 100.0f,
- irodeo_gfx_state.proj_matrix
- );
-
- glm_translated(irodeo_gfx_state.proj_matrix, offset);
-
- bgfx_set_view_transform(0, irodeo_gfx_state.view_matrix, irodeo_gfx_state.proj_matrix);
+ mat4 oldway_proj_matrix;
+ glm_mat4_identity(oldway_proj_matrix);
+ irodeo_gfx_state.proj_matrix = rodeo_math_mat4_identity();
+
+ //rodeo_math_mat4_t translation = rodeo_math_mat4_identity();
+ rodeo_math_mat4_t translation = rodeo_math_mat4_translate(irodeo_gfx_state.proj_matrix, offset);
+ //irodeo_print_matrix(translation);
+
+ //rodeo_math_mat4_t ortho = rodeo_math_mat4_orthographic(
+ // 0 - (game_aspect < window_aspect ? rodeo_gfx_letterbox_first_get().width : 0),
+ // result_width - (game_aspect < window_aspect ? rodeo_gfx_letterbox_first_get().width : 0),
+ // result_height - (game_aspect > window_aspect ? rodeo_gfx_letterbox_first_get().height : 0),
+ // 0 - (game_aspect > window_aspect ? rodeo_gfx_letterbox_first_get().height : 0),
+ // -100.0f,
+ // 100.0f
+ //);
+ rodeo_math_mat4_t ortho = rodeo_math_mat4_orthographic(
+ 0,
+ result_width,
+ result_height,
+ 0,
+ -100.0f,
+ 100.0f
+ );
+ glm_ortho(
+ 0,
+ result_width,
+ result_height,
+ 0,
+ -100.0f,
+ 100.0f,
+ oldway_proj_matrix
+ );
+ glm_translate(oldway_proj_matrix, oldway_offset);
+ //irodeo_print_matrix(ortho);
+
+ irodeo_gfx_state.proj_matrix = rodeo_math_mat4_translate(ortho, offset);
+ //irodeo_gfx_state.proj_matrix = rodeo_math_mat4_multiply(ortho, translation);
+ //irodeo_gfx_state.proj_matrix = rodeo_math_mat4_translate(ortho, offset);
+ //irodeo_gfx_state.proj_matrix = ortho;
+ irodeo_print_matrix(irodeo_gfx_state.proj_matrix);
+ //irodeo_gfx_state.proj_matrix = ortho;
+
+ bgfx_set_view_transform(0, irodeo_gfx_state.view_matrix.raw, irodeo_gfx_state.proj_matrix.raw);
+ //bgfx_set_view_transform(0, oldway_view_matrix, irodeo_gfx_state.proj_matrix.raw);
bgfx_set_view_rect(0, 0, 0, (uint16_t)rodeo_window_width_get(), (uint16_t)rodeo_window_height_get());
irodeo_gfx_render_buffer_transient_alloc();
diff --git a/src/math/irodeo_math.h b/src/math/irodeo_math.h
new file mode 100644
index 0000000..beed68f
--- /dev/null
+++ b/src/math/irodeo_math.h
@@ -0,0 +1,16 @@
+#pragma once
+
+// external needs to be first here
+// -- external --
+/*#define CGLM_FORCE_LEFT_HANDED*/
+#define CGLM_FORCE_DEPTH_ZERO_TO_ONE
+/*#define CGLM_CLIPSPACE_INCLUDE_ALL*/
+#include "cglm/struct.h"
+
+// -- internal --
+// private
+#include "math/irodeo_vec2.h"
+#include "math/irodeo_vec3.h"
+//#include "math/irodeo_mat4.h"
+
+
diff --git a/src/math/irodeo_math_t.h b/src/math/irodeo_math_t.h
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/src/math/irodeo_math_t.h
@@ -0,0 +1 @@
+
diff --git a/src/math/irodeo_vec2.h b/src/math/irodeo_vec2.h
new file mode 100644
index 0000000..0b79032
--- /dev/null
+++ b/src/math/irodeo_vec2.h
@@ -0,0 +1,14 @@
+#pragma once
+
+// -- internal --
+// public
+#include "rodeo/math/vec2_t.h"
+// private
+#include "math/irodeo_math.h"
+
+rodeo_math_vec2_t
+irodeo_math_cglmVec2_to_rodeoVec2(vec2s in);
+
+vec2s
+irodeo_math_rodeoVec2_to_cglmVec2(rodeo_math_vec2_t in);
+
diff --git a/src/math/irodeo_vec3.h b/src/math/irodeo_vec3.h
new file mode 100644
index 0000000..bbfffac
--- /dev/null
+++ b/src/math/irodeo_vec3.h
@@ -0,0 +1,15 @@
+
+#pragma once
+
+// -- internal --
+// public
+#include "rodeo/math/vec3_t.h"
+// private
+#include "math/irodeo_math.h"
+
+rodeo_math_vec3_t
+irodeo_math_cglmVec3_to_rodeoVec3(vec3s in);
+
+vec3s
+irodeo_math_rodeoVec3_to_cglmVec3(rodeo_math_vec3_t in);
+
diff --git a/src/math/rodeo_mat4.c b/src/math/rodeo_mat4.c
new file mode 100644
index 0000000..a842d78
--- /dev/null
+++ b/src/math/rodeo_mat4.c
@@ -0,0 +1,132 @@
+
+// -- internal --
+// public
+#include "rodeo/math.h"
+// private
+#include "math/irodeo_math.h"
+
+static inline
+rodeo_math_mat4_t
+irodeo_math_cglmMat4_to_rodeoMat4(mat4s in)
+{
+ return (rodeo_math_mat4_t){
+ .val = {
+ .m00 = in.raw[0][0], .m01 = in.raw[0][1], .m02 = in.raw[0][2], .m03 = in.raw[0][3],
+ .m10 = in.raw[1][0], .m11 = in.raw[1][1], .m12 = in.raw[1][2], .m13 = in.raw[1][3],
+ .m20 = in.raw[2][0], .m21 = in.raw[2][1], .m22 = in.raw[2][2], .m23 = in.raw[2][3],
+ .m30 = in.raw[3][0], .m31 = in.raw[3][1], .m32 = in.raw[3][2], .m33 = in.raw[3][3]
+ }
+ };
+}
+
+static inline
+mat4s
+irodeo_math_rodeoMat4_to_cglmMat4(rodeo_math_mat4_t in)
+{
+ return (mat4s){
+ .raw = {
+ {
+ in.val.m00, in.val.m01, in.val.m02, in.val.m03
+ },
+ {
+ in.val.m10, in.val.m11, in.val.m12, in.val.m13
+ },
+ {
+ in.val.m20, in.val.m21, in.val.m22, in.val.m23
+ },
+ {
+ in.val.m20, in.val.m21, in.val.m22, in.val.m23
+ },
+ }
+ };
+}
+
+rodeo_math_mat4_t
+rodeo_math_mat4_identity(void)
+{
+ return irodeo_math_cglmMat4_to_rodeoMat4(glms_mat4_identity());
+}
+
+rodeo_math_mat4_t
+rodeo_math_mat4_zero(void)
+{
+ return irodeo_math_cglmMat4_to_rodeoMat4(glms_mat4_zero());
+}
+
+rodeo_math_mat4_t
+rodeo_math_mat4_transpose(rodeo_math_mat4_t m)
+{
+ return irodeo_math_cglmMat4_to_rodeoMat4(
+ glms_mat4_transpose(
+ irodeo_math_rodeoMat4_to_cglmMat4(m)
+ )
+ );
+}
+
+rodeo_math_mat4_t
+rodeo_math_mat4_translate(rodeo_math_mat4_t m, rodeo_math_vec3_t v)
+{
+ return irodeo_math_cglmMat4_to_rodeoMat4(
+ glms_translated(
+ irodeo_math_rodeoMat4_to_cglmMat4(m),
+ irodeo_math_rodeoVec3_to_cglmVec3(v)
+ )
+ );
+}
+
+rodeo_math_mat4_t
+rodeo_math_mat4_scale(rodeo_math_mat4_t m, rodeo_math_vec3_t v)
+{
+ return irodeo_math_cglmMat4_to_rodeoMat4(
+ glms_scale(
+ irodeo_math_rodeoMat4_to_cglmMat4(m),
+ irodeo_math_rodeoVec3_to_cglmVec3(v)
+ )
+ );
+}
+
+rodeo_math_mat4_t
+rodeo_math_mat4_rotate(rodeo_math_mat4_t m, float turns, rodeo_math_vec3_t v)
+{
+ return irodeo_math_cglmMat4_to_rodeoMat4(
+ glms_rotate(
+ irodeo_math_rodeoMat4_to_cglmMat4(m),
+ turns,
+ irodeo_math_rodeoVec3_to_cglmVec3(v)
+ )
+ );
+}
+
+rodeo_math_mat4_t
+rodeo_math_mat4_multiply(rodeo_math_mat4_t a, rodeo_math_mat4_t b)
+{
+ return irodeo_math_cglmMat4_to_rodeoMat4(
+ glms_mat4_mul(
+ irodeo_math_rodeoMat4_to_cglmMat4(a),
+ irodeo_math_rodeoMat4_to_cglmMat4(b)
+ )
+ );
+}
+
+rodeo_math_mat4_t
+rodeo_math_mat4_orthographic(
+ float left,
+ float right,
+ float bottom,
+ float top,
+ float near,
+ float far
+)
+{
+ return irodeo_math_cglmMat4_to_rodeoMat4(
+ glms_ortho_rh_zo(
+ left,
+ right,
+ bottom,
+ top,
+ near,
+ far
+ )
+ );
+}
+
diff --git a/src/math/rodeo_math.c b/src/math/rodeo_math.c
new file mode 100644
index 0000000..20516e3
--- /dev/null
+++ b/src/math/rodeo_math.c
@@ -0,0 +1,20 @@
+
+// -- internal --
+// public
+#include "rodeo/math.h"
+
+// -- system --
+#include "math.h"
+
+float
+rodeo_math_radians_to_turns(float radians)
+{
+ return (radians / mrodeo_math_pi) / 2.0f;
+}
+
+float
+rodeo_math_turns_to_radians(float turns)
+{
+ return turns * mrodeo_math_pi * 2.0f;
+}
+
diff --git a/src/math/rodeo_vec2.c b/src/math/rodeo_vec2.c
new file mode 100644
index 0000000..a9e369e
--- /dev/null
+++ b/src/math/rodeo_vec2.c
@@ -0,0 +1,189 @@
+
+// -- internal --
+// public
+#include "rodeo/math.h"
+#include "rodeo/math/vec2.h"
+// private
+#include "math/irodeo_math.h"
+#include "math/irodeo_vec2.h"
+
+rodeo_math_vec2_t
+irodeo_math_cglmVec2_to_rodeoVec2(vec2s in)
+{
+ return (rodeo_math_vec2_t){
+ .x = in.raw[0],
+ .y = in.raw[1]
+ };
+}
+
+vec2s
+irodeo_math_rodeoVec2_to_cglmVec2(rodeo_math_vec2_t in)
+{
+ return (vec2s){
+ .raw[0] = in.x,
+ .raw[1] = in.y
+ };
+}
+
+
+rodeo_math_vec2_t
+rodeo_math_vec2_zero(void)
+{
+ return irodeo_math_cglmVec2_to_rodeoVec2(glms_vec2_zero());
+}
+
+rodeo_math_vec2_t
+rodeo_math_vec2_one(void)
+{
+ return irodeo_math_cglmVec2_to_rodeoVec2(glms_vec2_one());
+}
+
+float
+rodeo_math_vec2_dot(rodeo_math_vec2_t a, rodeo_math_vec2_t b)
+{
+ return glms_vec2_dot(
+ irodeo_math_rodeoVec2_to_cglmVec2(a),
+ irodeo_math_rodeoVec2_to_cglmVec2(b)
+ );
+}
+
+float
+rodeo_math_vec2_cross(rodeo_math_vec2_t a, rodeo_math_vec2_t b)
+{
+ return glms_vec2_dot(
+ irodeo_math_rodeoVec2_to_cglmVec2(a),
+ irodeo_math_rodeoVec2_to_cglmVec2(b)
+ );
+}
+
+rodeo_math_vec2_t
+rodeo_math_vec2_add(rodeo_math_vec2_t a, rodeo_math_vec2_t b)
+{
+ return irodeo_math_cglmVec2_to_rodeoVec2(
+ glms_vec2_add(
+ irodeo_math_rodeoVec2_to_cglmVec2(a),
+ irodeo_math_rodeoVec2_to_cglmVec2(b)
+ )
+ );
+}
+
+rodeo_math_vec2_t
+rodeo_math_vec2_subtract(rodeo_math_vec2_t a, rodeo_math_vec2_t b)
+{
+ return irodeo_math_cglmVec2_to_rodeoVec2(
+ glms_vec2_sub(
+ irodeo_math_rodeoVec2_to_cglmVec2(a),
+ irodeo_math_rodeoVec2_to_cglmVec2(b)
+ )
+ );
+}
+
+rodeo_math_vec2_t
+rodeo_math_vec2_multiply(rodeo_math_vec2_t a, rodeo_math_vec2_t b)
+{
+ return irodeo_math_cglmVec2_to_rodeoVec2(
+ glms_vec2_mul(
+ irodeo_math_rodeoVec2_to_cglmVec2(a),
+ irodeo_math_rodeoVec2_to_cglmVec2(b)
+ )
+ );
+}
+
+rodeo_math_vec2_t
+rodeo_math_vec2_scale(rodeo_math_vec2_t a, float b)
+{
+ return irodeo_math_cglmVec2_to_rodeoVec2(
+ glms_vec2_scale(
+ irodeo_math_rodeoVec2_to_cglmVec2(a),
+ b
+ )
+ );
+}
+
+rodeo_math_vec2_t
+rodeo_math_vec2_divide(rodeo_math_vec2_t a, rodeo_math_vec2_t b)
+{
+ return irodeo_math_cglmVec2_to_rodeoVec2(
+ glms_vec2_div(
+ irodeo_math_rodeoVec2_to_cglmVec2(a),
+ irodeo_math_rodeoVec2_to_cglmVec2(b)
+ )
+ );
+}
+
+rodeo_math_vec2_t
+rodeo_math_vec2_negate(rodeo_math_vec2_t a)
+{
+ return irodeo_math_cglmVec2_to_rodeoVec2(
+ glms_vec2_negate(
+ irodeo_math_rodeoVec2_to_cglmVec2(a)
+ )
+ );
+}
+
+rodeo_math_vec2_t
+rodeo_math_vec2_normalize(rodeo_math_vec2_t a)
+{
+ return irodeo_math_cglmVec2_to_rodeoVec2(
+ glms_vec2_normalize(
+ irodeo_math_rodeoVec2_to_cglmVec2(a)
+ )
+ );
+}
+
+rodeo_math_vec2_t
+rodeo_math_vec2_rotate(rodeo_math_vec2_t a, float turns)
+{
+ return irodeo_math_cglmVec2_to_rodeoVec2(
+ glms_vec2_rotate(
+ irodeo_math_rodeoVec2_to_cglmVec2(a),
+ rodeo_math_radians_to_turns(turns)
+ )
+ );
+}
+
+float
+rodeo_math_vec2_distance(rodeo_math_vec2_t a, rodeo_math_vec2_t b)
+{
+ return (
+ glms_vec2_distance(
+ irodeo_math_rodeoVec2_to_cglmVec2(a),
+ irodeo_math_rodeoVec2_to_cglmVec2(b)
+ )
+ );
+}
+
+float
+rodeo_math_vec2_distanceSq(rodeo_math_vec2_t a, rodeo_math_vec2_t b)
+{
+ return (
+ glms_vec2_distance2(
+ irodeo_math_rodeoVec2_to_cglmVec2(a),
+ irodeo_math_rodeoVec2_to_cglmVec2(b)
+ )
+ );
+}
+
+rodeo_math_vec2_t
+rodeo_math_vec2_clamp(rodeo_math_vec2_t a, float minimum, float maximum)
+{
+ return irodeo_math_cglmVec2_to_rodeoVec2(
+ glms_vec2_clamp(
+ irodeo_math_rodeoVec2_to_cglmVec2(a),
+ minimum,
+ maximum
+ )
+ );
+}
+
+rodeo_math_vec2_t
+rodeo_math_vec2_lerp(rodeo_math_vec2_t from, rodeo_math_vec2_t to, float t)
+{
+ return irodeo_math_cglmVec2_to_rodeoVec2(
+ glms_vec2_lerp(
+ irodeo_math_rodeoVec2_to_cglmVec2(from),
+ irodeo_math_rodeoVec2_to_cglmVec2(to),
+ t
+ )
+ );
+}
diff --git a/src/math/rodeo_vec3.c b/src/math/rodeo_vec3.c
new file mode 100644
index 0000000..bcdf86b
--- /dev/null
+++ b/src/math/rodeo_vec3.c
@@ -0,0 +1,191 @@
+
+// -- internal --
+// public
+#include "rodeo/math.h"
+#include "rodeo/math/vec3.h"
+// private
+#include "math/irodeo_math.h"
+#include "math/irodeo_vec3.h"
+
+rodeo_math_vec3_t
+irodeo_math_cglmVec3_to_rodeoVec3(vec3s in)
+{
+ return (rodeo_math_vec3_t){
+ .x = in.raw[0],
+ .y = in.raw[1],
+ .z = in.raw[2]
+ };
+}
+
+vec3s
+irodeo_math_rodeoVec3_to_cglmVec3(rodeo_math_vec3_t in)
+{
+ return (vec3s){
+ .raw[0] = in.x,
+ .raw[1] = in.y,
+ .raw[2] = in.z
+ };
+}
+
+rodeo_math_vec3_t
+rodeo_math_vec3_zero(void)
+{
+ return irodeo_math_cglmVec3_to_rodeoVec3(glms_vec3_zero());
+}
+
+rodeo_math_vec3_t
+rodeo_math_vec3_one(void)
+{
+ return irodeo_math_cglmVec3_to_rodeoVec3(glms_vec3_one());
+}
+
+float
+rodeo_math_vec3_dot(rodeo_math_vec3_t a, rodeo_math_vec3_t b)
+{
+ return glms_vec3_dot(
+ irodeo_math_rodeoVec3_to_cglmVec3(a),
+ irodeo_math_rodeoVec3_to_cglmVec3(b)
+ );
+}
+
+float
+rodeo_math_vec3_cross(rodeo_math_vec3_t a, rodeo_math_vec3_t b)
+{
+ return glms_vec3_dot(
+ irodeo_math_rodeoVec3_to_cglmVec3(a),
+ irodeo_math_rodeoVec3_to_cglmVec3(b)
+ );
+}
+
+rodeo_math_vec3_t
+rodeo_math_vec3_add(rodeo_math_vec3_t a, rodeo_math_vec3_t b)
+{
+ return irodeo_math_cglmVec3_to_rodeoVec3(
+ glms_vec3_add(
+ irodeo_math_rodeoVec3_to_cglmVec3(a),
+ irodeo_math_rodeoVec3_to_cglmVec3(b)
+ )
+ );
+}
+
+rodeo_math_vec3_t
+rodeo_math_vec3_subtract(rodeo_math_vec3_t a, rodeo_math_vec3_t b)
+{
+ return irodeo_math_cglmVec3_to_rodeoVec3(
+ glms_vec3_sub(
+ irodeo_math_rodeoVec3_to_cglmVec3(a),
+ irodeo_math_rodeoVec3_to_cglmVec3(b)
+ )
+ );
+}
+
+rodeo_math_vec3_t
+rodeo_math_vec3_multiply(rodeo_math_vec3_t a, rodeo_math_vec3_t b)
+{
+ return irodeo_math_cglmVec3_to_rodeoVec3(
+ glms_vec3_mul(
+ irodeo_math_rodeoVec3_to_cglmVec3(a),
+ irodeo_math_rodeoVec3_to_cglmVec3(b)
+ )
+ );
+}
+
+rodeo_math_vec3_t
+rodeo_math_vec3_scale(rodeo_math_vec3_t a, float b)
+{
+ return irodeo_math_cglmVec3_to_rodeoVec3(
+ glms_vec3_scale(
+ irodeo_math_rodeoVec3_to_cglmVec3(a),
+ b
+ )
+ );
+}
+
+rodeo_math_vec3_t
+rodeo_math_vec3_divide(rodeo_math_vec3_t a, rodeo_math_vec3_t b)
+{
+ return irodeo_math_cglmVec3_to_rodeoVec3(
+ glms_vec3_div(
+ irodeo_math_rodeoVec3_to_cglmVec3(a),
+ irodeo_math_rodeoVec3_to_cglmVec3(b)
+ )
+ );
+}
+
+rodeo_math_vec3_t
+rodeo_math_vec3_negate(rodeo_math_vec3_t a)
+{
+ return irodeo_math_cglmVec3_to_rodeoVec3(
+ glms_vec3_negate(
+ irodeo_math_rodeoVec3_to_cglmVec3(a)
+ )
+ );
+}
+
+rodeo_math_vec3_t
+rodeo_math_vec3_normalize(rodeo_math_vec3_t a)
+{
+ return irodeo_math_cglmVec3_to_rodeoVec3(
+ glms_vec3_normalize(
+ irodeo_math_rodeoVec3_to_cglmVec3(a)
+ )
+ );
+}
+
+rodeo_math_vec3_t
+rodeo_math_vec3_rotate(rodeo_math_vec3_t a, float turns, rodeo_math_vec3_t axis)
+{
+ return irodeo_math_cglmVec3_to_rodeoVec3(
+ glms_vec3_rotate(
+ irodeo_math_rodeoVec3_to_cglmVec3(a),
+ rodeo_math_radians_to_turns(turns),
+ irodeo_math_rodeoVec3_to_cglmVec3(axis)
+ )
+ );
+}
+
+float
+rodeo_math_vec3_distance(rodeo_math_vec3_t a, rodeo_math_vec3_t b)
+{
+ return (
+ glms_vec3_distance(
+ irodeo_math_rodeoVec3_to_cglmVec3(a),
+ irodeo_math_rodeoVec3_to_cglmVec3(b)
+ )
+ );
+}
+
+float
+rodeo_math_vec3_distanceSq(rodeo_math_vec3_t a, rodeo_math_vec3_t b)
+{
+ return (
+ glms_vec3_distance2(
+ irodeo_math_rodeoVec3_to_cglmVec3(a),
+ irodeo_math_rodeoVec3_to_cglmVec3(b)
+ )
+ );
+}
+
+rodeo_math_vec3_t
+rodeo_math_vec3_clamp(rodeo_math_vec3_t a, float minimum, float maximum)
+{
+ return irodeo_math_cglmVec3_to_rodeoVec3(
+ glms_vec3_clamp(
+ irodeo_math_rodeoVec3_to_cglmVec3(a),
+ minimum,
+ maximum
+ )
+ );
+}
+
+rodeo_math_vec3_t
+rodeo_math_vec3_lerp(rodeo_math_vec3_t from, rodeo_math_vec3_t to, float t)
+{
+ return irodeo_math_cglmVec3_to_rodeoVec3(
+ glms_vec3_lerp(
+ irodeo_math_rodeoVec3_to_cglmVec3(from),
+ irodeo_math_rodeoVec3_to_cglmVec3(to),
+ t
+ )
+ );
+}