53 #ifndef ACG_MATRIX4X4_HH 54 #define ACG_MATRIX4X4_HH 61 #include "../Config/ACGDefines.hh" 75 template<
typename Scalar>
inline bool checkEpsilon(Scalar x) {
76 return fabs(x) < (1e-6);
79 template<>
inline bool checkEpsilon(
float x) {
80 return fabs(x) < (1e-4);
91 template <
class Scalar>
100 template <
class OtherScalar>
108 std::copy(_array,_array+16, mat_);
116 template<
typename otherScalar>
120 for (
int i = 0; i < 16; ++i)
121 mat_[i] = Scalar(_rhs.data()[i]);
129 inline Scalar&
operator()(
unsigned int row,
unsigned int col) {
130 return mat_[(row)+((col)<<2)];
134 inline const Scalar&
operator()(
unsigned int row,
unsigned int col)
const {
135 return mat_[(row)+((col)<<2)];
142 const Scalar *a = mat_;
143 const Scalar *b = _rhs.mat_;
144 for(i=0;i< 16;i++,a++,b++)
145 if(! checkEpsilon( *a - *b ))
158 std::transform(mat_,mat_+16, _rhs.mat_, _rhs.mat_, std::plus<Scalar>());
164 std::transform(mat_,mat_+16, _rhs.mat_, _rhs.mat_, std::minus<Scalar>());
177 std::transform(mat_,mat_+16,_rhs.mat_, mat_, std::plus<Scalar>());
183 std::transform(mat_,mat_+16, _rhs.mat_, mat_, std::minus<Scalar>());
195 template <
typename T>
199 template <
typename T>
203 template <
typename T>
216 const Scalar *a = mat_;
218 for(i=0;i< 16;i++,a++,b++) {
219 if ( ( i == 0) || ( i == 5 ) || ( i == 10 ) || ( i == 15 ) )
223 if(! checkEpsilon( *a - b ))
237 Scalar determinant()
const {
238 return mat_[12] * mat_[9] * mat_[6] * mat_[3] - mat_[8] * mat_[13] * mat_[6] * mat_[3] -
239 mat_[12] * mat_[5] * mat_[10] * mat_[3] + mat_[4] * mat_[13] * mat_[10] * mat_[3] +
240 mat_[8] * mat_[5] * mat_[14] * mat_[3] - mat_[4] * mat_[9] * mat_[14] * mat_[3] -
241 mat_[12] * mat_[9] * mat_[2] * mat_[7] + mat_[8] * mat_[13] * mat_[2] * mat_[7] +
242 mat_[12] * mat_[1] * mat_[10] * mat_[7] - mat_[0] * mat_[13] * mat_[10] * mat_[7] -
243 mat_[8] * mat_[1] * mat_[14] * mat_[7] + mat_[0] * mat_[9] * mat_[14] * mat_[7] +
244 mat_[12] * mat_[5] * mat_[2] * mat_[11] - mat_[4] * mat_[13] * mat_[2] * mat_[11] -
245 mat_[12] * mat_[1] * mat_[6] * mat_[11] + mat_[0] * mat_[13] * mat_[6] * mat_[11] +
246 mat_[4] * mat_[1] * mat_[14] * mat_[11] - mat_[0] * mat_[5] * mat_[14] * mat_[11] -
247 mat_[8] * mat_[5] * mat_[2] * mat_[15] + mat_[4] * mat_[9] * mat_[2] * mat_[15] +
248 mat_[8] * mat_[1] * mat_[6] * mat_[15] - mat_[0] * mat_[9] * mat_[6] * mat_[15] -
249 mat_[4] * mat_[1] * mat_[10] * mat_[15] + mat_[0] * mat_[5] * mat_[10] * mat_[15];
257 inline const Scalar* raw()
const {
return mat_; }
258 inline const Scalar* data()
const {
return mat_; }
278 template<
typename Scalar>
280 operator<<(std::ostream& os, const Matrix4x4T<Scalar>& m)
282 for(
int i=0; i<4; i++)
284 for(
int j=0; j<4; j++)
293 template<
typename Scalar>
297 for(
int i=0; i<4; i++)
298 for(
int j=0; j<4; j++)
306 #if defined(INCLUDE_TEMPLATES) && !defined(ACG_MATRIX4X4_C) 307 #define ACG_MATRIX4X4_TEMPLATES 308 #include "Matrix4x4T_impl.hh" 311 #endif // ACG_MATRIX4X4_HH defined Matrix4x4T & leftMult(const Matrix4x4T< Scalar > &_rhs)
multiply from left: self = _rhs * self
bool invert()
matrix inversion (returns true on success)
bool is_identity() const
check if the matrix is the identity ( up to an epsilon )
std::istream & operator>>(std::istream &is, Matrix4x4T< Scalar > &m)
read the space-separated components of a vector from a stream */
Namespace providing different geometric functions concerning angles.
Matrix4x4T()
constructor: uninitialized values
bool operator!=(const Matrix4x4T< Scalar > &_rhs) const
compare two matrices
Matrix4x4T operator-(Matrix4x4T< Scalar > _rhs) const
self - _rhs
void clear()
sets all elements to zero
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
Matrix4x4T(const Scalar _array[16])
Matrix4x4T< double > Matrix4x4d
typedef
void transpose()
transpose matrix
Matrix4x4T operator*(const Matrix4x4T< Scalar > &inst) const
self * _rhs
Matrix4x4T operator+(Matrix4x4T< Scalar > _rhs) const
self + _rhs
Matrix4x4T & operator*=(const Matrix4x4T< Scalar > &_rhs)
self *= _rhs
Scalar & operator()(unsigned int row, unsigned int col)
access operator (read and write)
const Scalar * get_raw_data() const
Matrix4x4T< Scalar > & operator=(const Matrix4x4T< otherScalar > &_rhs)
assignment from other matrix type
const Scalar & operator()(unsigned int row, unsigned int col) const
access operator (read only)
bool operator==(const Matrix4x4T< Scalar > &_rhs) const
compare two matrices (up to some epsilon)
Matrix4x4T(const Matrix4x4T< OtherScalar > &_rhs)
construct from other matrix type
void identity()
setup an identity matrix
VectorT< T, 3 > transform_vector(const VectorT< T, 3 > &_v) const
transform vector (x',y',z',0) = A * (x,y,z,0)
Matrix4x4T & operator+=(const Matrix4x4T< Scalar > &_rhs)
self += _rhs
Matrix4x4T< float > Matrix4x4f
typedef