diff options
| author | kkard2 <[email protected]> | 2025-09-20 17:52:01 +0200 |
|---|---|---|
| committer | kkard2 <[email protected]> | 2025-09-20 17:52:01 +0200 |
| commit | 7ce5bb498bfe95a912f690e9d17c148114f02de0 (patch) | |
| tree | c166655f73bfd769e670162e3114678a4e472430 | |
| parent | 0004eecef7a7693831bb5fd8b4cb3884ce7d4466 (diff) | |
simplify matrix api
| -rw-r--r-- | examples/matrix.c | 6 | ||||
| -rw-r--r-- | sponge.h | 30 |
2 files changed, 18 insertions, 18 deletions
diff --git a/examples/matrix.c b/examples/matrix.c index 0b0ac91..861b151 100644 --- a/examples/matrix.c +++ b/examples/matrix.c @@ -13,9 +13,9 @@ void draw_frame(sponge_Texture c) { sponge_Vec3 v1 = sponge_vec3_make(0.8f, 0.8f, 0.0f); sponge_Vec3 v2 = sponge_vec3_make(-0.8f, 0.8f, 0.0f); - sponge_Mat4 m = sponge_mat4_rotate(sponge_vec3_make(0.0f, 0.0f, angle)); - m = sponge_mat4_mul_mat4(m, sponge_mat4_translate(sponge_vec3_make(1.0f, 1.0f, 0.0f))); - m = sponge_mat4_mul_mat4(m, sponge_mat4_scale(sponge_vec3_make((float)(c.width / 2), (float)(c.height / 2), 1.0f))); + sponge_Mat4 m = sponge_mat4_rotate(0.0f, 0.0f, angle); + m = sponge_mat4_mul_mat4(m, sponge_mat4_translate(1.0f, 1.0f, 0.0f)); + m = sponge_mat4_mul_mat4(m, sponge_mat4_scale((float)(c.width / 2), (float)(c.height / 2), 1.0f)); v0 = sponge_vec3_mul_mat4(v0, m); v1 = sponge_vec3_mul_mat4(v1, m); @@ -86,10 +86,10 @@ sponge_Mat4 sponge_mat4_mul_mat4(sponge_Mat4 m0, sponge_Mat4 m1); sponge_Vec4 sponge_vec4_mul_mat4(sponge_Vec4 v0, sponge_Mat4 m0); sponge_Vec3 sponge_vec3_mul_mat4(sponge_Vec3 v0, sponge_Mat4 m0); // sets .w to 1 and divides by .w at the end if necessary sponge_Mat4 sponge_mat4_identity(); -sponge_Mat4 sponge_mat4_translate(sponge_Vec3 translation); +sponge_Mat4 sponge_mat4_translate(float x, float y, float z); // TODO(kard): quaternion type beat -sponge_Mat4 sponge_mat4_rotate(sponge_Vec3 euler); // y -> x -> z order -sponge_Mat4 sponge_mat4_scale(sponge_Vec3 scale); +sponge_Mat4 sponge_mat4_rotate(float x, float y, float z); // y -> x -> z order +sponge_Mat4 sponge_mat4_scale(float x, float y, float z); // checks if tex.width or tex.height is equal to 0 @@ -263,19 +263,19 @@ sponge_Mat4 sponge_mat4_identity() { return m; } -sponge_Mat4 sponge_mat4_translate(sponge_Vec3 translation) { +sponge_Mat4 sponge_mat4_translate(float x, float y, float z) { sponge_Mat4 m = sponge_mat4_identity(); - m.c30 = translation.x; - m.c31 = translation.y; - m.c32 = translation.z; + m.c30 = x; + m.c31 = y; + m.c32 = z; return m; } -sponge_Mat4 sponge_mat4_rotate(sponge_Vec3 euler) { +sponge_Mat4 sponge_mat4_rotate(float x, float y, float z) { // TOOD(kard): make this not stupid - float sx = sinf(euler.x); float cx = cosf(euler.x); - float sy = sinf(euler.y); float cy = cosf(euler.y); - float sz = sinf(euler.z); float cz = cosf(euler.z); + float sx = sinf(x); float cx = cosf(x); + float sy = sinf(y); float cy = cosf(y); + float sz = sinf(z); float cz = cosf(z); sponge_Mat4 mx = sponge_mat4_identity(); mx.c00 = 1; mx.c01 = 0; mx.c02 = 0; mx.c10 = 0; mx.c11 = cx; mx.c12 = sx; @@ -291,11 +291,11 @@ sponge_Mat4 sponge_mat4_rotate(sponge_Vec3 euler) { return sponge_mat4_mul_mat4(sponge_mat4_mul_mat4(my, mx), mz); } -sponge_Mat4 sponge_mat4_scale(sponge_Vec3 scale) { +sponge_Mat4 sponge_mat4_scale(float x, float y, float z) { sponge_Mat4 m = sponge_mat4_identity(); - m.c00 = scale.x; - m.c11 = scale.y; - m.c22 = scale.z; + m.c00 = x; + m.c11 = y; + m.c22 = z; return m; } |
