Back to index

nux  3.0.0
Public Member Functions | Static Public Member Functions | Public Attributes
nux::Matrix4x4< T > Class Template Reference

#include <Matrix4.h>

Inheritance diagram for nux::Matrix4x4< T >:
Inheritance graph
[legend]
Collaboration diagram for nux::Matrix4x4< T >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Matrix4x4 ()
 ~Matrix4x4 ()
 Matrix4x4 (const Matrix4x4 &)
 Matrix4x4 (T a00, T a01, T a02, T a03, T a10, T a11, T a12, T a13, T a20, T a21, T a22, T a23, T a30, T a31, T a32, T a33)
Matrix4x4< T > & operator= (const Matrix4x4< T > &)
bool operator== (const Matrix4x4< T > &)
Matrix4x4< T > operator* (const Matrix4x4< T > &) const
Matrix4x4< T > operator+ (const Matrix4x4< T > &) const
Matrix4x4< T > operator- (const Matrix4x4< T > &) const
Matrix4x4< T > & operator*= (const Matrix4x4< T > &) const
Matrix4x4< T > & operator+= (const Matrix4x4< T > &) const
Matrix4x4< T > & operator-= (const Matrix4x4< T > &) const
Matrix4x4< T > operator* (const T &) const
Matrix4x4< T > operator/ (const T &) const
Matrix4x4< T > operator*= (const T &) const
Matrix4x4< T > operator/= (const T &) const
Vector4 operator* (const Vector4 &) const
Matrix4x4< T > operator- ()
T & operator() (unsigned int i, unsigned int j)
operator() (unsigned int i, unsigned int j) const
 operator T * ()
 operator const T * () const
void Translate (T x, T y, T z)
void Translate (const Vector3 &)
void Rotate_x (T angle)
void Rotate_y (T angle)
void Rotate_z (T angle)
void Scale (T sx, T sy, T sz)
Trace () const
Determinant () const
void Inverse ()
Matrix4x4< T > GetInverse () const
void Transpose ()
void Scale (T s)
void Diagonal (T x, T y, T z, T w=T(1))
void Rotate (T angle, Vector3 axis)
void LookAt (const Vector3 &eye, const Vector3 &at, const Vector3 &up)
void Orthographic (T l, T r, T b, T t, T n, T f)
 set to an orthographic projection matrix.
void Perspective (T l, T r, T t, T b, T n, T f)
 set to a perspective projection matrix.
void PerspectiveInverse (T l, T r, T t, T b, T n, T f)
void Perspective (T FoV, T AspectRatio, T NearPlane, T FarPlane)
 set to a perspective projection matrix specified in terms of field of view and aspect ratio.
void Zero ()
void Identity ()

Static Public Member Functions

static Matrix4x4< T > IDENTITY ()
static Matrix4x4< T > ZERO ()
static Matrix4x4< T > ROTATEX (T angle)
static Matrix4x4< T > ROTATEY (T angle)
static Matrix4x4< T > ROTATEZ (T angle)
static Matrix4x4< T > TRANSLATE (T x, T y, T z)
static Matrix4x4< T > SCALE (T x, T y, T z)

Public Attributes

m [4][4]

Detailed Description

template<typename T>
class nux::Matrix4x4< T >

Definition at line 45 of file Matrix4.h.


Constructor & Destructor Documentation

template<typename T >
nux::Matrix4x4< T >::Matrix4x4 ( )

Definition at line 139 of file Matrix4.h.

  {
    Identity();
  }
template<typename T >
nux::Matrix4x4< T >::~Matrix4x4 ( )

Definition at line 156 of file Matrix4.h.

  {

  }
template<typename T >
nux::Matrix4x4< T >::Matrix4x4 ( const Matrix4x4< T > &  M)

Definition at line 173 of file Matrix4.h.

  {
    m[0][0] = M.m[0][0];
    m[0][1] = M.m[0][1];
    m[0][2] = M.m[0][2];
    m[0][3] = M.m[0][3];
    m[1][0] = M.m[1][0];
    m[1][1] = M.m[1][1];
    m[1][2] = M.m[1][2];
    m[1][3] = M.m[1][3];
    m[2][0] = M.m[2][0];
    m[2][1] = M.m[2][1];
    m[2][2] = M.m[2][2];
    m[2][3] = M.m[2][3];
    m[3][0] = M.m[3][0];
    m[3][1] = M.m[3][1];
    m[3][2] = M.m[3][2];
    m[3][3] = M.m[3][3];
  }
template<typename T>
nux::Matrix4x4< T >::Matrix4x4 ( a00,
a01,
a02,
a03,
a10,
a11,
a12,
a13,
a20,
a21,
a22,
a23,
a30,
a31,
a32,
a33 
)

Definition at line 208 of file Matrix4.h.

  {
    m[0][0] = a00;
    m[0][1] = a01;
    m[0][2] = a02;
    m[0][3] = a03;
    m[1][0] = a10;
    m[1][1] = a11;
    m[1][2] = a12;
    m[1][3] = a13;
    m[2][0] = a20;
    m[2][1] = a21;
    m[2][2] = a22;
    m[2][3] = a23;
    m[3][0] = a30;
    m[3][1] = a31;
    m[3][2] = a32;
    m[3][3] = a33;
  }

Member Function Documentation

template<typename T >
T nux::Matrix4x4< T >::Determinant ( ) const

