Core 1.0
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.
 
 Matrix4 (const Vector &)
 Create a homogeneous diagonal matrix with diagonal terms set to the vector entries.
 
 Matrix4 (const Matrix &)
 Create an homogeneous matrix from a simple Matrix.
 
 Matrix4 (const Matrix &, const Vector &)
 Create an homogeneous matrix from a simple Matrix and a translation vector.
 
 Matrix4 (const Matrix &, const Vector &, const Vector &)
 Constructor from a Matrix, a translation and a shear vector.
 
 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.
 
Matrix4operator*= (double)
 Destructive scalar multiply.
 
Matrix4operator/= (double)
 Destructive scalar divide.
 
Vector operator* (const Vector &) const
 Right multiply by a vector.
 
QString ToGLSL () const
 Return a string expression.
 
double Determinant () const
 Compute the determinant of the matrix.
 
double Trace () const
 Compute the trace (sum of diagonal terms).
 
Matrix4 T () const
 Transpose a matrix.
 
Matrix4 Inverse () const
 Computes the inverse of a matrix A-1.
 
void Float (float[16]) const
 Convert to a generic 4×4 float matrix.
 
Matrix Sub () const
 Return the sub-matrix obtained by removing the last column and row.
 

Static Public Member Functions

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

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 Matrix4::Inverse()).
 

Friends

Matrix4 operator+ (const Matrix4 &u, const Matrix4 &v)
 Overloaded.
 
Matrix4 operator- (const Matrix4 &u, const Matrix4 &v)
 Overloaded.
 
Matrix4 operator* (const Matrix4 &u, const Matrix4 &v)
 Multiplication.
 
Matrix4 operator* (const Matrix4 &A, const double &r)
 Multiplication by a real.
 
std::ostream & operator<< (std::ostream &s, const Matrix4 &matrix)
 Overloaded.
 

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.

◆ Inverse()

Matrix4 Matrix4::Inverse ( ) const

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.

◆ 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.

◆ Perspective()

Matrix4 Matrix4::Perspective ( const double & fovy,
const double & zNear,
const double & zFar,
const double & width,
const double & height )
static

Perspective projection matrix.

Parameters
fovyVertical field of view.
zNear,zFarNear and far distance.
width,heightScreen width and heigh.

◆ 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.

◆ ToGLSL()

QString Matrix4::ToGLSL ( ) const

Return a string expression.

Author
Hubert-Brierre Pierre

Yields a QString of the form 'mat4(m(0, 0), ..., m(3, 3))' that write the matrix in GLSL.

◆ Translate()

Matrix4 Matrix4::Translate ( const Vector & t)
static

Creates a translation matrix.

Parameters
tTranslation vector.

Friends And Related Symbol Documentation

◆ operator* [1/2]

Matrix4 operator* ( const Matrix4 & A,
const double & r )
friend

Multiplication by a real.

Parameters
Amatrix.
rReal.

◆ operator* [2/2]

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.