Core 1.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | Static Protected Attributes | Friends | List of all members
Matrix4 Class Reference

This class implements 42 matrix. More...

#include <matrix.h>

Public Member Functions

 Matrix4 ()
 Empty.
 
 Matrix4 (const double &)
 Create an scaling matrix with the same diagonal terms. More...
 
 Matrix4 (const Vector &)
 Create a homogeneous diagonal matrix with diagonal terms set to the vector entries. More...
 
 Matrix4 (const Matrix &)
 Create an homogeneous matrix from a simple Matrix. More...
 
 Matrix4 (const Matrix &, const Vector &)
 Create an homogeneous matrix from a simple Matrix and a translation vector. More...
 
 Matrix4 (const Matrix &, const Vector &, const Vector &)
 Constructor from a Matrix, a translation and a shear vector. More...
 
 Matrix4 (const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &)
 Create a matrix given its coefficients.
 
Matrix4 operator- () const
 Returns the opposite of a matrix -A.
 
Matrix4operator+= (const Matrix4 &)
 Destructive addition.
 
Matrix4operator-= (const Matrix4 &)
 Destructive subtraction.
 
Matrix4operator*= (const Matrix4 &)
 Destructive multiplication. More...
 
Matrix4operator*= (double)
 Destructive scalar multiply.
 
Matrix4operator/= (double)
 Destructive scalar divide.
 
Vector operator* (const Vector &) const
 Right multiply by a vector. More...
 
double Determinant () const
 Compute the determinant of the matrix. More...
 
double Trace () const
 Compute the trace (sum of diagonal terms).
 
Matrix4 T () const
 Transpose a matrix.
 
void Float (float[16]) const
 Convert to a generic 4×4 float matrix. More...
 
Matrix Rotation () const
 Return the rotation matrix.
 

Static Public Member Functions

static Matrix4 LookAt (const Vector &, const Vector &, const double &)
 Create a viewing transformation matrix. More...
 
static Matrix4 Rotation (const Vector &, const double &)
 Create a rotation matrix about an arbitrary axis. More...
 
static Matrix4 Rotation (const Vector &)
 Create a rotation matrix about the orthogonal axes. More...
 
static Matrix4 Scale (const Vector &)
 Creates a scaling matrix. More...
 
static Matrix4 Translate (const Vector &)
 Creates a translation matrix. More...
 
static Matrix4 Shear (const Vector &)
 Creates a shear matrix. More...
 

Static Public Attributes

static const Matrix4 Null
 Null matrix.
 
static const Matrix4 Identity
 Identity matrix.
 
static const Matrix4 Hermite
 Hermite matrix, usefull for bi-cubic Hermite interpolation.
 

Protected Attributes

double r [16] = { 1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0 }
 Coefficients.
 

Static Protected Attributes

static const double epsilon = 1.0e-18
 Epsilon value used to check if the determinant of a matrix is null (used in Inverse(const Matrix4&)).
 

Friends

Matrix4 operator+ (const Matrix4 &, const Matrix4 &)
 Overloaded. More...
 
Matrix4 operator- (const Matrix4 &, const Matrix4 &)
 Overloaded. More...
 
Matrix4 operator* (const Matrix4 &, const Matrix4 &)
 Multiplication. More...
 
Matrix4 Inverse (const Matrix4 &)
 Computes the inverse of a matrix A-1. More...
 
std::ostream & operator<< (std::ostream &, const Matrix4 &)
 Overloaded. More...
 

Detailed Description

This class implements 42 matrix.

Components are stored in a single dimension array, starting from element a00 and sorting components by column.

The diagonal elements of a matrix A are A00=A[0], A11=A[5], A22=A[10], A33=A[15]. The terms corresponding to the translation vector are A[12], A[13], A[14].

Constructor & Destructor Documentation

◆ Matrix4() [1/5]

Matrix4::Matrix4 ( const double &  a)
explicit