Definition at line 1020 of file Matrix4.h.

  {
    const T &m00 = m[0][0];
    const T &m01 = m[0][1];
    const T &m02 = m[0][2];
    const T &m03 = m[0][3];
    const T &m10 = m[1][0];
    const T &m11 = m[1][1];
    const T &m12 = m[1][2];
    const T &m13 = m[1][3];
    const T &m20 = m[2][0];
    const T &m21 = m[2][1];
    const T &m22 = m[2][2];
    const T &m23 = m[2][3];
    const T &m30 = m[3][0];
    const T &m31 = m[3][1];
    const T &m32 = m[3][2];
    const T &m33 = m[3][3];

    T det =
      m03 * m12 * m21 * m30 - m02 * m13 * m21 * m30 - m03 * m11 * m22 * m30 + m01 * m13 * m22 * m30 +
      m02 * m11 * m23 * m30 - m01 * m12 * m23 * m30 - m03 * m12 * m20 * m31 + m02 * m13 * m20 * m31 +
      m03 * m10 * m22 * m31 - m00 * m13 * m22 * m31 - m02 * m10 * m23 * m31 + m00 * m12 * m23 * m31 +
      m03 * m11 * m20 * m32 - m01 * m13 * m20 * m32 - m03 * m10 * m21 * m32 + m00 * m13 * m21 * m32 +
      m01 * m10 * m23 * m32 - m00 * m11 * m23 * m32 - m02 * m11 * m20 * m33 + m01 * m12 * m20 * m33 +
      m02 * m10 * m21 * m33 - m00 * m12 * m21 * m33 - m01 * m10 * m22 * m33 + m00 * m11 * m22 * m33;

    return det;
  }
template<typename T>
void nux::Matrix4x4< T >::Diagonal ( x,
y,
z,
w = T (1) 
)

Definition at line 1205 of file Matrix4.h.

  {
    m[0][0] = x;
    m[0][1] = 0.0;
    m[0][2] = 0.0;
    m[0][3] = 0.0;
    m[1][0] = 0.0;
    m[1][1] = y;
    m[1][2] = 0.0;
    m[1][3] = 0.0;
    m[2][0] = 0.0;
    m[2][1] = 0.0;
    m[2][2] = z;
    m[2][3] = 0.0;
    m[3][0] = 0.0;
    m[3][1] = 0.0;
    m[3][2] = 0.0;
    m[3][3] = w;
  }
template<typename T >
Matrix4x4< T > nux::Matrix4x4< T >::GetInverse ( ) const

Definition at line 1134 of file Matrix4.h.

  {
    Matrix4x4<T> Temp = *this;
    Temp.Inverse();
    return Temp;
  }

Here is the call graph for this function:

template<typename T >
void nux::Matrix4x4< T >::Identity ( )

Definition at line 797 of file Matrix4.h.

  {
    m[0][0] = 1.0;
    m[0][1] = 0.0;
    m[0][2] = 0.0;
    m[0][3] = 0.0;
    m[1][0] = 0.0;
    m[1][1] = 1.0;
    m[1][2] = 0.0;
    m[1][3] = 0.0;
    m[2][0] = 0.0;
    m[2][1] = 0.0;
    m[2][2] = 1.0;
    m[2][3] = 0.0;
    m[3][0] = 0.0;
    m[3][1] = 0.0;
    m[3][2] = 0.0;
    m[3][3] = 1.0;
  }

Here is the caller graph for this function:

template<typename T >
Matrix4x4< T > nux::Matrix4x4< T >::IDENTITY ( ) [static]

Definition at line 1421 of file Matrix4.h.

  {
    Matrix4x4<T> matrix;
    matrix.Identity();
    return matrix;
  }

Here is the call graph for this function:

template<typename T >
void nux::Matrix4x4< T >::Inverse ( )

Definition at line 1051 of file Matrix4.h.

  {
    T det = Determinant();

    if (det == T (0) )
    {
      // Determinant is null. Matrix cannot be inverted.
#ifdef NUX_DEBUG
      NUX_HARDWARE_BREAK;
#endif
      return;
    }

    const T &m00 = m[0][0];

    const T &m01 = m[0][1];

    const T &m02 = m[0][2];

    const T &m03 = m[0][3];

    const T &m10 = m[1][0];

    const T &m11 = m[1][1];

    const T &m12 = m[1][2];

    const T &m13 = m[1][3];

    const T &m20 = m[2][0];

    const T &m21 = m[2][1];

    const T &m22 = m[2][2];

    const T &m23 = m[2][3];

    const T &m30 = m[3][0];

    const T &m31 = m[3][1];

    const T &m32 = m[3][2];

    const T &m33 = m[3][3];

    Matrix4x4<T> Temp;

    Temp.m[0][0] = m12 * m23 * m31 - m13 * m22 * m31 + m13 * m21 * m32 - m11 * m23 * m32 - m12 * m21 * m33 + m11 * m22 * m33;

    Temp.m[0][1] = m03 * m22 * m31 - m02 * m23 * m31 - m03 * m21 * m32 + m01 * m23 * m32 + m02 * m21 * m33 - m01 * m22 * m33;

    Temp.m[0][2] = m02 * m13 * m31 - m03 * m12 * m31 + m03 * m11 * m32 - m01 * m13 * m32 - m02 * m11 * m33 + m01 * m12 * m33;

    Temp.m[0][3] = m03 * m12 * m21 - m02 * m13 * m21 - m03 * m11 * m22 + m01 * m13 * m22 + m02 * m11 * m23 - m01 * m12 * m23;

    Temp.m[1][0] = m13 * m22 * m30 - m12 * m23 * m30 - m13 * m20 * m32 + m10 * m23 * m32 + m12 * m20 * m33 - m10 * m22 * m33;

    Temp.m[1][1] = m02 * m23 * m30 - m03 * m22 * m30 + m03 * m20 * m32 - m00 * m23 * m32 - m02 * m20 * m33 + m00 * m22 * m33;

    Temp.m[1][2] = m03 * m12 * m30 - m02 * m13 * m30 - m03 * m10 * m32 + m00 * m13 * m32 + m02 * m10 * m33 - m00 * m12 * m33;

    Temp.m[1][3] = m02 * m13 * m20 - m03 * m12 * m20 + m03 * m10 * m22 - m00 * m13 * m22 - m02 * m10 * m23 + m00 * m12 * m23;

    Temp.m[2][0] = m11 * m23 * m30 - m13 * m21 * m30 + m13 * m20 * m31 - m10 * m23 * m31 - m11 * m20 * m33 + m10 * m21 * m33;

    Temp.m[2][1] = m03 * m21 * m30 - m01 * m23 * m30 - m03 * m20 * m31 + m00 * m23 * m31 + m01 * m20 * m33 - m00 * m21 * m33;

    Temp.m[2][2] = m01 * m13 * m30 - m03 * m11 * m30 + m03 * m10 * m31 - m00 * m13 * m31 - m01 * m10 * m33 + m00 * m11 * m33;

    Temp.m[2][3] = m03 * m11 * m20 - m01 * m13 * m20 - m03 * m10 * m21 + m00 * m13 * m21 + m01 * m10 * m23 - m00 * m11 * m23;

    Temp.m[3][0] = m12 * m21 * m30 - m11 * m22 * m30 - m12 * m20 * m31 + m10 * m22 * m31 + m11 * m20 * m32 - m10 * m21 * m32;

    Temp.m[3][1] = m01 * m22 * m30 - m02 * m21 * m30 + m02 * m20 * m31 - m00 * m22 * m31 - m01 * m20 * m32 + m00 * m21 * m32;

    Temp.m[3][2] = m02 * m11 * m30 - m01 * m12 * m30 - m02 * m10 * m31 + m00 * m12 * m31 + m01 * m10 * m32 - m00 * m11 * m32;

    Temp.m[3][3] = m01 * m12 * m20 - m02 * m11 * m20 + m02 * m10 * m21 - m00 * m12 * m21 - m01 * m10 * m22 + m00 * m11 * m22;

    *this = (T (1) / det) * Temp;
  }

