diff --git a/matrix.cpp b/matrix.cpp index 07897f40..29da3f62 100644 --- a/matrix.cpp +++ b/matrix.cpp @@ -529,6 +529,42 @@ matrix::scale (util::vector<3,T> v) } +//----------------------------------------------------------------------------- +template +matrix +matrix::rotate (util::vector<3,T> about, T angle) +{ + about.normalise (); + + T c = std::cos (angle); + T s = std::sin (angle); + T x = about.x, + y = about.y, + z = about.z; + + return { { + { x * x * (1 - c) + c, + x * y * (1 - c) - z * s, + x * z * (1 - c) + y * s, + 0 + }, + + { y * x * (1 - c) + z * s, + y * y * (1 - c) + c, + y * z * (1 - c) - x * s, + 0 + }, + + { z * x * (1 - c) - y * s, + z * y * (1 - c) + x * s, + z * z * (1 - c) + c, + 0 + }, + + { 0, 0, 0, 1 } + } }; +} + //----------------------------------------------------------------------------- template const matrix