/*
* 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
*/
#ifndef __UTIL_MATRIX_HPP
#define __UTIL_MATRIX_HPP
#include "point.hpp"
#include
namespace util {
template
struct matrix {
T values[4][4];
static const size_t rows = 4;
static const size_t cols = 4;
matrix& transpose (void);
matrix transposed (void) const;
matrix inverse (void) const;
matrix& invert (void);
matrix inverse_affine (void) const;
matrix& invert_affine (void);
T det (void) const;
matrix operator* (const matrix&) const;
vector<4,T> operator* (const vector<4,T>&) const;
point<4,T> operator* (const point<4,T> &) const;
matrix& operator*= (T);
matrix operator/ (T) const;
matrix& operator/= (T);
bool operator== (const matrix&) const;
bool is_affine (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);
static matrix perspective (T fov, T aspect, T near, T far);
static matrix look_at (point<3,T> eye, point<3,T> centre, vector<3,T> up);
// Affine matrices
static matrix translate (util::vector<3,T>);
static matrix scale (util::vector<3,T>);
static matrix rotate (util::vector<3,T> about, T angle);
// Constant matrices
static const matrix IDENTITY;
static const matrix ZEROES;
};
typedef matrix matrixf;
template
std::ostream& operator<< (std::ostream&, const matrix&);
}
#endif