53#ifndef ACG_MATRIX4X4_HH
54#define ACG_MATRIX4X4_HH
61#include "../Config/ACGDefines.hh"
75template<
typename Scalar>
inline bool checkEpsilon(Scalar x) {
76 return fabs(x) < (1e-6);
79template<>
inline bool checkEpsilon(
float x) {
80 return fabs(x) < (1e-4);
91template <
class Scalar>
95 using value_type = Scalar;
101 template <
class OtherScalar>
109 std::copy(_array,_array+16, mat_);
117 template<
typename otherScalar>
121 for (
int i = 0; i < 16; ++i)
122 mat_[i] = Scalar(_rhs.data()[i]);
130 inline Scalar&
operator()(
unsigned int row,
unsigned int col) {
131 return mat_[(row)+((col)<<2)];
135 inline const Scalar&
operator()(
unsigned int row,
unsigned int col)
const {
136 return mat_[(row)+((col)<<2)];
143 const Scalar *a = mat_;
144 const Scalar *b = _rhs.mat_;
145 for(i=0;i< 16;i++,a++,b++)
146 if(! checkEpsilon( *a - *b ))
159 std::transform(mat_,mat_+16, _rhs.mat_, _rhs.mat_, std::plus<Scalar>());
165 std::transform(mat_,mat_+16, _rhs.mat_, _rhs.mat_, std::minus<Scalar>());
178 std::transform(mat_,mat_+16,_rhs.mat_, mat_, std::plus<Scalar>());
184 std::transform(mat_,mat_+16, _rhs.mat_, mat_, std::minus<Scalar>());
196 template <
typename T>
200 template <
typename T>
204 template <
typename T>
217 const Scalar *a = mat_;
219 for(i=0;i< 16;i++,a++,b++) {
220 if ( ( i == 0) || ( i == 5 ) || ( i == 10 ) || ( i == 15 ) )
224 if(! checkEpsilon( *a - b ))
238 Scalar determinant()
const {
239 return mat_[12] * mat_[9] * mat_[6] * mat_[3] - mat_[8] * mat_[13] * mat_[6] * mat_[3] -
240 mat_[12] * mat_[5] * mat_[10] * mat_[3] + mat_[4] * mat_[13] * mat_[10] * mat_[3] +
241 mat_[8] * mat_[5] * mat_[14] * mat_[3] - mat_[4] * mat_[9] * mat_[14] * mat_[3] -
242 mat_[12] * mat_[9] * mat_[2] * mat_[7] + mat_[8] * mat_[13] * mat_[2] * mat_[7] +
243 mat_[12] * mat_[1] * mat_[10] * mat_[7] - mat_[0] * mat_[13] * mat_[10] * mat_[7] -
244 mat_[8] * mat_[1] * mat_[14] * mat_[7] + mat_[0] * mat_[9] * mat_[14] * mat_[7] +
245 mat_[12] * mat_[5] * mat_[2] * mat_[11] - mat_[4] * mat_[13] * mat_[2] * mat_[11] -
246 mat_[12] * mat_[1] * mat_[6] * mat_[11] + mat_[0] * mat_[13] * mat_[6] * mat_[11] +
247 mat_[4] * mat_[1] * mat_[14] * mat_[11] - mat_[0] * mat_[5] * mat_[14] * mat_[11] -
248 mat_[8] * mat_[5] * mat_[2] * mat_[15] + mat_[4] * mat_[9] * mat_[2] * mat_[15] +
249 mat_[8] * mat_[1] * mat_[6] * mat_[15] - mat_[0] * mat_[9] * mat_[6] * mat_[15] -
250 mat_[4] * mat_[1] * mat_[10] * mat_[15] + mat_[0] * mat_[5] * mat_[10] * mat_[15];
258 inline const Scalar* raw()
const {
return mat_; }
259 inline const Scalar* data()
const {
return mat_; }
279template<
typename Scalar>
283 for(
int i=0; i<4; i++)
285 for(
int j=0; j<4; j++)
294template<
typename Scalar>
298 for(
int i=0; i<4; i++)
299 for(
int j=0; j<4; j++)
307#if defined(INCLUDE_TEMPLATES) && !defined(ACG_MATRIX4X4_C)
308#define ACG_MATRIX4X4_TEMPLATES
309#include "Matrix4x4T_impl.hh"
Matrix4x4T operator+(Matrix4x4T< Scalar > _rhs) const
self + _rhs
Matrix4x4T & operator*=(const Matrix4x4T< Scalar > &_rhs)
self *= _rhs
Matrix4x4T()
constructor: uninitialized values
Matrix4x4T(const Scalar _array[16])
const Scalar * get_raw_data() const
Matrix4x4T & leftMult(const Matrix4x4T< Scalar > &_rhs)
multiply from left: self = _rhs * self
const Scalar & operator()(unsigned int row, unsigned int col) const
access operator (read only)
VectorT< T, 3 > transform_vector(const VectorT< T, 3 > &_v) const
transform vector (x',y',z',0) = A * (x,y,z,0)
void identity()
setup an identity matrix
Matrix4x4T operator-(Matrix4x4T< Scalar > _rhs) const
self - _rhs
bool invert()
matrix inversion (returns true on success)
Matrix4x4T(const Matrix4x4T< OtherScalar > &_rhs)
construct from other matrix type
bool operator==(const Matrix4x4T< Scalar > &_rhs) const
compare two matrices (up to some epsilon)
bool is_identity() const
check if the matrix is the identity ( up to an epsilon )
void clear()
sets all elements to zero
Matrix4x4T & operator+=(const Matrix4x4T< Scalar > &_rhs)
self += _rhs
Matrix4x4T operator*(const Matrix4x4T< Scalar > &inst) const
self * _rhs
bool operator!=(const Matrix4x4T< Scalar > &_rhs) const
compare two matrices
Matrix4x4T & operator-=(const Matrix4x4T< Scalar > &_rhs)
self -= _rhs
Matrix4x4T< Scalar > & operator=(const Matrix4x4T< otherScalar > &_rhs)
assignment from other matrix type
Scalar & operator()(unsigned int row, unsigned int col)
access operator (read and write)
void transpose()
transpose matrix
VectorT< T, 3 > transform_point(const VectorT< T, 3 > &_v) const
transform point (x',y',z',1) = M * (x,y,z,1)
Namespace providing different geometric functions concerning angles.
Matrix4x4T< double > Matrix4x4d
typedef
std::ostream & operator<<(std::ostream &os, const Matrix4x4T< Scalar > &m)
output matrix to ostream os
Matrix4x4T< float > Matrix4x4f
typedef
std::istream & operator>>(std::istream &is, Matrix4x4T< Scalar > &m)
read the space-separated components of a vector from a stream */