QtBase
v6.3.1
|
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space. More...
#include <qmatrix4x4.h>
Public Types | |
enum | Flag { Identity = 0x0000 , Translation = 0x0001 , Scale = 0x0002 , Rotation2D = 0x0004 , Rotation = 0x0008 , Perspective = 0x0010 , General = 0x001f } |
Friends | |
class | ::tst_QMatrixNxN |
QMatrix4x4 | operator+ (const QMatrix4x4 &m1, const QMatrix4x4 &m2) |
QMatrix4x4 | operator- (const QMatrix4x4 &m1, const QMatrix4x4 &m2) |
QMatrix4x4 | operator* (const QMatrix4x4 &m1, const QMatrix4x4 &m2) |
QVector4D | operator* (const QVector4D &vector, const QMatrix4x4 &matrix) |
QVector4D | operator* (const QMatrix4x4 &matrix, const QVector4D &vector) |
QPoint | operator* (const QPoint &point, const QMatrix4x4 &matrix) |
QPointF | operator* (const QPointF &point, const QMatrix4x4 &matrix) |
QMatrix4x4 | operator- (const QMatrix4x4 &matrix) |
QMatrix4x4 | operator* (float factor, const QMatrix4x4 &matrix) |
QMatrix4x4 | operator* (const QMatrix4x4 &matrix, float factor) |
Q_GUI_EXPORT QMatrix4x4 | operator/ (const QMatrix4x4 &matrix, float divisor) |
Q_GUI_EXPORT bool | qFuzzyCompare (const QMatrix4x4 &m1, const QMatrix4x4 &m2) |
Q_GUI_EXPORT QDebug | operator<< (QDebug dbg, const QMatrix4x4 &m) |
Related Functions | |
(Note that these are not member functions.) | |
QMatrix4x4 | operator+ (const QMatrix4x4 &m1, const QMatrix4x4 &m2) |
QMatrix4x4 | operator- (const QMatrix4x4 &m1, const QMatrix4x4 &m2) |
QMatrix4x4 | operator* (const QMatrix4x4 &m1, const QMatrix4x4 &m2) |
QVector4D | operator* (const QVector4D &vector, const QMatrix4x4 &matrix) |
QVector4D | operator* (const QMatrix4x4 &matrix, const QVector4D &vector) |
QPoint | operator* (const QPoint &point, const QMatrix4x4 &matrix) |
QPointF | operator* (const QPointF &point, const QMatrix4x4 &matrix) |
QMatrix4x4 | operator- (const QMatrix4x4 &matrix) |
QMatrix4x4 | operator* (float factor, const QMatrix4x4 &matrix) |
QMatrix4x4 | operator* (const QMatrix4x4 &matrix, float factor) |
QMatrix4x4 | operator/ (const QMatrix4x4 &matrix, float divisor) |
bool | qFuzzyCompare (const QMatrix4x4 &m1, const QMatrix4x4 &m2) |
QDataStream & | operator<< (QDataStream &stream, const QMatrix4x4 &matrix) |
QDataStream & | operator>> (QDataStream &stream, QMatrix4x4 &matrix) |
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
\inmodule QtGui
The QMatrix4x4 class in general is treated as a row-major matrix, in that the constructors and operator() functions take data in row-major format, as is familiar in C-style usage.
Internally the data is stored as column-major format, so as to be optimal for passing to OpenGL functions, which expect column-major data.
When using these functions be aware that they return data in {column-major} format: \list
Definition at line 60 of file qmatrix4x4.h.
enum QMatrix4x4::Flag |
Enumerator | |
---|---|
Identity | |
Translation | |
Scale | |
Rotation2D | |
Rotation | |
Perspective | |
General |
Definition at line 197 of file qmatrix4x4.h.
|
inline |
Constructs an identity matrix.
Definition at line 63 of file qmatrix4x4.h.
|
inlineexplicit |
Definition at line 64 of file qmatrix4x4.h.
|
explicit |
Constructs a matrix from the given 16 floating-point values. The contents of the array values is assumed to be in row-major order.
If the matrix has a special type (identity, translate, scale, etc), the programmer should follow this constructor with a call to optimize() if they wish QMatrix4x4 to optimize further calls to translate(), scale(), etc.
Definition at line 103 of file qmatrix4x4.cpp.
|
inline |
Constructs a matrix from the 16 elements m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, and m44. The elements are specified in row-major order.
If the matrix has a special type (identity, translate, scale, etc), the programmer should follow this constructor with a call to optimize() if they wish QMatrix4x4 to optimize further calls to translate(), scale(), etc.
Definition at line 226 of file qmatrix4x4.h.
|
explicit |
Constructs a 4x4 matrix from the left-most 4 columns and top-most 4 rows of matrix. If matrix has less than 4 columns or rows, the remaining elements are filled with elements from the identity matrix.
QMatrix4x4::QMatrix4x4 | ( | const float * | values, |
int | cols, | ||
int | rows | ||
) |
QMatrix4x4::QMatrix4x4 | ( | const QTransform & | transform | ) |
Constructs a 4x4 matrix from the conventional Qt 2D transformation matrix transform.
If transform has a special type (identity, translate, scale, etc), the programmer should follow this constructor with a call to optimize() if they wish QMatrix4x4 to optimize further calls to translate(), scale(), etc.
Definition at line 176 of file qmatrix4x4.cpp.
Q_INLINE_TEMPLATE QMatrix4x4::QMatrix4x4 | ( | const QGenericMatrix< N, M, float > & | matrix | ) |
Definition at line 240 of file qmatrix4x4.h.
|
inline |
Returns the elements of column index as a 4D vector.
Definition at line 289 of file qmatrix4x4.h.
|
inline |
Returns a constant pointer to the raw data of this matrix. This raw data is stored in column-major format.
Definition at line 183 of file qmatrix4x4.h.
void QMatrix4x4::copyDataTo | ( | float * | values | ) | const |
Retrieves the 16 items in this matrix and copies them to values in row-major order.
Definition at line 1652 of file qmatrix4x4.cpp.
|
inline |
Returns a pointer to the raw data of this matrix.
Definition at line 1080 of file qmatrix4x4.h.
|
inline |
Returns a constant pointer to the raw data of this matrix. This raw data is stored in column-major format.
Definition at line 182 of file qmatrix4x4.h.
double QMatrix4x4::determinant | ( | ) | const |
Returns the determinant of this matrix.
Definition at line 326 of file qmatrix4x4.cpp.
|
inline |
Fills all elements of this matrx with value.
Definition at line 367 of file qmatrix4x4.h.
|
inline |
Definition at line 208 of file qmatrix4x4.h.
void QMatrix4x4::flipCoordinates | ( | ) |
Flips between right-handed and left-handed coordinate systems by multiplying the y and z coordinates by -1. This is normally used to create a left-handed orthographic view without scaling the viewport as ortho() does.
Definition at line 1626 of file qmatrix4x4.cpp.
void QMatrix4x4::frustum | ( | float | left, |
float | right, | ||
float | bottom, | ||
float | top, | ||
float | nearPlane, | ||
float | farPlane | ||
) |
Multiplies this matrix by another that applies a perspective frustum projection for a window with lower-left corner (left, bottom), upper-right corner (right, top), and the specified nearPlane and farPlane clipping planes.
Definition at line 1445 of file qmatrix4x4.cpp.
QMatrix4x4 QMatrix4x4::inverted | ( | bool * | invertible = nullptr | ) | const |
Returns the inverse of this matrix. Returns the identity if this matrix cannot be inverted; i.e. determinant() is zero. If invertible is not null, then true will be written to that location if the matrix can be inverted; false otherwise.
If the matrix is recognized as the identity or an orthonormal matrix, then this function will quickly invert the matrix using optimized routines.
Definition at line 352 of file qmatrix4x4.cpp.
|
inline |
Returns true
if this matrix is affine matrix; false otherwise.
An affine matrix is a 4x4 matrix with row 3 equal to (0, 0, 0, 1), e.g. no projective coefficients.
Definition at line 324 of file qmatrix4x4.h.
|
inline |
Returns true
if this matrix is the identity; false otherwise.
Definition at line 329 of file qmatrix4x4.h.
Multiplies this matrix by a viewing matrix derived from an eye point. The center value indicates the center of the view that the eye is looking at. The up value indicates which direction should be considered up with respect to the eye.
Definition at line 1535 of file qmatrix4x4.cpp.
Maps point by multiplying this matrix by point. The matrix is applied pre-point.
Definition at line 938 of file qmatrix4x4.h.
Maps point by post-multiplying this matrix by point. The matrix is applied pre-point.
Definition at line 970 of file qmatrix4x4.h.
Maps point by multiplying this matrix by point extended to a 4D vector by assuming 1.0 for the w coordinate. The matrix is applied pre-point.
Definition at line 1007 of file qmatrix4x4.h.
Maps point by multiplying this matrix by point. The matrix is applied pre-point.
Definition at line 1073 of file qmatrix4x4.h.
Maps rect by multiplying this matrix by the corners of rect and then forming a new rectangle from the results. The returned rectangle will be an ordinary 2D rectangle with sides parallel to the horizontal and vertical axes.
Definition at line 1783 of file qmatrix4x4.cpp.
Maps rect by multiplying this matrix by the corners of rect and then forming a new rectangle from the results. The returned rectangle will be an ordinary 2D rectangle with sides parallel to the horizontal and vertical axes.
Definition at line 1829 of file qmatrix4x4.cpp.
Maps vector by multiplying the top 3x3 portion of this matrix by vector. The translation and projection components of this matrix are ignored. The matrix is applied pre-vector.
Definition at line 1046 of file qmatrix4x4.h.
QMatrix3x3 QMatrix4x4::normalMatrix | ( | ) | const |
Returns the normal matrix corresponding to this 4x4 transformation. The normal matrix is the transpose of the inverse of the top-left 3x3 part of this 4x4 matrix. If the 3x3 sub-matrix is not invertible, this function returns the identity.
Definition at line 472 of file qmatrix4x4.cpp.
QMatrix4x4::operator QVariant | ( | ) | const |
Returns the matrix as a QVariant.
Definition at line 1995 of file qmatrix4x4.cpp.
|
inline |
Returns true
if this matrix is not identical to other; false otherwise. This operator uses an exact floating-point comparison.
Definition at line 573 of file qmatrix4x4.h.
|
inline |
Returns a reference to the element at position (row, column) in this matrix so that the element can be assigned to.
Definition at line 281 of file qmatrix4x4.h.
|
inline |
Returns a constant reference to the element at position (row, column) in this matrix.
Definition at line 275 of file qmatrix4x4.h.
|
inline |
Multiplies the contents of other by this matrix.
Definition at line 432 of file qmatrix4x4.h.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Multiplies all elements of this matrix by factor.
Definition at line 531 of file qmatrix4x4.h.
|
inline |
Adds the contents of other to this matrix.
Definition at line 388 of file qmatrix4x4.h.
|
inline |
Subtracts the contents of other from this matrix.
Definition at line 410 of file qmatrix4x4.h.
QMatrix4x4 & QMatrix4x4::operator/= | ( | float | divisor | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Divides all elements of this matrix by divisor.
Definition at line 571 of file qmatrix4x4.cpp.
|
inline |
Returns true
if this matrix is identical to other; false otherwise. This operator uses an exact floating-point comparison.
Definition at line 553 of file qmatrix4x4.h.
void QMatrix4x4::optimize | ( | ) |
Optimize the usage of this matrix from its current elements.
Some operations such as translate(), scale(), and rotate() can be performed more efficiently if the matrix being modified is already known to be the identity, a previous translate(), a previous scale(), etc.
Normally the QMatrix4x4 class keeps track of this special type internally as operations are performed. However, if the matrix is modified directly with operator()(int, int) or data(), then QMatrix4x4 will lose track of the special type and will revert to the safest but least efficient operations thereafter.
By calling optimize() after directly modifying the matrix, the programmer can force QMatrix4x4 to recover the special type if the elements appear to conform to one of the known optimized types.
Definition at line 1940 of file qmatrix4x4.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Multiplies this matrix by another that applies an orthographic projection for a window with boundaries specified by rect. The near and far clipping planes will be -1 and 1 respectively.
Definition at line 1373 of file qmatrix4x4.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Multiplies this matrix by another that applies an orthographic projection for a window with boundaries specified by rect. The near and far clipping planes will be -1 and 1 respectively.
Definition at line 1391 of file qmatrix4x4.cpp.
void QMatrix4x4::ortho | ( | float | left, |
float | right, | ||
float | bottom, | ||
float | top, | ||
float | nearPlane, | ||
float | farPlane | ||
) |
Multiplies this matrix by another that applies an orthographic projection for a window with lower-left corner (left, bottom), upper-right corner (right, top), and the specified nearPlane and farPlane clipping planes.
Definition at line 1404 of file qmatrix4x4.cpp.
void QMatrix4x4::perspective | ( | float | verticalAngle, |
float | aspectRatio, | ||
float | nearPlane, | ||
float | farPlane | ||
) |
Multiplies this matrix by another that applies a perspective projection. The vertical field of view will be verticalAngle degrees within a window with a given aspectRatio that determines the horizontal field of view. The projection will have the specified nearPlane and farPlane clipping planes which are the distances from the viewer to the corresponding planes.
Definition at line 1488 of file qmatrix4x4.cpp.
void QMatrix4x4::projectedRotate | ( | float | angle, |
float | x, | ||
float | y, | ||
float | z | ||
) |
void QMatrix4x4::rotate | ( | const QQuaternion & | quaternion | ) |
Multiples this matrix by another that rotates coordinates according to a specified quaternion. The quaternion is assumed to have been normalized.
Definition at line 1322 of file qmatrix4x4.cpp.
Multiples this matrix by another that rotates coordinates through angle degrees about vector.
Definition at line 1081 of file qmatrix4x4.cpp.
void QMatrix4x4::rotate | ( | float | angle, |
float | x, | ||
float | y, | ||
float | z = 0.0f |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Multiplies this matrix by another that rotates coordinates through angle degrees about the vector (x, y, z).
Definition at line 1096 of file qmatrix4x4.cpp.
|
inline |
Returns the elements of row index as a 4D vector.
Definition at line 305 of file qmatrix4x4.h.
Multiplies this matrix by another that scales coordinates by the components of vector.
Definition at line 803 of file qmatrix4x4.cpp.
void QMatrix4x4::scale | ( | float | factor | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Multiplies this matrix by another that scales coordinates by the given factor.
Definition at line 924 of file qmatrix4x4.cpp.
void QMatrix4x4::scale | ( | float | x, |
float | y | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Multiplies this matrix by another that scales coordinates by the components x, and y.
Definition at line 849 of file qmatrix4x4.cpp.
void QMatrix4x4::scale | ( | float | x, |
float | y, | ||
float | z | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Multiplies this matrix by another that scales coordinates by the components x, y, and z.
Definition at line 883 of file qmatrix4x4.cpp.
Sets the elements of column index to the components of value.
Definition at line 295 of file qmatrix4x4.h.
Sets the elements of row index to the components of value.
Definition at line 311 of file qmatrix4x4.h.
|
inline |
Sets this matrix to the identity.
Definition at line 346 of file qmatrix4x4.h.
QGenericMatrix< N, M, float > QMatrix4x4::toGenericMatrix |
Constructs a NxM generic matrix from the left-most N columns and top-most M rows of this 4x4 matrix. If N or M is greater than 4, then the remaining elements are filled with elements from the identity matrix.
Definition at line 258 of file qmatrix4x4.h.
QTransform QMatrix4x4::toTransform | ( | ) | const |
Returns the conventional Qt 2D transformation matrix that corresponds to this matrix.
The returned QTransform is formed by simply dropping the third row and third column of the QMatrix4x4. This is suitable for implementing orthographic projections where the z coordinate should be dropped rather than projected.
Definition at line 1668 of file qmatrix4x4.cpp.
QTransform QMatrix4x4::toTransform | ( | float | distanceToPlane | ) | const |
Returns the conventional Qt 2D transformation matrix that corresponds to this matrix.
If distanceToPlane is non-zero, it indicates a projection factor to use to adjust for the z coordinate. The value of 1024 corresponds to the projection factor used by QTransform::rotate() for the x and y axes.
If distanceToPlane is zero, then the returned QTransform is formed by simply dropping the third row and third column of the QMatrix4x4. This is suitable for implementing orthographic projections where the z coordinate should be dropped rather than projected.
Definition at line 1690 of file qmatrix4x4.cpp.
Multiplies this matrix by another that translates coordinates by the components of vector.
Definition at line 965 of file qmatrix4x4.cpp.
void QMatrix4x4::translate | ( | float | x, |
float | y | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Multiplies this matrix by another that translates coordinates by the components x, and y.
Definition at line 1008 of file qmatrix4x4.cpp.
void QMatrix4x4::translate | ( | float | x, |
float | y, | ||
float | z | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Multiplies this matrix by another that translates coordinates by the components x, y, and z.
Definition at line 1042 of file qmatrix4x4.cpp.
QMatrix4x4 QMatrix4x4::transposed | ( | ) | const |
Returns this matrix, transposed about its diagonal.
Definition at line 528 of file qmatrix4x4.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Sets up viewport transform for viewport bounded by rect and with near and far set to 0 and 1 respectively.
Definition at line 1088 of file qmatrix4x4.h.
void QMatrix4x4::viewport | ( | float | left, |
float | bottom, | ||
float | width, | ||
float | height, | ||
float | nearPlane = 0.0f , |
||
float | farPlane = 1.0f |
||
) |
Multiplies this matrix by another that performs the scale and bias transformation used by OpenGL to transform from normalized device coordinates (NDC) to viewport (window) coordinates. That is it maps points from the cube ranging over [-1, 1] in each dimension to the viewport with it's near-lower-left corner at (left, bottom, nearPlane) and with size (width, height, farPlane - nearPlane).
This matches the transform used by the fixed function OpenGL viewport transform controlled by the functions glViewport() and glDepthRange().
Definition at line 1589 of file qmatrix4x4.cpp.
|
friend |
Definition at line 216 of file qmatrix4x4.h.
|
related |
Returns the product of m1 and m2.
Definition at line 637 of file qmatrix4x4.h.
|
friend |
Returns the product of m1 and m2.
Definition at line 637 of file qmatrix4x4.h.
|
related |
Returns the result of transforming vector according to matrix, with the matrix applied pre-vector.
Definition at line 789 of file qmatrix4x4.h.
|
friend |
Returns the result of transforming vector according to matrix, with the matrix applied pre-vector.
Definition at line 789 of file qmatrix4x4.h.
|
related |
Returns the result of multiplying all elements of matrix by factor.
Definition at line 916 of file qmatrix4x4.h.
|
friend |
Returns the result of multiplying all elements of matrix by factor.
Definition at line 916 of file qmatrix4x4.h.
|
related |
Returns the result of transforming point according to matrix, with the matrix applied post-point.
Definition at line 813 of file qmatrix4x4.h.
|
friend |
Returns the result of transforming point according to matrix, with the matrix applied post-point.
Definition at line 813 of file qmatrix4x4.h.
|
related |
Returns the result of transforming point according to matrix, with the matrix applied post-point.
Definition at line 834 of file qmatrix4x4.h.
|
friend |
Returns the result of transforming point according to matrix, with the matrix applied post-point.
Definition at line 834 of file qmatrix4x4.h.
|
related |
Returns the result of transforming vector according to matrix, with the matrix applied post-vector.
Definition at line 767 of file qmatrix4x4.h.
|
friend |
Returns the result of transforming vector according to matrix, with the matrix applied post-vector.
Definition at line 767 of file qmatrix4x4.h.
|
related |
Returns the result of multiplying all elements of matrix by factor.
Definition at line 894 of file qmatrix4x4.h.
|
friend |
Returns the result of multiplying all elements of matrix by factor.
Definition at line 894 of file qmatrix4x4.h.
|
related |
Returns the sum of m1 and m2.
Definition at line 593 of file qmatrix4x4.h.
|
friend |
Returns the sum of m1 and m2.
Definition at line 593 of file qmatrix4x4.h.
|
related |
Returns the difference of m1 and m2.
Definition at line 615 of file qmatrix4x4.h.
|
friend |
Returns the difference of m1 and m2.
Definition at line 615 of file qmatrix4x4.h.
|
related |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns the negation of matrix.
Definition at line 872 of file qmatrix4x4.h.
|
friend |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns the negation of matrix.
Definition at line 872 of file qmatrix4x4.h.
|
related |
Returns the result of dividing all elements of matrix by divisor.
Definition at line 744 of file qmatrix4x4.cpp.
|
friend |
Returns the result of dividing all elements of matrix by divisor.
Definition at line 744 of file qmatrix4x4.cpp.
|
related |
Writes the given matrix to the given stream and returns a reference to the stream.
Definition at line 2050 of file qmatrix4x4.cpp.
|
friend |
Definition at line 2002 of file qmatrix4x4.cpp.
|
related |
Reads a 4x4 matrix from the given stream into the given matrix and returns a reference to the stream.
Definition at line 2068 of file qmatrix4x4.cpp.
|
related |
Returns true
if m1 and m2 are equal, allowing for a small fuzziness factor for floating-point comparisons; false otherwise.
Definition at line 774 of file qmatrix4x4.cpp.
|
friend |
Returns true
if m1 and m2 are equal, allowing for a small fuzziness factor for floating-point comparisons; false otherwise.
Definition at line 774 of file qmatrix4x4.cpp.