Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

NUM::OMatrix< T > Class Template Reference

3x4 object transform matrix class. More...

#include <omatrix.h>

Collaboration diagram for NUM::OMatrix< T >:

Collaboration graph
[legend]
List of all members.

Public Types

enum  _Add { Add }
 Dummy enums for constructor selection; mostly internal use. More...

enum  _Sub { Sub }
enum  _Mul { Mul }
enum  _Div { Div }
enum  _Null { Null }
enum  _Ident { Ident, Identity }
enum  _Scale { Scale }
enum  _Translate { Translate }
enum  _Rotate { Rotate }
enum  _Invers { Invers }
enum  _Transpose { Transpose }

Public Member Functions

 OMatrix ()
 Default constructor does not initialize the variables.

 OMatrix (const OMatrix &a)
 Copy-constructor as usual.

 OMatrix (enum _Null)
 Construct matrix with all elements set to 0.

 OMatrix (enum _Ident)
 Construct identitiy matrix.

 OMatrix (T m00, T m01, T m02, T m03, T m10, T m11, T m12, T m13, T m20, T m21, T m22, T m23, T m30, T m31, T m32, T m33)
 Construct a matrix with specified values, row-by-row.

 OMatrix (enum _Add, const OMatrix< T > &a, const OMatrix< T > &b)
 Construct matrix as sum of two passed matrices.

 OMatrix (enum _Sub, const OMatrix< T > &a, const OMatrix< T > &b)
 Construct matrix as difference of two passed matrices.

 OMatrix (enum _Mul, const OMatrix< T > &a, T b)
 Construct matrix as multiplication of matrix a with scalar b.

 OMatrix (enum _Div, const OMatrix< T > &a, T b)
 Construct matrix as division of matrix a by scalar b.

 OMatrix (enum _Mul, const OMatrix< T > &a, const OMatrix< T > &b)
 Construct matrix as multiplication of matrix a with matrix b.

 OMatrix (enum _Scale, T f)
 Construct scaling transform matrix,.

 OMatrix (enum _Scale, const Vector3< T > &f)
 Construct scaling transform matrix,.

 OMatrix (enum _Translate, const Vector3< T > &d)
 Construct translation transform matrix,.

 OMatrix (enum _Rotate, const Vector3< T > &axis, T angle)
 Construct rotation transform matrix; USE ONLY for normalized axis!

 OMatrix (enum _Invers, const OMatrix< T > &a)
 Construct matrix which is inversion of passed matrix.

 OMatrix (enum _Transpose, const OMatrix< T > &a)
 ~OMatrix ()
 Destructor (a no-op).

T * operator[] (int r)
const T * operator[] (int r) const
int nrows () const
 Get number of rows of object matrix. This is always 3.

int ncols () const
 Get number of columns of object matrix. This is always 4.

OMatrixoperator= (const OMatrix &a)
 Assignment operator: Copy passed matrix.

OMatrixzero ()
 Set matrix to zero.

OMatrixidentity ()
 Set matrix to identity matrix.

OMatrixoperator+= (const OMatrix &a)
 Add a matrix to this one:.

OMatrixoperator-= (const OMatrix &a)
 Subtract a matrix from this one:.

OMatrixoperator *= (T a)
 Multiply matrix with sclar value:.

OMatrixoperator/= (T a)
OMatrixoperator *= (const OMatrix &b)
 Multiply this matrix with another matrix from LEFT.

OMatrixoperator/= (const OMatrix &a)
 Multiply this matrix with another matrix from RIGHT.

OMatrixneg ()
 Change the sign of every element:.

OMatrixtranspose ()
determinant () const
bool IsNull (T epsilon) const

Private Member Functions

void _copy (const OMatrix &a)
void _zero ()
void _identity ()

Private Attributes

m [3][4]
 Internally stores the matrix.


Detailed Description

template<typename T = dbl>
class NUM::OMatrix< T >

3x4 object transform matrix class.

