59 #ifndef ACG_MATRIX4X4_HH 60 #define ACG_MATRIX4X4_HH 67 #include "../Config/ACGDefines.hh" 81 template<
typename Scalar>
inline bool checkEpsilon(Scalar x) {
82 return fabs(x) < (1e-6);
85 template<>
inline bool checkEpsilon(
float x) {
86 return fabs(x) < (1e-4);
97 template <
class Scalar>
106 template <
class OtherScalar>
114 std::copy(_array,_array+16, mat_);
122 template<
typename otherScalar>
126 for (
int i = 0; i < 16; ++i)
127 mat_[i] = Scalar(_rhs.data()[i]);
135 inline Scalar&
operator()(
unsigned int row,
unsigned int col) {
136 return mat_[(row)+((col)<<2)];
140 inline const Scalar&
operator()(
unsigned int row,
unsigned int col)
const {
141 return mat_[(row)+((col)<<2)];
148 const Scalar *a = mat_;
149 const Scalar *b = _rhs.mat_;
150 for(i=0;i< 16;i++,a++,b++)
151 if(! checkEpsilon( *a - *b ))
164 std::transform(mat_,mat_+16, _rhs.mat_, _rhs.mat_, std::plus<Scalar>());
170 std::transform(mat_,mat_+16, _rhs.mat_, _rhs.mat_, std::minus<Scalar>());
183 std::transform(mat_,mat_+16,_rhs.mat_, mat_, std::plus<Scalar>());
189 std::transform(mat_,mat_+16, _rhs.mat_, mat_, std::minus<Scalar>());
201 template <
typename T>
205 template <
typename T>
209 template <
typename T>
222 const Scalar *a = mat_;
224 for(i=0;i< 16;i++,a++,b++) {
225 if ( ( i == 0) || ( i == 5 ) || ( i == 10 ) || ( i == 15 ) )
229 if(! checkEpsilon( *a - b ))
243 Scalar determinant()
const {
244 return mat_[12] * mat_[9] * mat_[6] * mat_[3] - mat_[8] * mat_[13] * mat_[6] * mat_[3] -
245 mat_[12] * mat_[5] * mat_[10] * mat_[3] + mat_[4] * mat_[13] * mat_[10] * mat_[3] +
246 mat_[8] * mat_[5] * mat_[14] * mat_[3] - mat_[4] * mat_[9] * mat_[14] * mat_[3] -
247 mat_[12] * mat_[9] * mat_[2] * mat_[7] + mat_[8] * mat_[13] * mat_[2] * mat_[7] +
248 mat_[12] * mat_[1] * mat_[10] * mat_[7] - mat_[0] * mat_[13] * mat_[10] * mat_[7] -
249 mat_[8] * mat_[1] * mat_[14] * mat_[7] + mat_[0] * mat_[9] * mat_[14] * mat_[7] +
250 mat_[12] * mat_[5] * mat_[2] * mat_[11] - mat_[4] * mat_[13] * mat_[2] * mat_[11] -
251 mat_[12] * mat_[1] * mat_[6] * mat_[11] + mat_[0] * mat_[13] * mat_[6] * mat_[11] +
252 mat_[4] * mat_[1] * mat_[14] * mat_[11] - mat_[0] * mat_[5] * mat_[14] * mat_[11] -
253 mat_[8] * mat_[5] * mat_[2] * mat_[15] + mat_[4] * mat_[9] * mat_[2] * mat_[15] +
254 mat_[8] * mat_[1] * mat_[6] * mat_[15] - mat_[0] * mat_[9] * mat_[6] * mat_[15] -
255 mat_[4] * mat_[1] * mat_[10] * mat_[15] + mat_[0] * mat_[5] * mat_[10] * mat_[15];
263 inline const Scalar* raw()
const {
return mat_; }
264 inline const Scalar* data()
const {
return mat_; }
284 template<
typename Scalar>
286 operator<<(std::ostream& os, const Matrix4x4T<Scalar>& m)
288 for(
int i=0; i<4; i++)
290 for(
int j=0; j<4; j++)
299 template<
typename Scalar>
303 for(
int i=0; i<4; i++)
304 for(
int j=0; j<4; j++)
312 #if defined(INCLUDE_TEMPLATES) && !defined(ACG_MATRIX4X4_C) 313 #define ACG_MATRIX4X4_TEMPLATES 314 #include "Matrix4x4T.cc" 317 #endif // ACG_MATRIX4X4_HH defined Matrix4x4T(const Scalar _array[16])
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)
Matrix4x4T & operator*=(const Matrix4x4T< Scalar > &_rhs)
self *= _rhs
const Scalar & operator()(unsigned int row, unsigned int col) const
access operator (read only)
Matrix4x4T & operator+=(const Matrix4x4T< Scalar > &_rhs)
self += _rhs
bool is_identity() const
check if the matrix is the identity ( up to an epsilon )
void identity()
setup an identity matrix
std::istream & operator>>(std::istream &is, Matrix4x4T< Scalar > &m)
read the space-separated components of a vector from a stream */
bool operator!=(const Matrix4x4T< Scalar > &_rhs) const
compare two matrices
Matrix4x4T & leftMult(const Matrix4x4T< Scalar > &_rhs)
multiply from left: self = _rhs * self
Matrix4x4T & operator-=(const Matrix4x4T< Scalar > &_rhs)
self -= _rhs
const Scalar * get_raw_data() const
Namespace providing different geometric functions concerning angles.
Matrix4x4T()
constructor: uninitialized values
Matrix4x4T< double > Matrix4x4d
typedef
bool operator==(const Matrix4x4T< Scalar > &_rhs) const
compare two matrices (up to some epsilon)
Matrix4x4T< Scalar > & operator=(const Matrix4x4T< otherScalar > &_rhs)
assignment from other matrix type
bool invert()
matrix inversion (returns true on success)
Matrix4x4T operator*(const Matrix4x4T< Scalar > &inst) const
self * _rhs
Matrix4x4T< float > Matrix4x4f
typedef
Matrix4x4T operator+(Matrix4x4T< Scalar > _rhs) const
self + _rhs
Matrix4x4T(const Matrix4x4T< OtherScalar > &_rhs)
construct from other matrix type
Matrix4x4T operator-(Matrix4x4T< Scalar > _rhs) const
self - _rhs
Scalar & operator()(unsigned int row, unsigned int col)
access operator (read and write)
void clear()
sets all elements to zero
VectorT< T, 3 > transform_vector(const VectorT< T, 3 > &_v) const
transform vector (x',y',z',0) = A * (x,y,z,0)