reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

The ofMatrix4x4 is the big class of the math part of openFrameworks. More...

#include <ofMatrix4x4.h>

Public Member Functions

 ~ofMatrix4x4 ()
 destructor.
 
Constructors
 ofMatrix4x4 ()
 The default constructor provides an identity matrix.
 
 ofMatrix4x4 (const glm::mat4 &mat)
 
 operator glm::mat4 () const
 
 ofMatrix4x4 (float const *const ptr)
 Construct with a pointer.
 
 ofMatrix4x4 (const ofQuaternion &quat)
 Rotation matrices can be constructed from a quaternion.
 
 ofMatrix4x4 (float a00, float a01, float a02, float a03, float a10, float a11, float a12, float a13, float a20, float a21, float a22, float a23, float a30, float a31, float a32, float a33)
 Positional style.
 
make* Methods

These methods perform a total matrix makeover. All make* methods delete the current data and the matrix becomes a new type of transform.

void makeIdentityMatrix ()
 Matrix becomes the identity matrix.
 
Scale

Matrix becomes a scale transform.

Accepts x, y, z scale values as a vector or separately.

void makeScaleMatrix (const ofVec3f &)
 
void makeScaleMatrix (float, float, float)
 
Translation

Matrix becomes a translation transform.

Accepts x, y, z translation values as a vector or separately.

void makeTranslationMatrix (const ofVec3f &)
 
void makeTranslationMatrix (float, float, float)
 
Rotation

Matrix becomes a rotation transform.

Parameters
fromMatrix becomes a rotation from this vector direction.
toMatrix becomes a rotation to this vector direction.
void makeRotationMatrix (const ofVec3f &from, const ofVec3f &to)
 
void makeRotationMatrix (float angle, const ofVec3f &axis)
 
void makeRotationMatrix (float angle, float x, float y, float z)
 
void makeRotationMatrix (const ofQuaternion &quaternion)
 
void makeRotationMatrix (float angle1, const ofVec3f &axis1, float angle2, const ofVec3f &axis2, float angle3, const ofVec3f &axis3)
 Matrix becomes a rotation around multiple axes.
 
Make* methods related to another matrix
bool makeInvertOf (const ofMatrix4x4 &rhs)
 Matrix becomes the inverse of the provided matrix.
 
void makeOrthoNormalOf (const ofMatrix4x4 &rhs)
 Matrix becomes an orthonormalized version of the provided matrix.
 
void makeFromMultiplicationOf (const ofMatrix4x4 &, const ofMatrix4x4 &)
 Matrix becomes the result of the multiplication of two other matrices.
 
View matrix make*

These functions are based on some OpenGL matrix functions used for perspective settings. See the OpenGL docs of the related function for further details.

void makeOrthoMatrix (double left, double right, double bottom, double top, double zNear, double zFar)
 Matrix becomes an orthographic projection matrix.
 
void makeOrtho2DMatrix (double left, double right, double bottom, double top)
 Matrix becomes a 2D orthographic projection matrix.
 
void makeFrustumMatrix (double left, double right, double bottom, double top, double zNear, double zFar)
 Matrix becomes a perspective projection matrix.
 
void makePerspectiveMatrix (double fovy, double aspectRatio, double zNear, double zFar)
 Matrix becomes a perspective projection matrix.
 
void makeLookAtMatrix (const ofVec3f &eye, const ofVec3f &center, const ofVec3f &up)
 Matrix becomes a combination of translation and rotation.
 
void makeLookAtViewMatrix (const ofVec3f &eye, const ofVec3f &center, const ofVec3f &up)
 Matrix becomes a combination of an inverse translation and rotation.
 
Accessors
float & operator() (std::size_t row, std::size_t col)
 Write data with matrix(row,col)=number
 
float operator() (std::size_t row, std::size_t col) const
 Read data with matrix(row, col)
 
ofVec3f getRowAsVec3f (std::size_t i) const
 returns a copy of row i
 
ofVec4f getRowAsVec4f (std::size_t i) const
 returns a copy of row i
 
float * getPtr ()
 Access the internal data in float* format useful for opengl matrix transformations.
 
const float * getPtr () const
 
Checking
bool isValid () const
 Checks if the matrix is valid by ensuring its items are numbers.
 
bool isNaN () const
 Checks if the matrix contains items that are not numbers.
 
bool isIdentity () const
 Checks if the matrix is the identity matrix.
 
Setters
ofMatrix4x4operator= (const ofMatrix4x4 &rhs)
 Copy a matrix using = operator.
 
void set (const ofMatrix4x4 &rhs)
 Set the data of the matrix.
 
void set (float const *const ptr)
 
void set (double const *const ptr)
 