Here is the caller graph for this function:

template<typename T >
void nux::Matrix4x4< T >::LookAt ( const Vector3 eye,
const Vector3 at,
const Vector3 up 
)

Definition at line 1277 of file Matrix4.h.

  {
    // left handed

    Vector3 z_axis = at - eye;
    Vector3 x_axis = z_axis.CrossProduct (up);
    Vector3 y_axis = x_axis.CrossProduct (z_axis);

    x_axis.Normalize();
    y_axis.Normalize();
    z_axis.Normalize();

    Matrix4x4<T> Rot;
    Rot.m[0][0]      = x_axis.x;
    Rot.m[0][1] = x_axis.y;
    Rot.m[0][2] = x_axis.z;
    Rot.m[0][3] = 0;

    Rot.m[1][0]      = y_axis.x;
    Rot.m[1][1] = y_axis.y;
    Rot.m[1][2] = y_axis.z;
    Rot.m[1][3] = 0;

    Rot.m[2][0]      = -z_axis.x;
    Rot.m[2][1] = -z_axis.y;
    Rot.m[2][2] = -z_axis.z;
    Rot.m[2][3] = 0;

    Rot.m[3][0]      = 0.0f;
    Rot.m[3][1] = 0.0f;
    Rot.m[3][2] = 0.0f;
    Rot.m[3][3] = 1.0f;

    Matrix4x4<T> Trans;
    Trans.Translate (-eye.x, -eye.y, -eye.z);

    *this = Rot * Trans;
  }

Here is the call graph for this function:

template<typename T >
nux::Matrix4x4< T >::operator const T * ( ) const

Definition at line 745 of file Matrix4.h.

  {
    return reinterpret_cast<const T *> (&m);
  }
template<typename T >
nux::Matrix4x4< T >::operator T * ( )

Definition at line 739 of file Matrix4.h.

  {
    return reinterpret_cast<T *> (&m);
  }
template<typename T >
T & nux::Matrix4x4< T >::operator() ( unsigned int  i,
unsigned int  j 
)

Definition at line 727 of file Matrix4.h.

  {
    return m[i][j];
  }
template<typename T >
T nux::Matrix4x4< T >::operator() ( unsigned int  i,
unsigned int  j 
) const

Definition at line 733 of file Matrix4.h.

  {
    return m[i][j];
  }
template<typename T>
Matrix4x4< T > nux::Matrix4x4< T >::operator* ( const Matrix4x4< T > &  iM) const

Definition at line 292 of file Matrix4.h.

  {
    Matrix4x4<T> oM;

    // Output matrix first row
    oM.m[0][0] = m[0][0] * iM.m[0][0] + m[0][1] * iM.m[1][0] + m[0][2] * iM.m[2][0] + m[0][3] * iM.m[3][0];
    oM.m[0][1] = m[0][0] * iM.m[0][1] + m[0][1] * iM.m[1][1] + m[0][2] * iM.m[2][1] + m[0][3] * iM.m[3][1];
    oM.m[0][2] = m[0][0] * iM.m[0][2] + m[0][1] * iM.m[1][2] + m[0][2] * iM.m[2][2] + m[0][3] * iM.m[3][2];
    oM.m[0][3] = m[0][0] * iM.m[0][3] + m[0][1] * iM.m[1][3] + m[0][2] * iM.m[2][3] + m[0][3] * iM.m[3][3];

    // Output matrix second row
    oM.m[1][0] = m[1][0] * iM.m[0][0] + m[1][1] * iM.m[1][0] + m[1][2] * iM.m[2][0] + m[1][3] * iM.m[3][0];
    oM.m[1][1] = m[1][0] * iM.m[0][1] + m[1][1] * iM.m[1][1] + m[1][2] * iM.m[2][1] + m[1][3] * iM.m[3][1];
    oM.m[1][2] = m[1][0] * iM.m[0][2] + m[1][1] * iM.m[1][2] + m[1][2] * iM.m[2][2] + m[1][3] * iM.m[3][2];
    oM.m[1][3] = m[1][0] * iM.m[0][3] + m[1][1] * iM.m[1][3] + m[1][2] * iM.m[2][3] + m[1][3] * iM.m[3][3];

    // Output matrix third row
    oM.m[2][0] = m[2][0] * iM.m[0][0] + m[2][1] * iM.m[1][0] + m[2][2] * iM.m[2][0] + m[2][3] * iM.m[3][0];
    oM.m[2][1] = m[2][0] * iM.m[0][1] + m[2][1] * iM.m[1][1] + m[2][2] * iM.m[2][1] + m[2][3] * iM.m[3][1];
    oM.m[2][2] = m[2][0] * iM.m[0][2] + m[2][1] * iM.m[1][2] + m[2][2] * iM.m[2][2] + m[2][3] * iM.m[3][2];
    oM.m[2][3] = m[2][0] * iM.m[0][3] + m[2][1] * iM.m[1][3] + m[2][2] * iM.m[2][3] + m[2][3] * iM.m[3][3];

    // Output matrix fourth row
    oM.m[3][0] = m[3][0] * iM.m[0][0] + m[3][1] * iM.m[1][0] + m[3][2] * iM.m[2][0] + m[3][3] * iM.m[3][0];
    oM.m[3][1] = m[3][0] * iM.m[0][1] + m[3][1] * iM.m[1][1] + m[3][2] * iM.m[2][1] + m[3][3] * iM.m[3][1];
    oM.m[3][2] = m[3][0] * iM.m[0][2] + m[3][1] * iM.m[1][2] + m[3][2] * iM.m[2][2] + m[3][3] * iM.m[3][2];
    oM.m[3][3] = m[3][0] * iM.m[0][3] + m[3][1] * iM.m[1][3] + m[3][2] * iM.m[2][3] + m[3][3] * iM.m[3][3];

    return oM;
  }
