From 2fc9073901fe82968c05f246d976eee0c58dd0e5 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 15 Dec 2014 13:45:17 +1100 Subject: [PATCH] matrix: add affine definitions and translate impl --- matrix.cpp | 14 ++++++++++++++ matrix.hpp | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/matrix.cpp b/matrix.cpp index 61f64fcc..63f05fa6 100644 --- a/matrix.cpp +++ b/matrix.cpp @@ -501,6 +501,20 @@ matrix::look_at (util::point<3> eye, } +//----------------------------------------------------------------------------- +template +matrix +matrix::translate (util::vector<3> v) +{ + return { { + { 1.f, 0.f, 0.f, v.x }, + { 0.f, 1.f, 0.f, v.y }, + { 0.f, 0.f, 1.f, v.z }, + { 0.f, 0.f, 0.f, 1.f }, + } }; +} + + //----------------------------------------------------------------------------- template const matrix diff --git a/matrix.hpp b/matrix.hpp index f3270586..cd29ab68 100644 --- a/matrix.hpp +++ b/matrix.hpp @@ -65,6 +65,11 @@ namespace util { static matrix perspective (T fov, T aspect, T near, T far); static matrix look_at (util::point<3> eye, util::point<3> centre, util::vector<3> up); + // Affine matrices + static matrix translate (util::vector<3>); + static matrix scale (util::vector<3>); + static matrix rotate (util::vector<3> about, T angle); + // Constant matrices static const matrix IDENTITY; static const matrix ZEROES;