void set (float a00, float a01, float a02, float a03, float a10, float a11, float a12, float a13, float a20, float a21, float a22, float a23, float a30, float a31, float a32, float a33)
 
Matrix multiplication
ofVec3f postMult (const ofVec3f &v) const
 Matrix * vector multiplication.
 
ofVec4f postMult (const ofVec4f &v) const
 
void postMult (const ofMatrix4x4 &)
 Post-multiply by another matrix.
 
ofVec3f preMult (const ofVec3f &v) const
 Vector * matrix multiplication.
 
ofVec4f preMult (const ofVec4f &v) const
 
void preMult (const ofMatrix4x4 &)
 Pre-multiply by another matrix.
 
void operator*= (const ofMatrix4x4 &other)
 The *= operation for matrices.
 
ofMatrix4x4 operator* (const ofMatrix4x4 &m) const
 creates a new matrix from the product of two matrices.
 
ofVec3f operator* (const ofVec3f &v) const
 Matrix * Vector operator.
 
ofVec4f operator* (const ofVec4f &v) const
 
void postMultTranslate (const ofVec3f &v)
 Equivalent to postMult(newTranslationMatrix(v)).
 
void postMultScale (const ofVec3f &v)
 Equivalent to postMult(scale(v)).
 
void postMultRotate (const ofQuaternion &q)
 Equivalent to postMult(newRotationMatrix(q)).
 
void postMultTranslate (float x, float y, float z)
 
void postMultRotate (float angle, float x, float y, float z)
 
void postMultScale (float x, float y, float z)
 
void preMultScale (const ofVec3f &v)
 Equivalent to preMult(newScaleMatrix(v)).
 
void preMultTranslate (const ofVec3f &v)
 Equivalent to preMult(newTranslationMatrix(v)).
 
void preMultRotate (const ofQuaternion &q)
 Equivalent to preMult(newRotationMatrix(q)).
 
Set methods

All of these methods alter the components, deleting the previous data only in that component.

void setRotate (const ofQuaternion &q)
 
void setTranslation (float tx, float ty, float tz)
 
void setTranslation (const ofVec3f &v)
 
PostMult Transformations

All of these methods apply the transformations over the current one, calling postMult under the hood. These work as the opposite of the equivalent OpenGL functions.

For example, glTranslate + glRotate == rotate + translate.

void rotate (float angle, float x, float y, float z)
 Rotates by angle (degrees) around the given x, y, z axis.
 
void rotateRad (float angle, float x, float y, float z)
 Rotates by angle (radians) around the given x, y, z axis.
 
void rotate (const ofQuaternion &q)
 Rotates based on the quarternion.
 
void translate (float tx, float ty, float tz)
 Translates by tx, ty, tz.
 
void translate (const ofVec3f &v)
 Translates along the vector.
 
void scale (float x, float y, float z)
 Scales each axis by the corresponding x, y, z.
 
void scale (const ofVec3f &v)
 Scales each axis by the corresponding x, y, z of the vector.
 
PreMult Transformations

All of these methods apply the transformations over the current one, calling preMult under the hood. These work the the same the equivalent OpenGL functions.

void glRotate (float angle, float x, float y, float z)
 
void glRotateRad (float angle, float x, float y, float z)
 
void glRotate (const ofQuaternion &q)
 
void glTranslate (float tx, float ty, float tz)
 
void glTranslate (const ofVec3f &v)
 
void glScale (float x, float y, float z)
 
void glScale (const ofVec3f &v)
 
Get Methods

These return matrix components. getRotate and getScale can only be used if the matrix only has rotation or only has scale, since these transform values are stored in the same area of the matrix. For matrices with both use decompose instead.

ofQuaternion getRotate () const
 
ofVec3f getTranslation () const
 
ofVec3f getScale () const
 

Static Public Member Functions

static ofVec3f transform3x3 (const ofVec3f &v, const ofMatrix4x4 &m)
 Apply a 3x3 transform (no translation) of v * M.
 
static ofVec3f transform3x3 (const ofMatrix4x4 &m, const ofVec3f &v)
 Apply a 3x3 transform (no translation) of M * v.
 
Static new* matrix functions

These are static utility functions to create new matrices. These functions generally return the equivalent of declaring a matrix and calling the corresponding "make..." function on it.

static ofMatrix4x4 newIdentityMatrix (void)
 
static ofMatrix4x4 newScaleMatrix (const ofVec3f &sv)
 
static ofMatrix4x4 newScaleMatrix (float sx, float sy, float sz)
 
static ofMatrix4x4 newTranslationMatrix (const ofVec3f &dv)
 
static ofMatrix4x4 newTranslationMatrix (float x, float y, float z)
 
