Support Forum       G3D Web Page     
Public Member Functions | Static Public Member Functions | List of all members
G3D::Matrix4 Class Reference

A 4x4 matrix. More...

Public Member Functions

 Matrix4 (const Any &any)
 Must be in one of the following forms: More...
 
 Matrix4 (float r1c1, float r1c2, float r1c3, float r1c4, float r2c1, float r2c2, float r2c3, float r2c4, float r3c1, float r3c2, float r3c3, float r3c4, float r4c1, float r4c2, float r4c3, float r4c4)
 
 Matrix4 (DoNotInitialize dni)
 
 Matrix4 (const float *init)
 
init should be row major. More...
 
 Matrix4 (const class Matrix3 &upper3x3, const class Vector3 &lastCol=Vector3::zero())
 a is the upper left 3x3 submatrix and b is the upper right 3x1 submatrix. More...
 
 Matrix4 (const class CoordinateFrame &c)
 
 Matrix4 (const double *init)
 
 Matrix4 ()
 Matrix4::zero() More...
 
Matrix4 adjoint () const
 
Transpose of the cofactor matrix (used in computing the inverse). More...
 
class CoordinateFrame approxCoordinateFrame () const
 Produces an RT transformation that nearly matches this Matrix4. More...
 
Matrix4 cofactor () const
 
Vector4 column (int c) const
 
void deserialize (class BinaryInput &b)
 
float determinant () const
 
bool fuzzyEq (const Matrix4 &b) const
 
void getPerspectiveProjectionParameters (double &left, double &right, double &bottom, double &top, double &nearval, double &farval, float updirection=-1.0f) const
 If this is a perspective projection matrix created by Matrix4::perspectiveProjection, extract its parameters. More...
 
class Vector3 homoMul (const class Vector3 &v, float w) const
 Homogeneous multiplication. More...
 
Matrix4 inverse () const
 
 operator const float * () const
 
 operator float * ()
 Returns a row-major pointer. More...
 
bool operator!= (const Matrix4 &other) const
 
Matrix4 operator* (const Matrix4 &other) const
 
Matrix4 operator* (const float s) const
 
Vector4 operator* (const Vector4 &vector) const
 
Matrix4 operator+ (const Matrix4 &other) const
 
bool operator== (const Matrix4 &other) const
 
float * operator[] (int r)
 
const float * operator[] (int r) const
 
const Vector4row (int r) const
 
void serialize (class BinaryOutput &b) const
 Serializes row-major. More...
 
void setColumn (int c, const Vector4 &v)
 
void setRow (int r, const class Vector4 &v)
 
Any toAny () const
 
String toString () const
 
Matrix4 transpose () const
 
class Matrix2 upper2x2 () const
 
class Matrix3 upper3x3 () const
 

Static Public Member Functions

static Matrix4 diagonal (float e00, float e11, float e22, float e33)
 
static const Matrix4identity ()
 
static Matrix4 orthogonalProjection (float left, float right, float bottom, float top, float nearval, float farval, float upDirection=-1.0f)
 
Constructs an orthogonal projection matrix from the given parameters. More...
 
static Matrix4 orthogonalProjection (const class Rect2D &rect, float nearval, float farval, float upDirection=-1.0f)
 
static Matrix4 perspectiveProjection (double left, double right, double bottom, double top, double nearval, double farval, float upDirection=-1.0f)
 
static Matrix4 pitchDegrees (float deg)
 
static Matrix4 rollDegrees (float deg)
 
static Matrix4 scale (const Vector3 &v)
 3D scale matrix More...
 
static Matrix4 scale (float x, float y, float z)
 3D scale matrix More...
 
static Matrix4 scale (float s)
 3D scale matrix More...
 
static Matrix4 translation (const Vector3 &v)
 3D translation matrix More...
 
static Matrix4 translation (float x, float y, float z)
 
static Matrix4 yawDegrees (float deg)
 Create a rotation matrix that rotates deg degrees around the Y axis. More...
 
static const Matrix4zero ()
 

Detailed Description

A 4x4 matrix.

Do not subclass. Data is initialized to 0 when default constructed.

