From ec3a81ed35619fe6a9126e3ed2793ddc7935513d Mon Sep 17 00:00:00 2001 From: Allanis Date: Sun, 24 Dec 2017 19:22:33 +0000 Subject: [PATCH] [Add] Added Rotating frames. --- src/matrix4x4.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/matrix4x4.h b/src/matrix4x4.h index d981668..22d8f35 100644 --- a/src/matrix4x4.h +++ b/src/matrix4x4.h @@ -68,6 +68,30 @@ public: m[3] = 0; m[7] = 0; m[11] = 0; m[15] = 1; } + /* (x,y,z) must be normalized. */ + static matrix4x4 RotateMatrix(T ang, T x, T y, T z) { + matrix4x4 m; + T c = cos(ang); + T s = sin(ang); + m[ 0] = x*x*(1-c)+c; + m[ 1] = y*x*(1-c)+z*s; + m[ 2] = x*z*(1-c)-y*s; + m[ 3] = 0; + m[ 4] = x*y*(1-c)-z*s; + m[ 5] = y*y*(1-c)+c; + m[ 6] = y*z*(1-c)+x*s; + m[ 7] = 0; + m[ 8] = x*z*(1-c)+y*s; + m[ 9] = y*z*(1-c)-x*s; + m[10] = z*z*(1-c)+c; + m[11] = 0; + m[12] = 0; + m[13] = 0; + m[14] = 0; + m[15] = 1; + return m; + } + void RotateZ(T radians) { *this = (*this) * RotateZMatrix(radians); } void RotateY(T radians) { *this = (*this) * RotateYMatrix(radians); } void rotateX(T radians) { *this = (*this) * RotateXMatrix(radians); }