static ofMatrix4x4 newRotationMatrix (const ofVec3f &from, const ofVec3f &to)
 
static ofMatrix4x4 newRotationMatrix (float angle, float x, float y, float z)
 
static ofMatrix4x4 newRotationMatrix (float angle, const ofVec3f &axis)
 
static ofMatrix4x4 newRotationMatrix (float angle1, const ofVec3f &axis1, float angle2, const ofVec3f &axis2, float angle3, const ofVec3f &axis3)
 
static ofMatrix4x4 newRotationMatrix (const ofQuaternion &quat)
 
static ofMatrix4x4 newOrthoMatrix (double left, double right, double bottom, double top, double zNear, double zFar)
 
static ofMatrix4x4 newOrtho2DMatrix (double left, double right, double bottom, double top)
 
static ofMatrix4x4 newFrustumMatrix (double left, double right, double bottom, double top, double zNear, double zFar)
 
static ofMatrix4x4 newPerspectiveMatrix (double fovy, double aspectRatio, double zNear, double zFar)
 
static ofMatrix4x4 newLookAtMatrix (const ofVec3f &eye, const ofVec3f &center, const ofVec3f &up)
 

Public Attributes

ofVec4f _mat [4]
 The values of the matrix, stored in row-major order.
 

Getters

ofMatrix4x4 getInverse () const
 Gets the inverse matrix.
 
bool getOrtho (double &left, double &right, double &bottom, double &top, double &zNear, double &zFar) const
 Get the perspective components from a matrix.
 
bool getFrustum (double &left, double &right, double &bottom, double &top, double &zNear, double &zFar) const
 Gets the perspective components for a frustum projection matrix.
 
bool getPerspective (double &fovy, double &aspectRatio, double &zNear, double &zFar) const
 Get the frustum settings of a symmetric perspective projection matrix.
 
void getLookAt (ofVec3f &eye, ofVec3f &center, ofVec3f &up, float lookDistance=1.0f) const
 Gets the lookAt determiners of the matrix.
 
void decompose (ofVec3f &translation, ofQuaternion &rotation, ofVec3f &scale, ofQuaternion &so) const
 Decompose the matrix into translation, rotation, scale and scale orientation.
 
static ofMatrix4x4 getInverseOf (const ofMatrix4x4 &matrix)
 Create new matrices as transformation of another.
 
static ofMatrix4x4 getTransposedOf (const ofMatrix4x4 &matrix)
 Makes a new matrix which is the transpose of the given matrix.
 
static ofMatrix4x4 getOrthoNormalOf (const ofMatrix4x4 &matrix)
 Makes a new matrix which is the given matrix, normalized.
 

Detailed Description

The ofMatrix4x4 is the big class of the math part of openFrameworks.

You'll sometimes see it used for doing things like setting where the camera in OpenGL (the mathematically calculated one, not the ofCamera one) is looking or is pointed, or figuring how to position something in 3d space, doing scaling, etc. The great thing about the 4x4 matrix is that it can do all these things at the same time. A single ofMatrix4x4 can represent a ton of different information about a stuff that goes on in doing 3d programming: where an object is, how you want to scale an object, where a camera is. Let's look at a few really basic examples:

MATS

Not particularly exciting, but you can see how they'd be useful. Luckily most of the need to transform, rotate, scale, shear, or further bazzlemunge (just kidding, bazzlemunging is not a thing) stuff in oF is handled internally by objects like ofNode or ofCamera.

oF uses row-vector style by default, meaning that when transforming a vector by multiplying with a matrix, you should put the vector on the left side and the matrix (or matrices) to its right. When multiplying by multiple matrices, the order of application of the transforms is left-to-right. This means that the standard order of manipulation operations is vector * scale * rotate * translate.

Note that in GLSL, this convention is reversed, and column-vector style is used. oF uploads the matrices to the GL context correctly, but you should reverse the order of your vertex manipulations to right-to-left style, e.g. translate * rotate * scale * vector.

On the application side, oF has operators which let you do matrix-vector multiplication with the vector on the right if that's your preferred style. To set up a combined transformation matrix for working in this style, you should do matrix transformations with the functions like glTranslate, glRotate, and glScale.

Constructor & Destructor Documentation

◆ ofMatrix4x4() [1/5]

ofMatrix4x4::ofMatrix4x4 ( )
inline

The default constructor provides an identity matrix.

◆ ofMatrix4x4() [2/5]

ofMatrix4x4::ofMatrix4x4 ( const glm::mat4 &  mat)
inline

◆ ofMatrix4x4() [3/5]

ofMatrix4x4::ofMatrix4x4 ( float const *const  ptr)
inline