Create an scaling matrix with the same diagonal terms.

The last term of the matrix is set to 1.0.

Parameters
aValue of diagonal entries.

◆ Matrix4() [2/5]

Matrix4::Matrix4 ( const Vector a)
explicit

Create a homogeneous diagonal matrix with diagonal terms set to the vector entries.

Last diagonal entry is set to 1.0.

Parameters
aVector of diagonal entries.

◆ Matrix4() [3/5]

Matrix4::Matrix4 ( const Matrix a)
explicit

Create an homogeneous matrix from a simple Matrix.

The translation and shear coefficients are set to 0.0.

Parameters
aMatrix.

◆ Matrix4() [4/5]

Matrix4::Matrix4 ( const Matrix a,
const Vector t 
)
explicit

Create an homogeneous matrix from a simple Matrix and a translation vector.

The shear coefficients are set to 0.0.

Parameters
aMatrix.
tTranslation vector.

◆ Matrix4() [5/5]

Matrix4::Matrix4 ( const Matrix a,
const Vector t,
const Vector s 
)
explicit

Constructor from a Matrix, a translation and a shear vector.

Parameters
aMatrix.
tTranslation vector.
sShear vector.

Member Function Documentation

◆ Determinant()

double Matrix4::Determinant ( ) const

Compute the determinant of the matrix.

See also
Matrix::Determinant().

◆ Float()

void Matrix4::Float ( float  a[16]) const

Convert to a generic 4×4 float matrix.

Parameters
aReturned matrix.

◆ LookAt()

Matrix4 Matrix4::LookAt ( const Vector eye,
const Vector look,
const double &  twist 
)
static

Create a viewing transformation matrix.

Parameters
eyeEye location.
lookLook at position.
twistTwisting angle from vertical.

◆ operator*()

Vector Matrix4::operator* ( const Vector v) const

Right multiply by a vector.

Parameters
vVector.

◆ operator*=()

Matrix4 & Matrix4::operator*= ( const Matrix4 v)

Destructive multiplication.

Parameters
vMatrix.

◆ Rotation() [1/2]

Matrix4 Matrix4::Rotation ( const Vector u)
static

Create a rotation matrix about the orthogonal axes.

Parameters
uVector of angles in radian.

◆ Rotation() [2/2]

Matrix4 Matrix4::Rotation ( const Vector v,
const double &  a 
)
static

Create a rotation matrix about an arbitrary axis.

Parameters
vAxis (should be normalized).
aAngle.

◆ Scale()

Matrix4 Matrix4::Scale ( const Vector u)
static

Creates a scaling matrix.

Parameters
uScaling vector.

◆ Shear()

Matrix4 Matrix4::Shear ( const Vector s)
static

Creates a shear matrix.

Parameters
sShear vector.

◆ Translate()

Matrix4 Matrix4::Translate ( const Vector t)
static

Creates a translation matrix.

Parameters
tTranslation vector.

Friends And Related Function Documentation

◆ Inverse

Matrix4 Inverse ( const Matrix4 m)
friend

Computes the inverse of a matrix A-1.

This function returns the null matrix if A cannot be inverted. The threshold value involved in the singular matrix detection is set to 10-18.

Parameters
mArgument matrix.

◆ operator*

Matrix4 operator* ( const Matrix4 u,
const Matrix4 v 
)
friend

Multiplication.

Parameters
u,vArgument matrix.

◆ operator+

Matrix4 operator+ ( const Matrix4 u,
const Matrix4 v 
)
friend

Overloaded.

Parameters
u,vArgument matrixes.

◆ operator-

Matrix4 operator- ( const Matrix4 u,
const Matrix4 v 
)
friend

Overloaded.

Parameters
u,vArgument matrixes.

◆ operator<<

std::ostream & operator<< ( std::ostream &  s,
const Matrix4 matrix 
)
friend

Overloaded.

Parameters
sStream.
matrixThe matrix.