aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2024-01-14 05:52:15 +0100
committerkdx <kikoodx@paranoici.org>2024-01-14 05:52:15 +0100
commitaf2baacc0ccd6fc3ebd58b4e314f8bc80361c416 (patch)
tree3cb3114e433436d1ed2d52f5e17efa1401c3078f
parent5df336d5a5bdefebffc7785e1455829e310e4e21 (diff)
downloadcminus-af2baacc0ccd6fc3ebd58b4e314f8bc80361c416.tar.gz
v2_transform
-rw-r--r--_.c10
-rw-r--r--_.h15
2 files changed, 19 insertions, 6 deletions
diff --git a/_.c b/_.c
index abaf19b..bdf651b 100644
--- a/_.c
+++ b/_.c
@@ -154,6 +154,16 @@ vec2 v2_lerp(vec2 a, vec2 b, f32 x) {
return v2_add(a, v2_mul(v2_sub(b, a), x));
}
+vec2 v2_transform(vec2 v, mat3 m) {
+ vec2 out = v2_zero();
+ repeat (i, 2) {
+ out.a[i] = v.x * m.a[0][i] +
+ v.y * m.a[1][i] +
+ m.a[2][i];
+ }
+ return out;
+}
+
mat3 m3_identity(void) {
return (mat3){{
{ 1, 0, 0 },
diff --git a/_.h b/_.h
index a915295..5ea9f60 100644
--- a/_.h
+++ b/_.h
@@ -77,17 +77,18 @@ void *_realloc(void *ptr, size_t size);
#endif
#define todo() panic("todo")
-// mathematical vectors
+// math shit
-#define UNPACK(V) (V).x, (V).y
+typedef union vec2 vec2;
+typedef union mat3 mat3;
-typedef union {
+union vec2 {
struct {
f32 x;
f32 y;
};
f32 a[2];
-} vec2;
+};
vec2 v2(f32 x, f32 y);
vec2 v2r(f32);
@@ -107,11 +108,13 @@ vec2 v2_clamp(vec2, vec2 min, vec2 max);
vec2 v2_swap(vec2);
vec2 v2_negate(vec2);
vec2 v2_lerp(vec2 from, vec2 to, f32);
+vec2 v2_transform(vec2, mat3);
#define v2_log(L, A) p##L("%.2f %.2f", (A).x, (A).y)
+#define v2_unpack(V) (V).x, (V).y
-typedef union {
+union mat3 {
f32 a[3][3];
-} mat3;
+};
mat3 m3_identity(void);
mat3 m3_zero(void);