Construct with a pointer.

You can pass a pointer to floats, and the first 16 contents will be extracted into this matrix.

Warning
the validity of these values is not checked!

◆ ofMatrix4x4() [4/5]

ofMatrix4x4::ofMatrix4x4 ( const ofQuaternion quat)
inline

Rotation matrices can be constructed from a quaternion.

◆ ofMatrix4x4() [5/5]

ofMatrix4x4::ofMatrix4x4 ( float  a00,
float  a01,
float  a02,
float  a03,
float  a10,
float  a11,
float  a12,
float  a13,
float  a20,
float  a21,
float  a22,
float  a23,
float  a30,
float  a31,
float  a32,
float  a33 
)

Positional style.

All 16 values of the matrix as positional arguments in row-major order.

◆ ~ofMatrix4x4()

ofMatrix4x4::~ofMatrix4x4 ( )
inline

destructor.

Member Function Documentation

◆ decompose()

void ofMatrix4x4::decompose ( ofVec3f translation,
ofQuaternion rotation,
ofVec3f scale,
ofQuaternion so 
) const

Decompose the matrix into translation, rotation, scale and scale orientation.

◆ getFrustum()

bool ofMatrix4x4::getFrustum ( double &  left,
double &  right,
double &  bottom,
double &  top,
double &  zNear,
double &  zFar 
) const

Gets the perspective components for a frustum projection matrix.

◆ getInverse()

ofMatrix4x4 ofMatrix4x4::getInverse ( ) const

Gets the inverse matrix.

◆ getInverseOf()

static ofMatrix4x4 ofMatrix4x4::getInverseOf ( const ofMatrix4x4 matrix)
inlinestatic

Create new matrices as transformation of another.

Makes a new matrix which is the inverse of the given matrix.

◆ getLookAt()

void ofMatrix4x4::getLookAt ( ofVec3f eye,
ofVec3f center,
ofVec3f up,
float  lookDistance = 1.0f 
) const

Gets the lookAt determiners of the matrix.

This function will only work for modelview matrices.

◆ getOrtho()

bool ofMatrix4x4::getOrtho ( double &  left,
double &  right,
double &  bottom,
double &  top,
double &  zNear,
double &  zFar 
) const

Get the perspective components from a matrix.

This only works with pure perspective projection matrices.

◆ getOrthoNormalOf()

static ofMatrix4x4 ofMatrix4x4::getOrthoNormalOf ( const ofMatrix4x4 matrix)
inlinestatic

Makes a new matrix which is the given matrix, normalized.

◆ getPerspective()

bool ofMatrix4x4::getPerspective ( double &  fovy,
double &  aspectRatio,
double &  zNear,
double &  zFar 
) const

Get the frustum settings of a symmetric perspective projection matrix.

Note, if matrix is not a symmetric perspective matrix then the shear will be lost. Asymmetric matrices occur when stereo, power walls, caves and reality center display are used. In these configuration one should use the getFrustum method instead.

Returns
false if matrix is not a perspective matrix, where parameter values are undefined.

◆ getPtr() [1/2]

float * ofMatrix4x4::getPtr ( )
inline

Access the internal data in float* format useful for opengl matrix transformations.

◆ getPtr() [2/2]

const float * ofMatrix4x4::getPtr ( ) const
inline

◆ getRotate()

ofQuaternion ofMatrix4x4::getRotate ( ) const

◆ getRowAsVec3f()

ofVec3f ofMatrix4x4::getRowAsVec3f ( std::size_t  i) const
inline

returns a copy of row i

◆ getRowAsVec4f()

ofVec4f ofMatrix4x4::getRowAsVec4f ( std::size_t  i) const
inline

returns a copy of row i

◆ getScale()

ofVec3f ofMatrix4x4::getScale ( ) const

◆ getTranslation()

ofVec3f ofMatrix4x4::getTranslation ( ) const

◆ getTransposedOf()

static ofMatrix4x4 ofMatrix4x4::getTransposedOf ( const ofMatrix4x4 matrix)
inlinestatic

Makes a new matrix which is the transpose of the given matrix.

◆ glRotate() [1/2]

void ofMatrix4x4::glRotate ( const ofQuaternion q)
See also
rotate

◆ glRotate() [2/2]

void ofMatrix4x4::glRotate ( float  angle,
float  x,
float  y,
float  z 
)
See also
rotate

◆ glRotateRad()

void ofMatrix4x4::glRotateRad ( float  angle,
float  x,
float  y,
float  z 
)
See also
rotate

◆ glScale() [1/2]

void ofMatrix4x4::glScale ( const ofVec3f v)
See also
scale

◆ glScale() [2/2]

