class methods
- ofMatrix4x4()
- ~ofMatrix4x4()
- decompose()
- getFrustum()
- getInverse()
- getInverseOf()
- getLookAt()
- getOrtho()
- getOrthoNormalOf()
- getPerspective()
- getPtr()
- getRotate()
- getRowAsVec3f()
- getRowAsVec4f()
- getScale()
- getTranslation()
- getTransposedOf()
- glRotate()
- glRotateRad()
- glScale()
- glTranslate()
- isIdentity()
- isNaN()
- isValid()
- makeFromMultiplicationOf()
- makeFrustumMatrix()
- makeIdentityMatrix()
- makeInvertOf()
- makeLookAtMatrix()
- makeLookAtViewMatrix()
- makeOrtho2DMatrix()
- makeOrthoMatrix()
- makeOrthoNormalOf()
- makePerspectiveMatrix()
- makeRotationMatrix()
- makeScaleMatrix()
- makeTranslationMatrix()
- newFrustumMatrix()
- newIdentityMatrix()
- newLookAtMatrix()
- newOrtho2DMatrix()
- newOrthoMatrix()
- newPerspectiveMatrix()
- newRotationMatrix()
- newScaleMatrix()
- newTranslationMatrix()
- operator()()
- operator*()
- operator*=()
- operator=()
- postMult()
- postMultRotate()
- postMultScale()
- postMultTranslate()
- preMult()
- preMultRotate()
- preMultScale()
- preMultTranslate()
- rotate()
- rotateRad()
- scale()
- set()
- setRotate()
- setTranslation()
- transform3x3()
- translate()
variables
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 OepnGL (the mathematically calculated one, not the ofCamera one) is looking or is pointedA, 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:
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.
Documentation from code comments
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:
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.
ofMatrix4x4()
ofMatrix4x4::ofMatrix4x4()
Documentation from code comments
The default constructor provides an identity matrix.
ofMatrix4x4(...)
ofMatrix4x4::ofMatrix4x4(const float *const ptr)
Documentation from code comments
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(...)
ofMatrix4x4::ofMatrix4x4(const ofQuaternion &quat)
Documentation from code comments
Rotation matrices can be constructed from a quaternion.
ofMatrix4x4(...)
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)
Documentation from code comments
Positional style.
All 16 values of the matrix as positional arguments in row-major order.
decompose(...)
void ofMatrix4x4::decompose(ofVec3f &translation, ofQuaternion &rotation, ofVec3f &scale, ofQuaternion &so)
Documentation from code comments
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)
Documentation from code comments
Gets the perspective components for a frustum projection matrix.
getInverse()
ofMatrix4x4 ofMatrix4x4::getInverse()
Documentation from code comments
Gets the inverse matrix.
getInverseOf(...)
ofMatrix4x4 ofMatrix4x4::getInverseOf(const ofMatrix4x4 &matrix)
Documentation from code comments
Makes a new matrix which is the inverse of the given matrix.
getLookAt(...)
void ofMatrix4x4::getLookAt(ofVec3f &eye, ofVec3f ¢er, ofVec3f &up, float lookDistance=1.0f)
Documentation from code comments
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)
Documentation from code comments
Get the perspective components from a matrix.
This only works with pure perspective projection matrices.
getOrthoNormalOf(...)
ofMatrix4x4 ofMatrix4x4::getOrthoNormalOf(const ofMatrix4x4 &matrix)
Documentation from code comments
Makes a new matrix which is the given matrix, normalized.
getPerspective(...)
bool ofMatrix4x4::getPerspective(double &fovy, double &aspectRatio, double &zNear, double &zFar)
Documentation from code comments
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()
float * ofMatrix4x4::getPtr()
Documentation from code comments
Access the internal data in float*
format
useful for opengl matrix transformations
getRotate()
ofQuaternion ofMatrix4x4::getRotate()
Documentation from code comments
\name 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.
getRowAsVec3f(...)
ofVec3f ofMatrix4x4::getRowAsVec3f(size_t i)
Documentation from code comments
returns a copy of row i
getRowAsVec4f(...)
ofVec4f ofMatrix4x4::getRowAsVec4f(size_t i)
Documentation from code comments
returns a copy of row i
getTransposedOf(...)
ofMatrix4x4 ofMatrix4x4::getTransposedOf(const ofMatrix4x4 &matrix)
Documentation from code comments
Makes a new matrix which is the transpose of the given matrix.
glRotate(...)
void ofMatrix4x4::glRotate(const ofQuaternion &q)
Documentation from code comments
See also: rotate
glRotate(...)
void ofMatrix4x4::glRotate(float angle, float x, float y, float z)
Documentation from code comments
See also: rotate
glRotateRad(...)
void ofMatrix4x4::glRotateRad(float angle, float x, float y, float z)
Documentation from code comments
See also: rotate
glScale(...)
void ofMatrix4x4::glScale(const ofVec3f &v)
Documentation from code comments
See also: scale
glScale(...)
void ofMatrix4x4::glScale(float x, float y, float z)
Documentation from code comments
See also: scale
glTranslate(...)
void ofMatrix4x4::glTranslate(const ofVec3f &v)
Documentation from code comments
See also: translate
glTranslate(...)
void ofMatrix4x4::glTranslate(float tx, float ty, float tz)
Documentation from code comments
See also: translate
isIdentity()
bool ofMatrix4x4::isIdentity()
Documentation from code comments
Checks if the matrix is the identity matrix.
isNaN()
bool ofMatrix4x4::isNaN()
Documentation from code comments
Checks if the matrix contains items that are not numbers.
isValid()
bool ofMatrix4x4::isValid()
Documentation from code comments
Checks if the matrix is valid by ensuring its items are numbers.
makeFromMultiplicationOf(...)
void ofMatrix4x4::makeFromMultiplicationOf(const ofMatrix4x4 &, const ofMatrix4x4 &)
Documentation from code comments
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)
Documentation from code comments
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()
Documentation from code comments
Matrix becomes the identity matrix.
makeInvertOf(...)
bool ofMatrix4x4::makeInvertOf(const ofMatrix4x4 &rhs)
Documentation from code comments
Matrix becomes the inverse of the provided matrix.
makeLookAtMatrix(...)
void ofMatrix4x4::makeLookAtMatrix(const ofVec3f &eye, const ofVec3f ¢er, const ofVec3f &up)
Documentation from code comments
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:
eye The position of the object.
center The point which the object is "looking" at.
up The direction which the object considers to be "up".
makeLookAtViewMatrix(...)
void ofMatrix4x4::makeLookAtViewMatrix(const ofVec3f &eye, const ofVec3f ¢er, const ofVec3f &up)
Documentation from code comments
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)
Documentation from code comments
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)
Documentation from code comments
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)
Documentation from code comments
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)
Documentation from code comments
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(...)
void ofMatrix4x4::makeRotationMatrix(const ofQuaternion &quaternion)
Documentation from code comments
Parameters:
quaternion Matrix becomes a rotation that produces the quaternion's orientation.
makeRotationMatrix(...)
void ofMatrix4x4::makeRotationMatrix(const ofVec3f &from, const ofVec3f &to)
Documentation from code comments
\name Rotation { Matrix becomes a rotation transform.
Parameters:
from Matrix becomes a rotation from this vector direction.
to Matrix becomes a rotation to this vector direction.
makeRotationMatrix(...)
void ofMatrix4x4::makeRotationMatrix(float angle, const ofVec3f &axis)
Documentation from code comments
Parameters:
angle Matrix becomes a rotation by angle (degrees).
axis Rotation is performed around this vector.
makeRotationMatrix(...)
void ofMatrix4x4::makeRotationMatrix(float angle, float x, float y, float z)
Documentation from code comments
Parameters:
angle Matrix becomes a rotation by angle (degrees).
x X-value of the rotation axis.
y Y-value of the rotation axis.
z Z-value of the rotation axis.
makeRotationMatrix(...)
void ofMatrix4x4::makeRotationMatrix(float angle1, const ofVec3f &axis1, float angle2, const ofVec3f &axis2, float angle3, const ofVec3f &axis3)
Documentation from code comments
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(...)
void ofMatrix4x4::makeScaleMatrix(const ofVec3f &)
Documentation from code comments
\name Scale { Matrix becomes a scale transform.
Accepts x, y, z scale values as a vector or separately.
makeTranslationMatrix(...)
void ofMatrix4x4::makeTranslationMatrix(const ofVec3f &)
Documentation from code comments
\name Translation { Matrix becomes a translation transform.
Accepts x, y, z translation values as a vector or separately.
newFrustumMatrix(...)
ofMatrix4x4 ofMatrix4x4::newFrustumMatrix(double left, double right, double bottom, double top, double zNear, double zFar)
Documentation from code comments
See also: makeFrustumMatrix
newIdentityMatrix()
ofMatrix4x4 ofMatrix4x4::newIdentityMatrix()
Documentation from code comments
See also: makeIdentityMatrix
newLookAtMatrix(...)
ofMatrix4x4 ofMatrix4x4::newLookAtMatrix(const ofVec3f &eye, const ofVec3f ¢er, const ofVec3f &up)
Documentation from code comments
See also: makeLookAtMatrix
newOrtho2DMatrix(...)
ofMatrix4x4 ofMatrix4x4::newOrtho2DMatrix(double left, double right, double bottom, double top)
Documentation from code comments
See also: makeOrtho2DMatrix
newOrthoMatrix(...)
ofMatrix4x4 ofMatrix4x4::newOrthoMatrix(double left, double right, double bottom, double top, double zNear, double zFar)
Documentation from code comments
See also: makeOrthoMatrix
newPerspectiveMatrix(...)
ofMatrix4x4 ofMatrix4x4::newPerspectiveMatrix(double fovy, double aspectRatio, double zNear, double zFar)
Documentation from code comments
See also: makePerspectiveMatrix
newRotationMatrix(...)
ofMatrix4x4 ofMatrix4x4::newRotationMatrix(const ofVec3f &from, const ofVec3f &to)
Documentation from code comments
See also: makeRotationMatrix
newRotationMatrix(...)
ofMatrix4x4 ofMatrix4x4::newRotationMatrix(float angle, float x, float y, float z)
newRotationMatrix(...)
ofMatrix4x4 ofMatrix4x4::newRotationMatrix(float angle1, const ofVec3f &axis1, float angle2, const ofVec3f &axis2, float angle3, const ofVec3f &axis3)
newScaleMatrix(...)
ofMatrix4x4 ofMatrix4x4::newScaleMatrix(const ofVec3f &sv)
Documentation from code comments
See also: makeScaleMatrix
newTranslationMatrix(...)
ofMatrix4x4 ofMatrix4x4::newTranslationMatrix(const ofVec3f &dv)
Documentation from code comments
See also: makeTranslationMatrix
operator()(...)
float & ofMatrix4x4::operator()(size_t row, size_t col)
Documentation from code comments
Write data with matrix(row,col)=number
operator()(...)
float ofMatrix4x4::operator()(size_t row, size_t col)
Documentation from code comments
Read data with matrix(row, col)
operator*(...)
ofMatrix4x4 ofMatrix4x4::operator*(const ofMatrix4x4 &m)
Documentation from code comments
creates a new matrix from the product of two matrices.
operator*(...)
ofVec3f ofMatrix4x4::operator*(const ofVec3f &v)
Documentation from code comments
Matrix * Vector operator.
Calls postMult() internally.
operator*=(...)
void ofMatrix4x4::operator*=(const ofMatrix4x4 &other)
Documentation from code comments
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)
Documentation from code comments
Copy a matrix using =
operator.
postMult(...)
void ofMatrix4x4::postMult(const ofMatrix4x4 &)
Documentation from code comments
Post-multiply by another matrix.
This matrix becomes this * other
.
postMult(...)
ofVec3f ofMatrix4x4::postMult(const ofVec3f &v)
Documentation from code comments
Matrix * vector multiplication.
This operation implicitly treat vectors as column-matrices.
postMult(...)
ofVec4f ofMatrix4x4::postMult(const ofVec4f &v)
Documentation from code comments
post-multiplies the vector by the matrix (i.e. returns M mult v). The vector is implicitly treated as a column-matrix
postMultRotate(...)
void ofMatrix4x4::postMultRotate(const ofQuaternion &q)
Documentation from code comments
Equivalent to postMult(newRotationMatrix(q)).
postMultScale(...)
void ofMatrix4x4::postMultScale(const ofVec3f &v)
Documentation from code comments
Equivalent to postMult(scale(v)).
postMultTranslate(...)
void ofMatrix4x4::postMultTranslate(const ofVec3f &v)
Documentation from code comments
Equivalent to postMult(newTranslationMatrix(v)).
postMultTranslate(...)
void ofMatrix4x4::postMultTranslate(float x, float y, float z)
Documentation from code comments
the positional argument version of the above
preMult(...)
void ofMatrix4x4::preMult(const ofMatrix4x4 &)
Documentation from code comments
Pre-multiply by another matrix.
This matrix becomes other * this
.
preMult(...)
ofVec3f ofMatrix4x4::preMult(const ofVec3f &v)
Documentation from code comments
Vector * matrix multiplication.
This operation implicitly treats vectors as row-matrices.
preMult(...)
ofVec4f ofMatrix4x4::preMult(const ofVec4f &v)
Documentation from code comments
pre-multiplies the vector by the matrix (i.e. returns v mult M) The vector is implicitly treated as a row-matrix
preMultRotate(...)
void ofMatrix4x4::preMultRotate(const ofQuaternion &q)
Documentation from code comments
Equivalent to preMult(newRotationMatrix(q)).
preMultScale(...)
void ofMatrix4x4::preMultScale(const ofVec3f &v)
Documentation from code comments
Equivalent to preMult(newScaleMatrix(v)).
preMultTranslate(...)
void ofMatrix4x4::preMultTranslate(const ofVec3f &v)
Documentation from code comments
Equivalent to preMult(newTranslationMatrix(v)).
rotate(...)
void ofMatrix4x4::rotate(const ofQuaternion &q)
Documentation from code comments
Rotates based on the quarternion.
rotate(...)
void ofMatrix4x4::rotate(float angle, float x, float y, float z)
Documentation from code comments
Rotates by angle (degrees) around the given x, y, z axis.
rotateRad(...)
void ofMatrix4x4::rotateRad(float angle, float x, float y, float z)
Documentation from code comments
Rotates by angle (radians) around the given x, y, z axis.
scale(...)
void ofMatrix4x4::scale(const ofVec3f &v)
Documentation from code comments
Scales each axis by the corresponding x, y, z of the vector.
scale(...)
void ofMatrix4x4::scale(float x, float y, float z)
Documentation from code comments
Scales each axis by the corresponding x, y, z.
set(...)
void ofMatrix4x4::set(const ofMatrix4x4 &rhs)
Documentation from code comments
Set the data of the matrix.
These functions are analogous to the corresponding constructors.
set(...)
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)
setRotate(...)
void ofMatrix4x4::setRotate(const ofQuaternion &q)
Documentation from code comments
\name Set methods {
All of these methods alter the components, deleting the previous data only in that component.
transform3x3(...)
ofVec3f ofMatrix4x4::transform3x3(const ofMatrix4x4 &m, const ofVec3f &v)
Documentation from code comments
Apply a 3x3 transform (no translation) of M * v.
transform3x3(...)
ofVec3f ofMatrix4x4::transform3x3(const ofVec3f &v, const ofMatrix4x4 &m)
Documentation from code comments
Apply a 3x3 transform (no translation) of v * M.
translate(...)
void ofMatrix4x4::translate(const ofVec3f &v)
Documentation from code comments
Translates along the vector.
translate(...)
void ofMatrix4x4::translate(float tx, float ty, float tz)
Documentation from code comments
Translates by tx, ty, tz.
Last updated Saturday, 17 August 2024 20:47:46 UTC - 99bfb4fd7929e233b87b05758efc36f91505592e
If you have any doubt about the usage of this module you can ask in the forum.
If you want to contribute better documentation or start documenting this section you can do so here
If you find anything wrong with this docs you can report any error by opening an issue