summaryrefslogtreecommitdiff
path: root/src/math/mat.c
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-12-15 00:39:18 +0800
committerchai <chaifix@163.com>2019-12-15 00:39:18 +0800
commit749bbc6a54e50c297ab49d9e515a3679651d1461 (patch)
tree097bbe044332e816aa481db1a4e325b8d3f63b0d /src/math/mat.c
parent3f44877edfe4c301b258d522bcb4e8d9b6e92382 (diff)
*misc
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) {