Author:
Wolfgang Wieser ] wwieser (a) gmx <*> de [
This is a simple non-reference counting implementation of the object matrix.

Todo:
Write a ref-counting version (like TLString) and see if it is faster. (To be done when the application actually works.)
This class is meant to be quite fast and hence does applies some optimizations like:

Definition at line 49 of file omatrix.h.


Member Enumeration Documentation

template<typename T = dbl>
enum NUM::OMatrix::_Add
 

Dummy enums for constructor selection; mostly internal use.

Enumeration values:
Add 

Definition at line 69 of file omatrix.h.

template<typename T = dbl>
enum NUM::OMatrix::_Div
 

Enumeration values:
Div 

Definition at line 72 of file omatrix.h.

template<typename T = dbl>
enum NUM::OMatrix::_Ident
 

Enumeration values:
Ident 
Identity 

Definition at line 74 of file omatrix.h.

template<typename T = dbl>
enum NUM::OMatrix::_Invers
 

Enumeration values:
Invers 

Definition at line 78 of file omatrix.h.

template<typename T = dbl>
enum NUM::OMatrix::_Mul
 

Enumeration values:
Mul 

Definition at line 71 of file omatrix.h.

template<typename T = dbl>
enum NUM::OMatrix::_Null
 

Enumeration values:
Null 

Definition at line 73 of file omatrix.h.

template<typename T = dbl>
enum NUM::OMatrix::_Rotate
 

Enumeration values:
Rotate 

Definition at line 77 of file omatrix.h.

template<typename T = dbl>
enum NUM::OMatrix::_Scale
 

Enumeration values:
Scale 

Definition at line 75 of file omatrix.h.

template<typename T = dbl>
enum NUM::OMatrix::_Sub
 

Enumeration values:
Sub 

Definition at line 70 of file omatrix.h.

template<typename T = dbl>
enum NUM::OMatrix::_Translate
 

Enumeration values:
Translate 

Definition at line 76 of file omatrix.h.

template<typename T = dbl>
enum NUM::OMatrix::_Transpose
 

Enumeration values:
Transpose 

Definition at line 79 of file omatrix.h.


Constructor & Destructor Documentation

template<typename T = dbl>
NUM::OMatrix< T >::OMatrix  )  [inline]
 

Default constructor does not initialize the variables.

Definition at line 83 of file omatrix.h.

template<typename T = dbl>
NUM::OMatrix< T >::OMatrix const OMatrix< T > &  a  )  [inline]
 

Copy-constructor as usual.

Definition at line 85 of file omatrix.h.

References NUM::OMatrix< T >::_copy().

template<typename T = dbl>
NUM::OMatrix< T >::OMatrix enum  _Null  )  [inline]
 

Construct matrix with all elements set to 0.

Definition at line 87 of file omatrix.h.

References NUM::OMatrix< T >::_zero().

template<typename T = dbl>
NUM::OMatrix< T >::OMatrix enum  _Ident  )  [inline]
 

Construct identitiy matrix.

Definition at line 89 of file omatrix.h.

References NUM::OMatrix< T >::_identity().

template<typename T = dbl>
NUM::OMatrix< T >::OMatrix m00,
m01,
m02,
m03,
m10,
m11,
m12,
m13,
m20,
m21,
m22,
m23,
m30,
m31,
m32,
m33
[inline]
 

Construct a matrix with specified values, row-by-row.

Definition at line 91 of file omatrix.h.

References NUM::OMatrix< T >::m.

template<typename T = dbl>
NUM::OMatrix< T >::OMatrix enum  _Add,
const OMatrix< T > &  a,
const OMatrix< T > &  b
[inline]
 

Construct matrix as sum of two passed matrices.

Definition at line 102 of file omatrix.h.

References NUM::OMatrix< T >::m.

template<typename T = dbl>
NUM::OMatrix< T >::OMatrix enum  _Sub,
const OMatrix< T > &  a,
const OMatrix< T > &  b
[inline]
 

Construct matrix as difference of two passed matrices.

Definition at line 109 of file omatrix.h.

References NUM::OMatrix< T >::m.

template<typename T = dbl>
NUM::OMatrix< T >::OMatrix enum  _Mul,
const OMatrix< T > &  a,
b
[inline]
 

Construct matrix as multiplication of matrix a with scalar b.

Definition at line 116 of file omatrix.h.

References NUM::OMatrix< T >::m.

template<typename T = dbl>
NUM::OMatrix< T >::OMatrix enum  _Div,
const OMatrix< T > &  a,
b
[inline]
 

Construct matrix as division of matrix a by scalar b.

Definition at line 123 of file omatrix.h.

References NUM::OMatrix< T >::m.

template<typename T>
NUM::OMatrix< T >::OMatrix enum  _Mul,
const OMatrix< T > &  a,
const OMatrix< T > &  b
 

Construct matrix as multiplication of matrix a with matrix b.

Definition at line 44 of file omatrix.cc.

References NUM::OMatrix< T >::m.

template<typename T = dbl>
NUM::OMatrix< T >::OMatrix enum  _Scale,
f
[inline]
 

Construct scaling transform matrix,.