template<typename T>
Matrix4x4< T > nux::Matrix4x4< T >::operator* ( const T &  f) const

Definition at line 526 of file Matrix4.h.

  {
    Matrix4x4<T> oM;

    oM.m[0][0] = m[0][0] * f;
    oM.m[0][1] = m[0][1] * f;
    oM.m[0][2] = m[0][2] * f;
    oM.m[0][3] = m[0][3] * f;
    oM.m[1][0] = m[1][0] * f;
    oM.m[1][1] = m[1][1] * f;
    oM.m[1][2] = m[1][2] * f;
    oM.m[1][3] = m[1][3] * f;
    oM.m[2][0] = m[2][0] * f;
    oM.m[2][1] = m[2][1] * f;
    oM.m[2][2] = m[2][2] * f;
    oM.m[2][3] = m[2][3] * f;
    oM.m[3][0] = m[3][0] * f;
    oM.m[3][1] = m[3][1] * f;
    oM.m[3][2] = m[3][2] * f;
    oM.m[3][3] = m[3][3] * f;

    return oM;
  }
template<typename T>
Vector4 nux::Matrix4x4< T >::operator* ( const Vector4 V) const

Definition at line 675 of file Matrix4.h.

  {
    Vector4 oV;

    oV.x = V.x * m[0][0] + V.y * m[0][1] + V.z * m[0][2] + V.w * m[0][3];
    oV.y = V.x * m[1][0] + V.y * m[1][1] + V.z * m[1][2] + V.w * m[1][3];
    oV.z = V.x * m[2][0] + V.y * m[2][1] + V.z * m[2][2] + V.w * m[2][3];
    oV.w = V.x * m[3][0] + V.y * m[3][1] + V.z * m[3][2] + V.w * m[3][3];

    return oV;
  }
template<typename T>
Matrix4x4< T > & nux::Matrix4x4< T >::operator*= ( const Matrix4x4< T > &  iM) const

Definition at line 411 of file Matrix4.h.

  {
    Matrix4x4<T> oM;

    oM.m[0][0] = m[0][0] * iM.m[0][0] + m[0][1] * iM.m[1][0] + m[0][2] * iM.m[2][0] + m[0][3] * iM.m[3][0];
    oM.m[1][0] = m[1][0] * iM.m[0][0] + m[1][1] * iM.m[1][0] + m[1][2] * iM.m[2][0] + m[1][3] * iM.m[3][0];
    oM.m[2][0] = m[2][0] * iM.m[0][0] + m[2][1] * iM.m[1][0] + m[2][2] * iM.m[2][0] + m[2][3] * iM.m[3][0];
    oM.m[3][0] = m[3][0] * iM.m[0][0] + m[3][1] * iM.m[1][0] + m[3][2] * iM.m[2][0] + m[3][3] * iM.m[3][0];

    oM.m[0][1] = m[0][0] * iM.m[0][1] + m[0][1] * iM.m[1][1] + m[0][2] * iM.m[2][1] + m[0][3] * iM.m[3][1];
    oM.m[1][1] = m[1][0] * iM.m[0][1] + m[1][1] * iM.m[1][1] + m[1][2] * iM.m[2][1] + m[1][3] * iM.m[3][1];
    oM.m[2][1] = m[2][0] * iM.m[0][1] + m[2][1] * iM.m[1][1] + m[2][2] * iM.m[2][1] + m[2][3] * iM.m[3][1];
    oM.m[3][1] = m[3][0] * iM.m[0][1] + m[3][1] * iM.m[1][1] + m[3][2] * iM.m[2][1] + m[3][3] * iM.m[3][1];

    oM.m[0][2] = m[0][0] * iM.m[0][2] + m[0][1] * iM.m[1][2] + m[0][2] * iM.m[2][2] + m[0][3] * iM.m[3][2];
    oM.m[1][2] = m[1][0] * iM.m[0][2] + m[1][1] * iM.m[1][2] + m[1][2] * iM.m[2][2] + m[1][3] * iM.m[3][2];
    oM.m[2][2] = m[2][0] * iM.m[0][2] + m[2][1] * iM.m[1][2] + m[2][2] * iM.m[2][2] + m[2][3] * iM.m[3][2];
    oM.m[3][2] = m[3][0] * iM.m[0][2] + m[3][1] * iM.m[1][2] + m[3][2] * iM.m[2][2] + m[3][3] * iM.m[3][2];

    oM.m[0][3] = m[0][0] * iM.m[0][3] + m[0][1] * iM.m[1][3] + m[0][2] * iM.m[2][3] + m[0][3] * iM.m[3][3];
    oM.m[1][3] = m[1][0] * iM.m[0][3] + m[1][1] * iM.m[1][3] + m[1][2] * iM.m[2][3] + m[1][3] * iM.m[3][3];
    oM.m[2][3] = m[2][0] * iM.m[0][3] + m[2][1] * iM.m[1][3] + m[2][2] * iM.m[2][3] + m[2][3] * iM.m[3][3];
    oM.m[3][3] = m[3][0] * iM.m[0][3] + m[3][1] * iM.m[1][3] + m[3][2] * iM.m[2][3] + m[3][3] * iM.m[3][3];

    *this = oM;
    return *this;
  }