void ofMatrix4x4::glScale ( float  x,
float  y,
float  z 
)
See also
scale

◆ glTranslate() [1/2]

void ofMatrix4x4::glTranslate ( const ofVec3f v)
See also
translate

◆ glTranslate() [2/2]

void ofMatrix4x4::glTranslate ( float  tx,
float  ty,
float  tz 
)
See also
translate

◆ isIdentity()

bool ofMatrix4x4::isIdentity ( ) const

Checks if the matrix is the identity matrix.

◆ isNaN()

bool ofMatrix4x4::isNaN ( ) const

Checks if the matrix contains items that are not numbers.

◆ isValid()

bool ofMatrix4x4::isValid ( ) const
inline

Checks if the matrix is valid by ensuring its items are numbers.

◆ makeFromMultiplicationOf()

void ofMatrix4x4::makeFromMultiplicationOf ( const ofMatrix4x4 lhs,
const ofMatrix4x4 rhs 
)

Matrix becomes the result of the multiplication of two other matrices.

◆ makeFrustumMatrix()

void ofMatrix4x4::makeFrustumMatrix ( double  left,
double  right,
double  bottom,
double  top,
double  zNear,
double  zFar 
)

Matrix becomes a perspective projection matrix.

Related to: glFrustum. The viewing volume is frustum-shaped and defined by the six parameters. Left, right, top, and bottom specify coordinates in the zNear clipping plane where the frustum edges intersect it, and the zNear and zFar parameters define the forward distances of the view volume. The resulting volume can be vertically and horizontally asymmetrical around the center of the near plane.

◆ makeIdentityMatrix()

void ofMatrix4x4::makeIdentityMatrix ( )

Matrix becomes the identity matrix.

◆ makeInvertOf()

bool ofMatrix4x4::makeInvertOf ( const ofMatrix4x4 rhs)

Matrix becomes the inverse of the provided matrix.

◆ makeLookAtMatrix()

void ofMatrix4x4::makeLookAtMatrix ( const ofVec3f eye,
const ofVec3f center,
const ofVec3f up 
)

Matrix becomes a combination of translation and rotation.

Matrix becomes a combination of a translation to the position of 'eye' and a rotation matrix which orients an object to point towards 'center' along its z-axis. Use this function if you want an object to look at a point from another point in space.

Parameters
eyeThe position of the object.
centerThe point which the object is "looking" at.
upThe direction which the object considers to be "up".

◆ makeLookAtViewMatrix()

void ofMatrix4x4::makeLookAtViewMatrix ( const ofVec3f eye,
const ofVec3f center,
const ofVec3f up 
)

Matrix becomes a combination of an inverse translation and rotation.

Related to: gluLookAt. This creates the inverse of makeLookAtMatrix. The matrix will be an opposite translation from the 'eye' position, and it will rotate things in the opposite direction of the eye-to-center orientation. This is definitely confusing, but the main reason to use this transform is to set up a view matrix for a camera that's looking at a certain point. To achieve the effect of moving the camera somewhere and rotating it so that it points at something, the rest of the world is moved in the opposite direction and rotated in the opposite way around the camera. This way, you get the same effect as moving the actual camera, but all the projection math can still be done with the camera positioned at the origin (which makes it way simpler).

◆ makeOrtho2DMatrix()

void ofMatrix4x4::makeOrtho2DMatrix ( double  left,
double  right,
double  bottom,
double  top 
)

Matrix becomes a 2D orthographic projection matrix.

Related to: glOrtho2D. The box-shaped viewing volume is described by the four parameters and, implicitly, a zNear of -1 and a zFar of 1.

◆ makeOrthoMatrix()

void ofMatrix4x4::makeOrthoMatrix ( double  left,
double  right,
double  bottom,
double  top,
double  zNear,
double  zFar 
)

Matrix becomes an orthographic projection matrix.

Related to: glOrtho. The orthographic projection has a box-shaped viewing volume described by the six parameters. Left, right, bottom, and top specify coordinates in the zNear clipping plane where the corresponding box sides intersect it.

◆ makeOrthoNormalOf()

void ofMatrix4x4::makeOrthoNormalOf ( const ofMatrix4x4 rhs)

Matrix becomes an orthonormalized version of the provided matrix.

The basis vectors (the 3x3 chunk embedded in the upper left of the matrix) are normalized. This means the resulting matrix has had scaling effects removed. The fourth column and the fourth row are transferred over untouched, so translation will be included as well.

◆ makePerspectiveMatrix()

void ofMatrix4x4::makePerspectiveMatrix ( double  fovy,
double  aspectRatio,
double  zNear,
double  zFar 
)