Definition at line 132 of file omatrix.h.

References NUM::OMatrix< T >::m.

template<typename T = dbl>
NUM::OMatrix< T >::OMatrix enum  _Scale,
const Vector3< T > &  f
[inline]
 

Construct scaling transform matrix,.

Definition at line 138 of file omatrix.h.

References NUM::OMatrix< T >::m.

template<typename T = dbl>
NUM::OMatrix< T >::OMatrix enum  _Translate,
const Vector3< T > &  d
[inline]
 

Construct translation transform matrix,.

Definition at line 144 of file omatrix.h.

References NUM::OMatrix< T >::m.

template<typename T>
NUM::OMatrix< T >::OMatrix enum  _Rotate,
const Vector3< T > &  axis,
angle
 

Construct rotation transform matrix; USE ONLY for normalized axis!

Todo:
test this; maybe the matrix needs transposing.
IIRC, the invariant angle for rotations can be calclated as
omega = 1/2*(R - R^t) --> x in R^3
where the mapping is
x[0] = omega[0][1], x[1] = -omega[0][2], x[2] = omega[1][2].

Definition at line 114 of file omatrix.cc.

References NUM::angle(), NUM::OMatrix< T >::m, NUM::sincos(), and NUM::sqr().

template<typename T>
NUM::OMatrix< T >::OMatrix enum  _Invers,
const OMatrix< T > &  a
 

Construct matrix which is inversion of passed matrix.

Definition at line 149 of file omatrix.cc.

References NUM::OMatrix< T >::m.

template<typename T = dbl>
NUM::OMatrix< T >::OMatrix enum  _Transpose,
const OMatrix< T > &  a
[inline]
 

Construcz matrix which is transposed version of passed matrix. See the transpose() method for important information.

Definition at line 156 of file omatrix.h.

References NUM::OMatrix< T >::m.

template<typename T = dbl>
NUM::OMatrix< T >::~OMatrix  )  [inline]
 

Destructor (a no-op).

Definition at line 163 of file omatrix.h.


Member Function Documentation

template<typename T = dbl>
void NUM::OMatrix< T >::_copy const OMatrix< T > &  a  )  [inline, private]
 

Definition at line 55 of file omatrix.h.

References NUM::OMatrix< T >::m.

Referenced by NUM::OMatrix< T >::OMatrix(), and NUM::OMatrix< T >::operator=().

template<typename T = dbl>
void NUM::OMatrix< T >::_identity  )  [inline, private]
 

Definition at line 64 of file omatrix.h.

References NUM::OMatrix< T >::m.

Referenced by NUM::OMatrix< T >::identity(), and NUM::OMatrix< T >::OMatrix().

template<typename T = dbl>
void NUM::OMatrix< T >::_zero  )  [inline, private]
 

Definition at line 61 of file omatrix.h.

References NUM::OMatrix< T >::m.

Referenced by NUM::OMatrix< T >::OMatrix(), and NUM::OMatrix< T >::zero().

template<typename T = dbl>
T NUM::OMatrix< T >::determinant  )  const [inline]
 

Compute determinant of the 3x3 rotation part of the matrix: (Note: untested code)

Definition at line 290 of file omatrix.h.

References NUM::OMatrix< T >::m.

template<typename T = dbl>
OMatrix& NUM::OMatrix< T >::identity  )  [inline]
 

Set matrix to identity matrix.

Definition at line 186 of file omatrix.h.

References NUM::OMatrix< T >::_identity().

template<typename T = dbl>
bool NUM::OMatrix< T >::IsNull epsilon  )  const [inline]
 

Compare matrix against 0 with specified epsilon value:

See also:
equal() to compare two matrices.

Definition at line 297 of file omatrix.h.

References NUM::fabs(), and NUM::OMatrix< T >::m.

template<typename T = dbl>
int NUM::OMatrix< T >::ncols  )  const [inline]
 

Get number of columns of object matrix. This is always 4.

Definition at line 174 of file omatrix.h.

template<typename T = dbl>
OMatrix& NUM::OMatrix< T >::neg  )  [inline]
 

Change the sign of every element:.

Definition at line 262 of file omatrix.h.

References NUM::OMatrix< T >::m.

template<typename T = dbl>
int NUM::OMatrix< T >::nrows  )  const [inline]
 

Get number of rows of object matrix. This is always 3.

Definition at line 171 of file omatrix.h.

template<typename T>
OMatrix< T > & NUM::OMatrix< T >::operator *= const OMatrix< T > &  b  ) 
 

Multiply this matrix with another matrix from LEFT.

