QMatrix4x4 Class

  • Header: QMatrix4x4

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS Gui)

    target_link_libraries(mytarget PRIVATE Qt6::Gui)

  • qmake: QT += gui

  • Group: QMatrix4x4 is part of Rendering in 3D

Detailed Description

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:

See Also

Member Function Documentation

 

QMatrix4x4::QMatrix4x4()

Constructs an identity matrix.

[explicit] QMatrix4x4::QMatrix4x4(const float *values)

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.

See Also

See also copyDataTo(), optimize()

QMatrix4x4::QMatrix4x4(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44)

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.

See Also

See also optimize()

[explicit] QMatrix4x4::QMatrix4x4(const QGenericMatrix<N, M, float> &matrix = N)

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.

See Also

See also toGenericMatrix()

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.

See Also

See also toTransform(), optimize()

QVector4D QMatrix4x4::column(int index) const

Returns the elements of column index as a 4D vector.

See Also

See also setColumn(), row()

const float *QMatrix4x4::constData() const

Returns a constant pointer to the raw data of this matrix. This raw data is stored in column-major format.

See Also

See also data()

void QMatrix4x4::copyDataTo(float *values) const

Retrieves the 16 items in this matrix and copies them to values in row-major order.

float *QMatrix4x4::data()

Returns a pointer to the raw data of this matrix.

See Also

See also constData(), optimize()

const float *QMatrix4x4::data() const

Returns a constant pointer to the raw data of this matrix. This raw data is stored in column-major format.

See Also

See also constData()

double QMatrix4x4::determinant() const

Returns the determinant of this matrix.

void QMatrix4x4::fill(float value)

Fills all elements of this matrx with value.

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.

See Also

See also ortho(), perspective()

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.

See Also

See also determinant(), normalMatrix()

[since 5.5] bool QMatrix4x4::isAffine() const

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.

This function was introduced in Qt 5.5.

See Also

See also isIdentity()

bool QMatrix4x4::isIdentity() const

Returns true if this matrix is the identity; false otherwise.

See Also

See also setToIdentity()

void QMatrix4x4::lookAt(const QVector3D &eye, const QVector3D &center, const QVector3D &up)

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.

The up vector must not be parallel to the line of sight from eye to center.

QPoint QMatrix4x4::map(const QPoint &point) const

Maps point by multiplying this matrix by point.

See Also

See also mapRect()

QPointF QMatrix4x4::map(const QPointF &point) const

Maps point by multiplying this matrix by point.

See Also

See also mapRect()

QVector3D QMatrix4x4::map(const QVector3D &point) const

Maps point by multiplying this matrix by point.

See Also

See also mapRect(), mapVector()

QVector4D QMatrix4x4::map(const QVector4D &point) const

Maps point by multiplying this matrix by point.

See Also

See also mapRect()

QRect QMatrix4x4::mapRect(const QRect &rect) const

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.

See Also

See also map()

QRectF QMatrix4x4::mapRect(const QRectF &rect) const

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.