Matrix becomes a perspective projection matrix.

Related to: gluPerspective. The viewing volume is frustum-shaped amd defined by the four parameters. The fovy and aspect ratio are used to compute the positions of the left, right, top, and bottom sides of the viewing volume in the zNear plane. The fovy is the y field-of-view, the angle made by the top and bottom sides of frustum if they were to intersect. The aspect ratio is the width of the frustum divided by its height. Note that the resulting volume is both vertically and horizontally symmetrical around the center of the near plane.

◆ makeRotationMatrix() [1/5]

void ofMatrix4x4::makeRotationMatrix ( const ofQuaternion quaternion)
Parameters
quaternionMatrix becomes a rotation that produces the quaternion's orientation.

◆ makeRotationMatrix() [2/5]

void ofMatrix4x4::makeRotationMatrix ( const ofVec3f from,
const ofVec3f to 
)

◆ makeRotationMatrix() [3/5]

void ofMatrix4x4::makeRotationMatrix ( float  angle,
const ofVec3f axis 
)
Parameters
angleMatrix becomes a rotation by angle (degrees).
axisRotation is performed around this vector.

◆ makeRotationMatrix() [4/5]

void ofMatrix4x4::makeRotationMatrix ( float  angle,
float  x,
float  y,
float  z 
)
Parameters
angleMatrix becomes a rotation by angle (degrees).
xX-value of the rotation axis.
yY-value of the rotation axis.
zZ-value of the rotation axis.

◆ makeRotationMatrix() [5/5]

void ofMatrix4x4::makeRotationMatrix ( float  angle1,
const ofVec3f axis1,
float  angle2,
const ofVec3f axis2,
float  angle3,
const ofVec3f axis3 
)

Matrix becomes a rotation around multiple axes.

The final rotation is the result of rotating around each of the three axes, in order. Angles are given in degrees, and axes can be arbitrary vectors.

◆ makeScaleMatrix() [1/2]

void ofMatrix4x4::makeScaleMatrix ( const ofVec3f v)

◆ makeScaleMatrix() [2/2]

void ofMatrix4x4::makeScaleMatrix ( float  x,
float  y,
float  z 
)

◆ makeTranslationMatrix() [1/2]

void ofMatrix4x4::makeTranslationMatrix ( const ofVec3f v)

◆ makeTranslationMatrix() [2/2]

void ofMatrix4x4::makeTranslationMatrix ( float  x,
float  y,
float  z 
)

◆ newFrustumMatrix()

static ofMatrix4x4 ofMatrix4x4::newFrustumMatrix ( double  left,
double  right,
double  bottom,
double  top,
double  zNear,
double  zFar 
)
inlinestatic

◆ newIdentityMatrix()

static ofMatrix4x4 ofMatrix4x4::newIdentityMatrix ( void  )
inlinestatic

◆ newLookAtMatrix()

static ofMatrix4x4 ofMatrix4x4::newLookAtMatrix ( const ofVec3f eye,
const ofVec3f center,
const ofVec3f up 
)
inlinestatic

◆ newOrtho2DMatrix()

static ofMatrix4x4 ofMatrix4x4::newOrtho2DMatrix ( double  left,
double  right,
double  bottom,
double  top 
)
inlinestatic

◆ newOrthoMatrix()

static ofMatrix4x4 ofMatrix4x4::newOrthoMatrix ( double  left,
double  right,
double  bottom,
double  top,
double  zNear,
double  zFar 
)
inlinestatic

These functions create new matrices related to glFunctions. See the description of the corresponding make* methods for more info.

See also
makeOrthoMatrix

◆ newPerspectiveMatrix()

static ofMatrix4x4 ofMatrix4x4::newPerspectiveMatrix ( double  fovy,
double  aspectRatio,
double  zNear,
double  zFar 
)
inlinestatic

◆ newRotationMatrix() [1/5]

static ofMatrix4x4 ofMatrix4x4::newRotationMatrix ( const ofQuaternion quat)
inlinestatic

◆ newRotationMatrix() [2/5]

static ofMatrix4x4 ofMatrix4x4::newRotationMatrix ( const ofVec3f from,
const ofVec3f to 
)
inlinestatic

◆ newRotationMatrix() [3/5]

static ofMatrix4x4 ofMatrix4x4::newRotationMatrix ( float  angle,
const ofVec3f axis 
)
inlinestatic

◆ newRotationMatrix() [4/5]

static ofMatrix4x4 ofMatrix4x4::newRotationMatrix ( float  angle,
float  x,
float  y,
float  z 
)
inlinestatic

◆ newRotationMatrix() [5/5]