This operator calculates this := this*b.
This means that the transform b is done BEFORE the transform stored in *this.

See also:
operator/=().

Definition at line 61 of file omatrix.cc.

References NUM::OMatrix< T >::m.

template<typename T = dbl>
OMatrix& NUM::OMatrix< T >::operator *= a  )  [inline]
 

Multiply matrix with sclar value:.

Definition at line 207 of file omatrix.h.

References NUM::OMatrix< T >::m.

template<typename T = dbl>
OMatrix& NUM::OMatrix< T >::operator+= const OMatrix< T > &  a  )  [inline]
 

Add a matrix to this one:.

Definition at line 190 of file omatrix.h.

References NUM::OMatrix< T >::m.

template<typename T = dbl>
OMatrix& NUM::OMatrix< T >::operator-= const OMatrix< T > &  a  )  [inline]
 

Subtract a matrix from this one:.

Definition at line 198 of file omatrix.h.

References NUM::OMatrix< T >::m.

template<typename T>
OMatrix< T > & NUM::OMatrix< T >::operator/= const OMatrix< T > &  a  ) 
 

Multiply this matrix with another matrix from RIGHT.

This operator calculates this := a*this.
This means that the transform b is done AFTER the transform stored in *this, i.e. if you want to first scale and then translate the object, then you can do:

   OMatrix trafo(OMatrix::Ident);
   trafo/=OMatrix(OMatrix::Scale,fact);
   trafo/=OMatrix(OMatrix::Translate,vect);

which is identical to

   OMatrix trafo=OMatrix(OMatrix::Translate,vect) * 
      OMatrix(OMatrix::Scale,fact);

If you now compute trafo*vect, the vect will be first scaled and then translated.

See also:
operator*=().

Definition at line 85 of file omatrix.cc.

References NUM::OMatrix< T >::m.

template<typename T = dbl>
OMatrix& NUM::OMatrix< T >::operator/= a  )  [inline]
 

Divide matrix by scalar value. For speed reasons, you should better multiply with 1/a.

Definition at line 215 of file omatrix.h.

References NUM::OMatrix< T >::m.

template<typename T = dbl>
OMatrix& NUM::OMatrix< T >::operator= const OMatrix< T > &  a  )  [inline]
 

Assignment operator: Copy passed matrix.

Definition at line 178 of file omatrix.h.

References NUM::OMatrix< T >::_copy().

template<typename T = dbl>
const T* NUM::OMatrix< T >::operator[] int  r  )  const [inline]
 

Definition at line 168 of file omatrix.h.

References NUM::OMatrix< T >::m.

template<typename T = dbl>
T* NUM::OMatrix< T >::operator[] int  r  )  [inline]
 

Access to the matrix members. Indices [0,1,2][0,1,2,3]. No range check.

Definition at line 167 of file omatrix.h.

References NUM::OMatrix< T >::m.

template<typename T = dbl>
OMatrix& NUM::OMatrix< T >::transpose  )  [inline]
 

Transpose matrix.

Note:
Only the rotation part of the matrix is transposed, the translation column stays as it is. This is useful since computation of an inverse of a rotation matrix can be easily accomplished by transposing the matrix but as soon as there is a translation component, you need to do full-blown matrix inversion anyways.
(The scaling part is unaffected since it is on the diagonal.)

Definition at line 281 of file omatrix.h.

References NUM::OMatrix< T >::m.

template<typename T = dbl>
OMatrix& NUM::OMatrix< T >::zero  )  [inline]
 

Set matrix to zero.

Definition at line 182 of file omatrix.h.

References NUM::OMatrix< T >::_zero().


Member Data Documentation

template<typename T = dbl>
T NUM::OMatrix< T >::m[3][4] [private]
 

Internally stores the matrix.

Definition at line 53 of file omatrix.h.

Referenced by NUM::OMatrix< T >::_copy(), NUM::OMatrix< T >::_identity(), NUM::OMatrix< T >::_zero(), NUM::OMatrix< T >::determinant(), NUM::OMatrix< T >::IsNull(), NUM::OMatrix< T >::neg(), NUM::OMatrix< T >::OMatrix(), NUM::OMatrix< T >::operator *=(), NUM::OMatrix< T >::operator+=(), NUM::OMatrix< T >::operator-=(), NUM::OMatrix< T >::operator/=(), NUM::OMatrix< T >::operator[](), and NUM::OMatrix< T >::transpose().


The documentation for this class was generated from the following files:
Generated on Sat Feb 19 22:35:56 2005 for Ray by doxygen 1.3.5