template<typename T>
Matrix4x4< T > nux::Matrix4x4< T >::operator*= ( const T &  f) const

Definition at line 601 of file Matrix4.h.

  {
    Matrix4x4<T> oM;

    oM.m[0][0] = m[0][0] * f;
    oM.m[0][1] = m[0][1] * f;
    oM.m[0][2] = m[0][2] * f;
    oM.m[0][3] = m[0][3] * f;
    oM.m[1][0] = m[1][0] * f;
    oM.m[1][1] = m[1][1] * f;
    oM.m[1][2] = m[1][2] * f;
    oM.m[1][3] = m[1][3] * f;
    oM.m[2][0] = m[2][0] * f;
    oM.m[2][1] = m[2][1] * f;
    oM.m[2][2] = m[2][2] * f;
    oM.m[2][3] = m[2][3] * f;
    oM.m[3][0] = m[3][0] * f;
    oM.m[3][1] = m[3][1] * f;
    oM.m[3][2] = m[3][2] * f;
    oM.m[3][3] = m[3][3] * f;

    *this = oM;
    return *this;
  }
template<typename T>
Matrix4x4< T > nux::Matrix4x4< T >::operator+ ( const Matrix4x4< T > &  iM) const

Definition at line 335 of file Matrix4.h.

  {
    Matrix4x4<T> oM;

    oM.m[0][0] = m[0][0] + iM.m[0][0];
    oM.m[0][1] = m[0][1] + iM.m[0][1];
    oM.m[0][2] = m[0][2] + iM.m[0][2];
    oM.m[0][3] = m[0][3] + iM.m[0][3];
    oM.m[1][0] = m[1][0] + iM.m[1][0];
    oM.m[1][1] = m[1][1] + iM.m[1][1];
    oM.m[1][2] = m[1][2] + iM.m[1][2];
    oM.m[1][3] = m[1][3] + iM.m[1][3];
    oM.m[2][0] = m[2][0] + iM.m[2][0];
    oM.m[2][1] = m[2][1] + iM.m[2][1];
    oM.m[2][2] = m[2][2] + iM.m[2][2];
    oM.m[2][3] = m[2][3] + iM.m[2][3];
    oM.m[3][0] = m[3][0] + iM.m[3][0];
    oM.m[3][1] = m[3][1] + iM.m[3][1];
    oM.m[3][2] = m[3][2] + iM.m[3][2];
    oM.m[3][3] = m[3][3] + iM.m[3][3];

    return oM;
  }
template<typename T>
Matrix4x4< T > & nux::Matrix4x4< T >::operator+= ( const Matrix4x4< T > &  iM) const

Definition at line 451 of file Matrix4.h.

  {
    Matrix4x4<T> oM;

    oM.m[0][0] = m[0][0] + iM.m[0][0];
    oM.m[0][1] = m[0][1] + iM.m[0][1];
    oM.m[0][2] = m[0][2] + iM.m[0][2];
    oM.m[0][3] = m[0][3] + iM.m[0][3];
    oM.m[1][0] = m[1][0] + iM.m[1][0];
    oM.m[1][1] = m[1][1] + iM.m[1][1];
    oM.m[1][2] = m[1][2] + iM.m[1][2];
    oM.m[1][3] = m[1][3] + iM.m[1][3];
    oM.m[2][0] = m[2][0] + iM.m[2][0];
    oM.m[2][1] = m[2][1] + iM.m[2][1];
    oM.m[2][2] = m[2][2] + iM.m[2][2];
    oM.m[2][3] = m[2][3] + iM.m[2][3];
    oM.m[3][0] = m[3][0] + iM.m[3][0];
    oM.m[3][1] = m[3][1] + iM.m[3][1];
    oM.m[3][2] = m[3][2] + iM.m[3][2];
    oM.m[3][3] = m[3][3] + iM.m[3][3];

    *this = oM;
    return *this;
  }
template<typename T>
Matrix4x4< T > nux::Matrix4x4< T >::operator- ( const Matrix4x4< T > &  iM) const

Definition at line 371 of file Matrix4.h.

  {
    Matrix4x4<T> oM;

    oM.m[0][0] = m[0][0] - iM.m[0][0];
    oM.m[0][1] = m[0][1] - iM.m[0][1];
    oM.m[0][2] = m[0][2] - iM.m[0][2];
    oM.m[0][3] = m[0][3] - iM.m[0][3];
    oM.m[1][0] = m[1][0] - iM.m[1][0];
    oM.m[1][1] = m[1][1] - iM.m[1][1];
    oM.m[1][2] = m[1][2] - iM.m[1][2];
    oM.m[1][3] = m[1][3] - iM.m[1][3];
    oM.m[2][0] = m[2][0] - iM.m[2][0];
    oM.m[2][1] = m[2][1] - iM.m[2][1];
    oM.m[2][2] = m[2][2] - iM.m[2][2];
    oM.m[2][3] = m[2][3] - iM.m[2][3];
    oM.m[3][0] = m[3][0] - iM.m[3][0];
    oM.m[3][1] = m[3][1] - iM.m[3][1];
    oM.m[3][2] = m[3][2] - iM.m[3][2];
    oM.m[3][3] = m[3][3] - iM.m[3][3];

    return oM;
  }
template<typename T>
Matrix4x4< T > nux::Matrix4x4< T >::operator- ( )