See also
G3D::CoordinateFrame, G3D::Matrix3, G3D::Quat

Constructor & Destructor Documentation

◆ Matrix4() [1/8]

G3D::Matrix4::Matrix4 ( const Any any)
explicit

Must be in one of the following forms:

◆ Matrix4() [2/8]

G3D::Matrix4::Matrix4 ( float  r1c1,
float  r1c2,
float  r1c3,
float  r1c4,
float  r2c1,
float  r2c2,
float  r2c3,
float  r2c4,
float  r3c1,
float  r3c2,
float  r3c3,
float  r3c4,
float  r4c1,
float  r4c2,
float  r4c3,
float  r4c4 
)

◆ Matrix4() [3/8]

G3D::Matrix4::Matrix4 ( DoNotInitialize  dni)
inline

◆ Matrix4() [4/8]

G3D::Matrix4::Matrix4 ( const float *  init)


init should be row major.

◆ Matrix4() [5/8]

G3D::Matrix4::Matrix4 ( const class Matrix3 upper3x3,
const class Vector3 lastCol = Vector3::zero() 
)

a is the upper left 3x3 submatrix and b is the upper right 3x1 submatrix.

The last row of the created matrix is (0,0,0,1).

◆ Matrix4() [6/8]

G3D::Matrix4::Matrix4 ( const class CoordinateFrame c)

◆ Matrix4() [7/8]

G3D::Matrix4::Matrix4 ( const double *  init)

◆ Matrix4() [8/8]

G3D::Matrix4::Matrix4 ( )

Member Function Documentation

◆ adjoint()

Matrix4 G3D::Matrix4::adjoint ( ) const


Transpose of the cofactor matrix (used in computing the inverse).

Note: This is in fact only one type of adjoint. More generally, an adjoint of a matrix is any mapping of a matrix which possesses certain properties. This returns the so-called adjugate or classical adjoint.

◆ approxCoordinateFrame()

class CoordinateFrame G3D::Matrix4::approxCoordinateFrame ( ) const

Produces an RT transformation that nearly matches this Matrix4.

Because a Matrix4 may not be precisely a rotation and translation, this may introduce error.

◆ cofactor()

Matrix4 G3D::Matrix4::cofactor ( ) const

◆ column()

Vector4 G3D::Matrix4::column ( int  c) const

◆ deserialize()

void G3D::Matrix4::deserialize ( class BinaryInput b)

◆ determinant()

float G3D::Matrix4::determinant ( ) const

Referenced by G3D::determinant().

◆ diagonal()

static Matrix4 G3D::Matrix4::diagonal ( float  e00,
float  e11,
float  e22,
float  e33 
)
inlinestatic

◆ fuzzyEq()

bool G3D::Matrix4::fuzzyEq ( const Matrix4 b) const

◆ getPerspectiveProjectionParameters()

void G3D::Matrix4::getPerspectiveProjectionParameters ( double &  left,
double &  right,
double &  bottom,
double &  top,
double &  nearval,
double &  farval,
float  updirection = -1.0f 
) const

If this is a perspective projection matrix created by Matrix4::perspectiveProjection, extract its parameters.

Uses double precision because the operations involved in projection involve divisions that can significantly impact precision.

◆ homoMul()

class Vector3 G3D::Matrix4::homoMul ( const class Vector3 v,
float  w 
) const

Homogeneous multiplication.

Let k = M * [v w]^T. result = k.xyz() / k.w

◆ identity()

static const Matrix4& G3D::Matrix4::identity ( )
static

◆ inverse()

Matrix4 G3D::Matrix4::inverse ( ) const

◆ operator const float *()

G3D::Matrix4::operator const float * ( ) const
inline

◆ operator float *()

G3D::Matrix4::operator float * ( )
inline

Returns a row-major pointer.

◆ operator!=()

bool G3D::Matrix4::operator!= ( const Matrix4 other) const

◆ operator*() [1/3]

Matrix4 G3D::Matrix4::operator* ( const Matrix4 other) const

◆ operator*() [2/3]

Matrix4 G3D::Matrix4::operator* ( const float  s) const

◆ operator*() [3/3]

Vector4 G3D::Matrix4::operator* ( const Vector4 vector) const