static ofMatrix4x4 ofMatrix4x4::newRotationMatrix ( float  angle1,
const ofVec3f axis1,
float  angle2,
const ofVec3f axis2,
float  angle3,
const ofVec3f axis3 
)
inlinestatic

◆ newScaleMatrix() [1/2]

static ofMatrix4x4 ofMatrix4x4::newScaleMatrix ( const ofVec3f sv)
inlinestatic
See also
makeScaleMatrix

◆ newScaleMatrix() [2/2]

static ofMatrix4x4 ofMatrix4x4::newScaleMatrix ( float  sx,
float  sy,
float  sz 
)
inlinestatic

◆ newTranslationMatrix() [1/2]

static ofMatrix4x4 ofMatrix4x4::newTranslationMatrix ( const ofVec3f dv)
inlinestatic

◆ newTranslationMatrix() [2/2]

static ofMatrix4x4 ofMatrix4x4::newTranslationMatrix ( float  x,
float  y,
float  z 
)
inlinestatic

◆ operator glm::mat4()

ofMatrix4x4::operator glm::mat4 ( ) const
inline

◆ operator()() [1/2]

float & ofMatrix4x4::operator() ( std::size_t  row,
std::size_t  col 
)
inline

Write data with matrix(row,col)=number

◆ operator()() [2/2]

float ofMatrix4x4::operator() ( std::size_t  row,
std::size_t  col 
) const
inline

Read data with matrix(row, col)

◆ operator*() [1/3]

ofMatrix4x4 ofMatrix4x4::operator* ( const ofMatrix4x4 m) const
inline

creates a new matrix from the product of two matrices.

◆ operator*() [2/3]

ofVec3f ofMatrix4x4::operator* ( const ofVec3f v) const
inline

Matrix * Vector operator.

Calls postMult() internally.

◆ operator*() [3/3]

ofVec4f ofMatrix4x4::operator* ( const ofVec4f v) const
inline

◆ operator*=()

void ofMatrix4x4::operator*= ( const ofMatrix4x4 other)
inline

The *= operation for matrices.

This is equivalent to calling postMult(other), but it allows you to do someMatrix *= someMatrix without breaking const-correctness. Calling someMatrix.postMult(someMatrix) won't work.

◆ operator=()

ofMatrix4x4 & ofMatrix4x4::operator= ( const ofMatrix4x4 rhs)

Copy a matrix using = operator.

◆ postMult() [1/3]

void ofMatrix4x4::postMult ( const ofMatrix4x4 other)

Post-multiply by another matrix.

This matrix becomes this * other.

◆ postMult() [2/3]

ofVec3f ofMatrix4x4::postMult ( const ofVec3f v) const
inline

Matrix * vector multiplication.

Although OpenGL uses post-multiplication (vector-on-the-right) with column-major matrix memory layout, oF uses pre-multiplication (vector-on-the-left) with row-major matrix memory layout by default.

openGL:

0 4 8 12
1 5 9 13
2 6 10 14
3 7 11 15

ofMatrix4x4:

0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15

However, the two memory layouts are compatible because of a funny trick.

When the ofMatrix4x4 is uploaded into OpenGL's memory, OpenGL treats it like a column-major matrix. The rows of the ofMatrix4x4 are loaded as columns for the GLSL mat4. The result is that the matrix is transposed. This seems like a bug, but it's in fact exactly what we want, because to do the transition from pre-multiplication to post-multiplication style, we need to perform the very same transpose.

By using pre-multiplication, oF treats vectors as 1x4 matrices, since that provides a valid 1x4 * 4x4 operation. When moving to post-multiplication, OpenGL is treating vectors like columns, providing a similarly valid 4x4 * 4x1 operation. This means that the resulting vector in OGL-land is the transpose of the result when done in oF-land.

Recall that in matrix multiplication,

(V * M * S)^T = (S^T) * (M^T) * (V^T)

What this means is that to convert from pre-multiplication to post-multiplication, we need to transpose our matrices (and vectors) and reverse the order of multiplication. You're already reversing the order of multiplication by writing your shaders with the vector on the right, and the implicit transpose that happens when your matrix is uploaded to GL memory accomplishes the transposition for free!

For more information on this subject, check out this post.

This operation implicitly treat vectors as column-matrices.

◆ postMult() [3/3]

ofVec4f ofMatrix4x4::postMult ( const ofVec4f v) const
inline

◆ postMultRotate() [1/2]

void ofMatrix4x4::postMultRotate ( const ofQuaternion q)
inline

Equivalent to postMult(newRotationMatrix(q)).

◆ postMultRotate() [2/2]

void ofMatrix4x4::postMultRotate ( float  angle,
float  x,
float  y,
float  z 
)
inline

