42 lines
1.2 KiB
C
42 lines
1.2 KiB
C
#include "matrix.h"
|
|
|
|
#include <math.h>
|
|
|
|
struct mat3x3 multiply3x3(struct mat3x3 a, struct mat3x3 b) {
|
|
// c ij = a i1 · b 1j + a i2 · b 2j + a i3 · b 3j
|
|
struct mat3x3 res = {0};
|
|
|
|
res.m11 = a.m11 * b.m11 + a.m12 * b.m21 + a.m13 * b.m31;
|
|
res.m12 = a.m11 * b.m12 + a.m12 * b.m22 + a.m13 * b.m32;
|
|
res.m13 = a.m11 * b.m13 + a.m12 * b.m23 + a.m13 * b.m33;
|
|
res.m21 = a.m21 * b.m11 + a.m22 * b.m21 + a.m23 * b.m31;
|
|
res.m22 = a.m21 * b.m12 + a.m22 * b.m22 + a.m23 * b.m32;
|
|
res.m23 = a.m21 * b.m13 + a.m22 * b.m23 + a.m23 * b.m33;
|
|
res.m31 = a.m31 * b.m11 + a.m32 * b.m21 + a.m33 * b.m31;
|
|
res.m32 = a.m31 * b.m12 + a.m32 * b.m22 + a.m33 * b.m32;
|
|
res.m33 = a.m31 * b.m13 + a.m32 * b.m23 + a.m33 * b.m33;
|
|
return res;
|
|
}
|
|
|
|
struct mat3x3 translate3x3(struct Vec2 offset) {
|
|
struct mat3x3 res = IDENT3x3;
|
|
res.m13 = offset.x;
|
|
res.m23 = offset.y;
|
|
return res;
|
|
}
|
|
|
|
struct mat3x3 rotate3x3(float alpha) {
|
|
struct mat3x3 res = IDENT3x3;
|
|
res.m11 = cosf(alpha);
|
|
res.m12 = -sinf(alpha);
|
|
res.m21 = sinf(alpha);
|
|
res.m22 = cosf(alpha);
|
|
return res;
|
|
}
|
|
|
|
struct mat3x3 scale3x3(struct Vec2 scale) {
|
|
struct mat3x3 res = IDENT3x3;
|
|
res.m11 = scale.x;
|
|
res.m22 = scale.y;
|
|
return res;
|
|
}
|