Definition at line 699 of file Matrix4.h.

  {
    Matrix4x4<T> oM;

    oM.m[0][0] = -m[0][0];
    oM.m[0][1] = -m[0][1];
    oM.m[0][2] = -m[0][2];
    oM.m[0][3] = -m[0][3];

    oM.m[1][0] = -m[1][0];
    oM.m[1][1] = -m[1][1];
    oM.m[1][2] = -m[1][2];
    oM.m[1][3] = -m[1][3];

    oM.m[2][0] = -m[2][0];
    oM.m[2][1] = -m[2][1];
    oM.m[2][2] = -m[2][2];
    oM.m[2][3] = -m[2][3];

    oM.m[3][0] = -m[3][0];
    oM.m[3][1] = -m[3][1];
    oM.m[3][2] = -m[3][2];
    oM.m[3][3] = -m[3][3];

    return oM;
  }
template<typename T>
Matrix4x4< T > & nux::Matrix4x4< T >::operator-= ( const Matrix4x4< T > &  iM) const

Definition at line 488 of file Matrix4.h.

  {
    Matrix4x4<T> oM;

    oM.m[0][0] = m[0][0] - iM.m[0][0];
    oM.m[0][1] = m[0][1] - iM.m[0][1];
    oM.m[0][2] = m[0][2] - iM.m[0][2];
    oM.m[0][3] = m[0][3] - iM.m[0][3];
    oM.m[1][0] = m[1][0] - iM.m[1][0];
    oM.m[1][1] = m[1][1] - iM.m[1][1];
    oM.m[1][2] = m[1][2] - iM.m[1][2];
    oM.m[1][3] = m[1][3] - iM.m[1][3];
    oM.m[2][0] = m[2][0] - iM.m[2][0];
    oM.m[2][1] = m[2][1] - iM.m[2][1];
    oM.m[2][2] = m[2][2] - iM.m[2][2];
    oM.m[2][3] = m[2][3] - iM.m[2][3];
    oM.m[3][0] = m[3][0] - iM.m[3][0];
    oM.m[3][1] = m[3][1] - iM.m[3][1];
    oM.m[3][2] = m[3][2] - iM.m[3][2];
    oM.m[3][3] = m[3][3] - iM.m[3][3];

    *this = oM;
    return *this;
  }
template<typename T>
Matrix4x4< T > nux::Matrix4x4< T >::operator/ ( const T &  f) const

Definition at line 562 of file Matrix4.h.

  {
    Matrix4x4<T> oM;

    oM.m[0][0] = m[0][0] / f;
    oM.m[0][1] = m[0][1] / f;
    oM.m[0][2] = m[0][2] / f;
    oM.m[0][3] = m[0][3] / f;
    oM.m[1][0] = m[1][0] / f;
    oM.m[1][1] = m[1][1] / f;
    oM.m[1][2] = m[1][2] / f;
    oM.m[1][3] = m[1][3] / f;
    oM.m[2][0] = m[2][0] / f;
    oM.m[2][1] = m[2][1] / f;
    oM.m[2][2] = m[2][2] / f;
    oM.m[2][3] = m[2][3] / f;
    oM.m[3][0] = m[3][0] / f;
    oM.m[3][1] = m[3][1] / f;
    oM.m[3][2] = m[3][2] / f;
    oM.m[3][3] = m[3][3] / f;

    return oM;
  }
template<typename T>
Matrix4x4< T > nux::Matrix4x4< T >::operator/= ( const T &  f) const

Definition at line 638 of file Matrix4.h.

  {
    Matrix4x4<T> oM;

    oM.m[0][0] = m[0][0] / f;
    oM.m[0][1] = m[0][1] / f;
    oM.m[0][2] = m[0][2] / f;
    oM.m[0][3] = m[0][3] / f;
    oM.m[1][0] = m[1][0] / f;
    oM.m[1][1] = m[1][1] / f;
    oM.m[1][2] = m[1][2] / f;
    oM.m[1][3] = m[1][3] / f;
    oM.m[2][0] = m[2][0] / f;
    oM.m[2][1] = m[2][1] / f;
    oM.m[2][2] = m[2][2] / f;
    oM.m[2][3] = m[2][3] / f;
    oM.m[3][0] = m[3][0] / f;
    oM.m[3][1] = m[3][1] / f;
    oM.m[3][2] = m[3][2] / f;
    oM.m[3][3] = m[3][3] / f;

    *this = oM;
    return *this;
  }
template<typename T>
Matrix4x4< T > & nux::Matrix4x4< T >::operator= ( const Matrix4x4< T > &  M)

Definition at line 244 of file Matrix4.h.

  {
    m[0][0] = M.m[0][0];
    m[0][1] = M.m[0][1];
    m[0][2] = M.m[0][2];
    m[0][3] = M.m[0][3];
    m[1][0] = M.m[1][0];
    m[1][1] = M.m[1][1];
    m[1][2] = M.m[1][2];
    m[1][3] = M.m[1][3];
    m[2][0] = M.m[2][0];
    m[2][1] = M.m[2][1];
    m[2][2] = M.m[2][2];
    m[2][3] = M.m[2][3];
    m[3][0] = M.m[3][0];
    m[3][1] = M.m[3][1];
    m[3][2] = M.m[3][2];
    m[3][3] = M.m[3][3];

    return (*this);
  }
template<typename T>
bool nux::Matrix4x4< T >::operator== ( const Matrix4x4< T > &  M)

Definition at line 267 of file Matrix4.h.

  {
    for (int i = 0; i < 4; i++)
      for (int j = 0; j < 4; j++)
      {
        if (m[i][j] != M.m[i][j])
          return false;
      }

    return true;
  }
template<typename T>
void nux::Matrix4x4< T >::Orthographic ( l,
r,
b,
t,
n,
f 
)

set to an orthographic projection matrix.

Definition at line 1323 of file Matrix4.h.

  {
    T sx = 1 / (r - l);
    T sy = 1 / (t - b);
    T sz = 1 / (f - n);

    m[0][0] = 2.0f * sx;
    m[0][1] = 0.0f;
    m[0][2] = 0.0f;
    m[0][3] = - (r + l) * sx;

    m[1][0] = 0.0f;
    m[1][1] = 2.0f * sy;
    m[1][2] = 0.0f;
    m[1][3] = - (t + b) * sy;

    m[2][0] = 0.0f;
    m[2][1] = 0.0f;
    m[2][2] = -2.0f * sz;
    m[2][3] = - (f + n) * sz;

    m[3][0] = 0.0f;
    m[3][1] = 0.0f;
    m[3][2] = 0.0f;
    m[3][3] = 1.0f;
  }