◆ operator+()

Matrix4 G3D::Matrix4::operator+ ( const Matrix4 other) const
inline

◆ operator==()

bool G3D::Matrix4::operator== ( const Matrix4 other) const

◆ operator[]() [1/2]

float* G3D::Matrix4::operator[] ( int  r)
inline

◆ operator[]() [2/2]

const float* G3D::Matrix4::operator[] ( int  r) const
inline

◆ orthogonalProjection() [1/2]

static Matrix4 G3D::Matrix4::orthogonalProjection ( float  left,
float  right,
float  bottom,
float  top,
float  nearval,
float  farval,
float  upDirection = -1.0f 
)
static


Constructs an orthogonal projection matrix from the given parameters.

Near and far are the NEGATIVE of the near and far plane Z values (to follow OpenGL conventions).

Parameters
upDirectionUse -1.0 for 2D Y increasing downwards (the G3D 8.x default convention), 1.0 for 2D Y increasing upwards (the G3D 7.x default and OpenGL convention)

◆ orthogonalProjection() [2/2]

static Matrix4 G3D::Matrix4::orthogonalProjection ( const class Rect2D rect,
float  nearval,
float  farval,
float  upDirection = -1.0f 
)
static
Parameters
upDirectionUse -1.0 for 2D Y increasing downwards (the G3D 8.x default convention), 1.0 for 2D Y increasing upwards (the G3D 7.x default and OpenGL convention)

◆ perspectiveProjection()

static Matrix4 G3D::Matrix4::perspectiveProjection ( double  left,
double  right,
double  bottom,
double  top,
double  nearval,
double  farval,
float  upDirection = -1.0f 
)
static
Parameters
upDirectionUse -1.0 for 2D Y increasing downwards (the G3D 8.x default convention), 1.0 for 2D Y increasing upwards (the G3D 7.x default and OpenGL convention)
Uses double precision because the operations involved in
projection involve divisions that can significantly impact
precision.     

◆ pitchDegrees()

static Matrix4 G3D::Matrix4::pitchDegrees ( float  deg)
inlinestatic

◆ rollDegrees()

static Matrix4 G3D::Matrix4::rollDegrees ( float  deg)
inlinestatic

◆ row()

const Vector4& G3D::Matrix4::row ( int  r) const

◆ scale() [1/3]

static Matrix4 G3D::Matrix4::scale ( const Vector3 v)
inlinestatic

3D scale matrix

Referenced by scale().

◆ scale() [2/3]

static Matrix4 G3D::Matrix4::scale ( float  x,
float  y,
float  z 
)
inlinestatic

3D scale matrix

◆ scale() [3/3]

static Matrix4 G3D::Matrix4::scale ( float  s)
inlinestatic

3D scale matrix

◆ serialize()

void G3D::Matrix4::serialize ( class BinaryOutput b) const

Serializes row-major.

◆ setColumn()

void G3D::Matrix4::setColumn ( int  c,
const Vector4 v 
)

◆ setRow()

void G3D::Matrix4::setRow ( int  r,
const class Vector4 v 
)

◆ toAny()

Any G3D::Matrix4::toAny ( ) const

◆ toString()

String G3D::Matrix4::toString ( ) const

◆ translation() [1/2]

static Matrix4 G3D::Matrix4::translation ( const Vector3 v)
inlinestatic

3D translation matrix

◆ translation() [2/2]

static Matrix4 G3D::Matrix4::translation ( float  x,
float  y,
float  z 
)
inlinestatic

◆ transpose()

Matrix4 G3D::Matrix4::transpose ( ) const

◆ upper2x2()

class Matrix2 G3D::Matrix4::upper2x2 ( ) const

◆ upper3x3()

class Matrix3 G3D::Matrix4::upper3x3 ( ) const

◆ yawDegrees()

static Matrix4 G3D::Matrix4::yawDegrees ( float  deg)
inlinestatic

Create a rotation matrix that rotates deg degrees around the Y axis.

◆ zero()

static const Matrix4& G3D::Matrix4::zero ( )
static

documentation generated on Wed Nov 24 2021 08:01:58 using doxygen 1.8.15