summaryrefslogtreecommitdiff
path: root/src/math/mat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/math/mat.c')
-rw-r--r--src/math/mat.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/math/mat.c b/src/math/mat.c
index 84a5a41..f889697 100644
--- a/src/math/mat.c
+++ b/src/math/mat.c
@@ -9,6 +9,7 @@
static Mat4 sharedMat;
static Mat4 sharedMat2;
+static Vec3 sharedVec3;
static Vec4 sharedVec4;
Mat4 mat4identity = {
@@ -333,6 +334,20 @@ void mat4_applytovec4(Mat4* mat, Vec4* v, Vec4* out) {
out->w = mat->e30 * v->x + mat->e31 * v->y + mat->e32 * v->z + mat->e33 * v->w;
}
+/*
+** mat3 apply to vec3
+*/
+void mat4_applytovec3(Mat4* mat, Vec3* v, Vec3* out) {
+ ssr_assert(mat && v && out);
+ if (v == out) {
+ sharedVec3 = *v;
+ v = &sharedVec3;
+ }
+ out->x = mat->e00 * v->x + mat->e01 * v->y + mat->e02 * v->z;
+ out->y = mat->e10 * v->x + mat->e11 * v->y + mat->e12 * v->z;
+ out->z = mat->e20 * v->x + mat->e21 * v->y + mat->e22 * v->z;
+}
+
#define trans(r, c) out->e##r##c = m->e##c##r
void mat4_transpose(Mat4* m, Mat4* out) {