◆ postMultScale() [1/2]

void ofMatrix4x4::postMultScale ( const ofVec3f v)
inline

Equivalent to postMult(scale(v)).

◆ postMultScale() [2/2]

void ofMatrix4x4::postMultScale ( float  x,
float  y,
float  z 
)
inline

◆ postMultTranslate() [1/2]

void ofMatrix4x4::postMultTranslate ( const ofVec3f v)
inline

Equivalent to postMult(newTranslationMatrix(v)).

These are specialized postMult methods, usually you want to use these for transforming with ofVec.

◆ postMultTranslate() [2/2]

void ofMatrix4x4::postMultTranslate ( float  x,
float  y,
float  z 
)
inline

◆ preMult() [1/3]

void ofMatrix4x4::preMult ( const ofMatrix4x4 other)

Pre-multiply by another matrix.

This matrix becomes other * this.

◆ preMult() [2/3]

ofVec3f ofMatrix4x4::preMult ( const ofVec3f v) const
inline

Vector * matrix multiplication.

This operation implicitly treats vectors as row-matrices.

◆ preMult() [3/3]

ofVec4f ofMatrix4x4::preMult ( const ofVec4f v) const
inline

◆ preMultRotate()

void ofMatrix4x4::preMultRotate ( const ofQuaternion q)
inline

Equivalent to preMult(newRotationMatrix(q)).

◆ preMultScale()

void ofMatrix4x4::preMultScale ( const ofVec3f v)
inline

Equivalent to preMult(newScaleMatrix(v)).

◆ preMultTranslate()

void ofMatrix4x4::preMultTranslate ( const ofVec3f v)
inline

Equivalent to preMult(newTranslationMatrix(v)).

◆ rotate() [1/2]

void ofMatrix4x4::rotate ( const ofQuaternion q)

Rotates based on the quarternion.

◆ rotate() [2/2]

void ofMatrix4x4::rotate ( float  angle,
float  x,
float  y,
float  z 
)

Rotates by angle (degrees) around the given x, y, z axis.

◆ rotateRad()

void ofMatrix4x4::rotateRad ( float  angle,
float  x,
float  y,
float  z 
)

Rotates by angle (radians) around the given x, y, z axis.

◆ scale() [1/2]

void ofMatrix4x4::scale ( const ofVec3f v)

Scales each axis by the corresponding x, y, z of the vector.

◆ scale() [2/2]

void ofMatrix4x4::scale ( float  x,
float  y,
float  z 
)

Scales each axis by the corresponding x, y, z.

◆ set() [1/4]

void ofMatrix4x4::set ( const ofMatrix4x4 rhs)

Set the data of the matrix.

These functions are analogous to the corresponding constructors.

◆ set() [2/4]

void ofMatrix4x4::set ( double const *const  ptr)

◆ set() [3/4]

void ofMatrix4x4::set ( float  a00,
float  a01,
float  a02,
float  a03,
float  a10,
float  a11,
float  a12,
float  a13,
float  a20,
float  a21,
float  a22,
float  a23,
float  a30,
float  a31,
float  a32,
float  a33 
)

◆ set() [4/4]

void ofMatrix4x4::set ( float const *const  ptr)

◆ setRotate()

void ofMatrix4x4::setRotate ( const ofQuaternion q)

◆ setTranslation() [1/2]

void ofMatrix4x4::setTranslation ( const ofVec3f v)

◆ setTranslation() [2/2]

void ofMatrix4x4::setTranslation ( float  tx,
float  ty,
float  tz 
)

◆ transform3x3() [1/2]

static ofVec3f ofMatrix4x4::transform3x3 ( const ofMatrix4x4 m,
const ofVec3f v 
)
inlinestatic

Apply a 3x3 transform (no translation) of M * v.

◆ transform3x3() [2/2]

static ofVec3f ofMatrix4x4::transform3x3 ( const ofVec3f v,
const ofMatrix4x4 m 
)
inlinestatic

Apply a 3x3 transform (no translation) of v * M.

◆ translate() [1/2]

void ofMatrix4x4::translate ( const ofVec3f v)

Translates along the vector.

◆ translate() [2/2]

void ofMatrix4x4::translate ( float  tx,
float  ty,
float  tz 
)

Translates by tx, ty, tz.

Member Data Documentation

◆ _mat

ofVec4f ofMatrix4x4::_mat[4]

The values of the matrix, stored in row-major order.


The documentation for this class was generated from the following files:
  • /Users/icq4ever/Desktop/oF0120/libs/openFrameworks/math/ofMatrix4x4.h
  • /Users/icq4ever/Desktop/oF0120/libs/openFrameworks/math/ofMatrix4x4.cpp