From 630567bcff817960a26fbbd0a7dca2c6c06d0745 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 19 Feb 2015 13:24:37 +1100 Subject: [PATCH] matrix: add type cast function --- Makefile.am | 1 + matrix.hpp | 4 ++++ matrix.ipp | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 matrix.ipp diff --git a/Makefile.am b/Makefile.am index 5f564fea..dab645ef 100644 --- a/Makefile.am +++ b/Makefile.am @@ -85,6 +85,7 @@ UTIL_FILES = \ maths.ipp \ maths/matrix.cpp \ maths/matrix.hpp \ + maths/matrix.ipp \ maths/vector.cpp \ maths/vector.hpp \ matrix.cpp \ diff --git a/matrix.hpp b/matrix.hpp index 348bdd9f..3d0ace2b 100644 --- a/matrix.hpp +++ b/matrix.hpp @@ -57,6 +57,9 @@ namespace util { bool is_affine (void) const; + template + matrix cast (void) const; + // Perspective matrices static matrix ortho (T left, T right, T bottom, T top, T near, T far); static matrix ortho2D (T left, T right, T bottom, T top); @@ -81,5 +84,6 @@ namespace util { std::ostream& operator<< (std::ostream&, const matrix&); } +#include "matrix.ipp" #endif diff --git a/matrix.ipp b/matrix.ipp new file mode 100644 index 00000000..dd5f2f8e --- /dev/null +++ b/matrix.ipp @@ -0,0 +1,39 @@ +/* + * This file is part of libgim. + * + * libgim is free software: you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * libgim is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with libgim. If not, see . + * + * Copyright 2011-2014 Danny Robson + */ + + +#ifdef __UTIL_MATRIX_IPP +#error +#endif + +#define __UTIL_MATRIX_IPP + +template +template +util::matrix +util::matrix::cast (void) const +{ + util::matrix out; + + for (size_t i = 0; i < rows; ++i) + for (size_t j = 0; j < cols; ++j) + out.values[i][j] = values[i][j]; + + return out; +}