From 6069edd0de07493977f538e4d52e776867844dea Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 30 Dec 2014 01:32:02 +1100 Subject: [PATCH] matrix: add rotate implementation --- matrix.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) 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