Here is the caller graph for this function:

template<typename T>
void nux::Matrix4x4< T >::Perspective ( l,
r,
t,
b,
n,
f 
)

set to a perspective projection matrix.

Definition at line 1356 of file Matrix4.h.

  {
    m[0][0]   = 2.0f * n / (r - l);
    m[0][1] = 0.0f;
    m[0][2] = (r + l) / (r - l);
    m[0][3] = 0.0f;

    m[1][0] = 0.0f;
    m[1][1] = 2.0f * n / (t - b);
    m[1][2] = (t + b) / (t - b);
    m[1][3] = 0.0f;

    m[2][0] = 0.0f;
    m[2][1] = 0.0f;
    m[2][2] = - (f + n) / (f - n);
    m[2][3] = -2.0f * f * n / (f - n);

    m[3][0] = 0.0f;
    m[3][1] = 0.0f;
    m[3][2] = -1.0f;
    m[3][3] = 0.0f;
  }

Here is the caller graph for this function:

template<typename T>
void nux::Matrix4x4< T >::Perspective ( FoV,
AspectRatio,
NearPlane,
FarPlane 
)

set to a perspective projection matrix specified in terms of field of view and aspect ratio.

Definition at line 1409 of file Matrix4.h.

  {
    const T t = tan (FoV * 0.5f) * NearPlane;
    const T b = -t;

    const T l = AspectRatio * b;
    const T r = AspectRatio * t;

    Perspective (l, r, t, b, NearPlane, FarPlane);
  }
template<typename T>
void nux::Matrix4x4< T >::PerspectiveInverse ( l,
r,
t,
b,
n,
f 
)

Definition at line 1384 of file Matrix4.h.

  {
    m[0][0]   = (r - l) / (2.0f * n);
    m[0][1] = 0;
    m[0][2] = 0;
    m[0][3] = (r + l) / (2.0f * n);

    m[1][0] = 0;
    m[1][1] = (t - b) / (2.0f * n);
    m[1][2] = (t + b) / (2.0f * n);
    m[1][3] = 0;

    m[2][0] = 0;
    m[2][1] = 0;
    m[2][2] = 0;
    m[2][3] = -1;

    m[3][0] = 0;
    m[3][1] = 0;
    m[3][2] = - (f - n) / (2.0f * f * n);
    m[3][3] = (f + n) / (2.0f * f * n);
  }
template<typename T>
void nux::Matrix4x4< T >::Rotate ( angle,
Vector3  axis 
)

Definition at line 1227 of file Matrix4.h.

  {
    //See Quaternion::from_angle_axis() and Quaternion::get_matrix()
    // note: adapted from david eberly's code without permission
    //TODO: make sure it is correct
    
    if (axis.LengthSquared() < constants::epsilon_micro)
    {
      Identity();
    }
    else
    {
      axis.Normalize();

      T fCos = (T) cos(angle);
      T fSin = (T) sin(angle);
      T fOneMinusCos = 1.0f-fCos;
      T fX2 = axis.x*axis.x;
      T fY2 = axis.y*axis.y;
      T fZ2 = axis.z*axis.z;
      T fXYM = axis.x*axis.y*fOneMinusCos;
      T fXZM = axis.x*axis.z*fOneMinusCos;
      T fYZM = axis.y*axis.z*fOneMinusCos;
      T fXSin = axis.x*fSin;
      T fYSin = axis.y*fSin;
      T fZSin = axis.z*fSin;

      m[0][0] = fX2*fOneMinusCos+fCos;
      m[0][1] = fXYM-fZSin;
      m[0][2] = fXZM+fYSin;
      m[0][3] = 0;

      m[1][0] = fXYM+fZSin;
      m[1][1] = fY2*fOneMinusCos+fCos;
      m[1][2] = fYZM-fXSin;
      m[1][3] = 0;

      m[2][0] = fXZM-fYSin;
      m[2][1] = fYZM+fXSin;
      m[2][2] = fZ2*fOneMinusCos+fCos;
      m[2][3] = 0;

      m[3][0] = 0;
      m[3][1] = 0;
      m[3][2] = 0;
      m[3][3] = 1;
    }
  }

Here is the call graph for this function:

template<typename T>
void nux::Matrix4x4< T >::Rotate_x ( angle)

Definition at line 877 of file Matrix4.h.

  {
    Identity();

    m[0][0] = 1.0f;
    m[1][0] = 0.0f;
    m[2][0] = 0.0f;
    m[3][0] = 0.0f;

    m[0][1] = 0.0f;
    m[1][1] = (T) cos (angle);
    m[2][1] = (T) sin (angle);
    m[3][1] = 0.0f;

    m[0][2] = 0.0f;
    m[1][2] = (T) - sin (angle);
    m[2][2] = (T) cos (angle);
    m[3][2] = 0.0f;

    m[0][3] = 0.0f;
    m[1][3] = 0.0f;
    m[2][3] = 0.0f;
    m[3][3] = 1.0f;
  }

Here is the caller graph for this function:

template<typename T>
void nux::Matrix4x4< T >::Rotate_y ( angle)

Definition at line 914 of file Matrix4.h.

  {
    Identity();

    m[0][0] = (T) cos (angle);
    m[1][0] = 0.0f;
    m[2][0] = (T) - sin (angle);
    m[3][0] = 0.0f;

    m[0][1] = 0.0f;
    m[1][1] = 1.0f;
    m[2][1] = 0.0f;
    m[3][1] = 0.0f;

    m[0][2] = (T) sin (angle);
    m[1][2] = 0.0f;
    m[2][2] = (T) cos (angle);
    m[3][2] = 0.0f;

    m[0][3] = 0.0f;
    m[1][3] = 0.0f;
    m[2][3] = 0.0f;
    m[3][3] = 1.0f;
  }

Here is the caller graph for this function:

template<typename T>
void nux::Matrix4x4< T >::Rotate_z ( angle)

Definition at line 951 of file Matrix4.h.

  {
    Identity();

    m[0][0] = (T) cos (angle);
    m[1][0] = (T) sin (angle);
    m[2][0] = 0.0f;
    m[3][0] = 0.0f;

    m[0][1] = (T) - sin (angle);
    m[1][1] = (T) cos (angle);
    m[2][1] = 0.0f;
    m[3][1] = 0.0f;

    m[0][2] = 0.0f;
    m[1][2] = 0.0f;
    m[2][2] = 1.0f;
    m[3][2] = 0.0f;

    m[0][3] = 0.0f;
    m[1][3] = 0.0f;
    m[2][3] = 0.0f;
    m[3][3] = 1.0f;
  }

Here is the caller graph for this function:

template<typename T>
Matrix4x4< T > nux::Matrix4x4< T >::ROTATEX ( angle) [static]

Definition at line 1437 of file Matrix4.h.

  {
    Matrix4x4<T> matrix;
    matrix.Rotate_x(angle);
    return matrix;
  }

Here is the call graph for this function:

template<typename T>
Matrix4x4< T > nux::Matrix4x4< T >::ROTATEY ( angle) [static]

Definition at line 1445 of file Matrix4.h.

  {
    Matrix4x4<T> matrix;
    matrix.Rotate_y(angle);
    return matrix;
  }

Here is the call graph for this function:

template<typename T>
Matrix4x4< T > nux::Matrix4x4< T >::ROTATEZ ( angle) [static]

Definition at line 1453 of file Matrix4.h.

  {
    Matrix4x4<T> matrix;
    matrix.Rotate_z(angle);
    return matrix;
  }

Here is the call graph for this function:

template<typename T>
void nux::Matrix4x4< T >::Scale ( sx,
sy,
sz 
)

Definition at line 988 of file Matrix4.h.

  {
    Identity();

    m[0][0] = sx;
    m[1][0] = 0.0f;
    m[2][0] = 0.0f;
    m[3][0] = 0.0f;

    m[0][1] = 0.0f;
    m[1][1] = sy;
    m[2][1] = 0.0f;
    m[3][1] = 0.0f;

    m[0][2] = 0.0f;
    m[1][2] = 0.0f;
    m[2][2] = sz;
    m[3][2] = 0.0f;

    m[0][3] = 0.0f;
    m[1][3] = 0.0f;
    m[2][3] = 0.0f;
    m[3][3] = 1.0f;
  }

Here is the caller graph for this function:

template<typename T>
void nux::Matrix4x4< T >::Scale ( s)

Definition at line 1179 of file Matrix4.h.

  {
    m[0][0] = s;
    m[0][1] = 0.0;
    m[0][2] = 0.0;
    m[0][3] = 0.0;
    m[1][0] = 0.0;
    m[1][1] = s;
    m[1][2] = 0.0;
    m[1][3] = 0.0;
    m[2][0] = 0.0;
    m[2][1] = 0.0;
    m[2][2] = s;
    m[2][3] = 0.0;
    m[3][0] = 0.0;
    m[3][1] = 0.0;
    m[3][2] = 0.0;
    m[3][3] = 1;
  }
template<typename T>
Matrix4x4< T > nux::Matrix4x4< T >::SCALE ( x,
y,
z 
) [static]

Definition at line 1469 of file Matrix4.h.

  {
    Matrix4x4<T> matrix;
    matrix.Scale(x, y, z);
    return matrix;
  }

Here is the call graph for this function:

template<typename T >
T nux::Matrix4x4< T >::Trace ( ) const

Definition at line 1014 of file Matrix4.h.

  {
    return m[0][0] + m[1][1] + m[2][2] + m[3][3];
  }
template<typename T>
void nux::Matrix4x4< T >::Translate ( x,
y,
z 
)

Definition at line 831 of file Matrix4.h.

  {
    Identity();
    m[0][3] = x;
    m[1][3] = y;
    m[2][3] = z;
  }

Here is the caller graph for this function:

template<typename T>
void nux::Matrix4x4< T >::Translate ( const Vector3 )
template<typename T>
Matrix4x4< T > nux::Matrix4x4< T >::TRANSLATE ( x,
y,
z 
) [static]

Definition at line 1461 of file Matrix4.h.

  {
    Matrix4x4<T> matrix;
    matrix.Translate(x, y, z);
    return matrix;
  }

Here is the call graph for this function:

template<typename T >
void nux::Matrix4x4< T >::Transpose ( )

Definition at line 851 of file Matrix4.h.

  {
    for (int i = 0; i < 4; i++)
    {
      for (int j = 0; j < i; j++)
      {
        T t = m[i][j];
        m[i][j] = m[j][i];
        m[j][i] = t;
      }
    }
  }

Here is the caller graph for this function:

template<typename T >
void nux::Matrix4x4< T >::Zero ( )

Definition at line 763 of file Matrix4.h.

  {
    m[0][0] = 0.0;
    m[0][1] = 0.0;
    m[0][2] = 0.0;
    m[0][3] = 0.0;
    m[1][0] = 0.0;
    m[1][1] = 0.0;
    m[1][2] = 0.0;
    m[1][3] = 0.0;
    m[2][0] = 0.0;
    m[2][1] = 0.0;
    m[2][2] = 0.0;
    m[2][3] = 0.0;
    m[3][0] = 0.0;
    m[3][1] = 0.0;
    m[3][2] = 0.0;
    m[3][3] = 0.0;

    //memset(m, 0, sizeof(m));
  }

Here is the caller graph for this function:

template<typename T >
Matrix4x4< T > nux::Matrix4x4< T >::ZERO ( ) [static]

Definition at line 1429 of file Matrix4.h.

  {
    Matrix4x4<T> matrix;
    matrix.Zero();
    return matrix;
  }

Here is the call graph for this function:


Member Data Documentation

template<typename T>
T nux::Matrix4x4< T >::m[4][4]

Definition at line 123 of file Matrix4.h.


The documentation for this class was generated from the following file: