IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QMatrix4x4 Class

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

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. The matrix is applied pre-point.

See Also

See also mapRect()

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

Maps point by post-multiplying this matrix by point. The matrix is applied pre-point.

See Also

See also mapRect()

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

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.

This function is not the same as mapVector(). For points, always use map(). mapVector() is suitable for vectors (directions) only.

See Also

See also mapRect(), mapVector()

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

Maps point by multiplying this matrix by point. The matrix is applied pre-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.

See Also

See also map()

QVector3D QMatrix4x4::mapVector(const QVector3D &vector) const

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.

See Also

See also map()

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.

See Also

See also inverted()

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.

See Also

See also operator()(int, int), data(), translate()

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.

See Also

See also frustum(), perspective()

void QMatrix4x4::ortho(const QRect &rect)

This is an overloaded function.

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.

See Also

See also frustum(), perspective()

void QMatrix4x4::ortho(const QRectF &rect)

This is an overloaded function.

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.

See Also

See also frustum(), perspective()

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.

See Also

See also ortho(), frustum()

void QMatrix4x4::rotate(float angle, const QVector3D &vector)

Multiples this matrix by another that rotates coordinates through angle degrees about vector.

See Also

See also scale(), translate()

void QMatrix4x4::rotate(float angle, float x, float y, float z = 0.0f)

This is an overloaded function.

Multiplies this matrix by another that rotates coordinates through angle degrees about the vector (x, y, z).

See Also

See also scale(), translate()

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.

See Also

See also scale(), translate(), QQuaternion

QVector4D QMatrix4x4::row(int index) const

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

See Also

See also setRow(), column()

void QMatrix4x4::scale(const QVector3D &vector)

Multiplies this matrix by another that scales coordinates by the components of vector.

See Also

See also translate(), rotate()

void QMatrix4x4::scale(float x, float y)

This is an overloaded function.

Multiplies this matrix by another that scales coordinates by the components x, and y.

See Also

See also translate(), rotate()

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

This is an overloaded function.

Multiplies this matrix by another that scales coordinates by the components x, y, and z.

See Also

See also translate(), rotate()

void QMatrix4x4::scale(float factor)

This is an overloaded function.

Multiplies this matrix by another that scales coordinates by the given factor.

See Also

See also translate(), rotate()

void QMatrix4x4::setColumn(int index, const QVector4D &value)

Sets the elements of column index to the components of value.

See Also

See also column(), setRow()

void QMatrix4x4::setRow(int index, const QVector4D &value)

Sets the elements of row index to the components of value.

See Also

See also row(), setColumn()

void QMatrix4x4::setToIdentity()

Sets this matrix to the identity.

See Also

See also isIdentity()

QGenericMatrix<N, M, float> QMatrix4x4::toGenericMatrix() const

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.

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.

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.

void QMatrix4x4::translate(const QVector3D &vector)

Multiplies this matrix by another that translates coordinates by the components of vector.

See Also

See also scale(), rotate()

void QMatrix4x4::translate(float x, float y)

This is an overloaded function.

Multiplies this matrix by another that translates coordinates by the components x, and y.

See Also

See also scale(), rotate()

void QMatrix4x4::translate(float x, float y, float z)

This is an overloaded function.

Multiplies this matrix by another that translates coordinates by the components x, y, and z.

See Also

See also scale(), rotate()

QMatrix4x4 QMatrix4x4::transposed() const

Returns this matrix, transposed about its diagonal.

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().

void QMatrix4x4::viewport(const QRectF &rect)

This is an overloaded function.

Sets up viewport transform for viewport bounded by rect and with near and far set to 0 and 1 respectively.

QVariant QMatrix4x4::operator QVariant() const

Returns the matrix as a QVariant.

bool QMatrix4x4::operator!=(const QMatrix4x4 &other) const

Returns true if this matrix is not identical to other; false otherwise. This operator uses an exact floating-point comparison.

const float &QMatrix4x4::operator()(int row, int column) const

Returns a constant reference to the element at position (row, column) in this matrix.

See Also

See also column(), row()

float &QMatrix4x4::operator()(int row, int column)

Returns a reference to the element at position (row, column) in this matrix so that the element can be assigned to.

See Also

See also optimize(), setColumn(), setRow()

QMatrix4x4 &QMatrix4x4::operator*=(const QMatrix4x4 &other)

Multiplies the contents of other by this matrix.

QMatrix4x4 &QMatrix4x4::operator*=(float factor)

This is an overloaded function.

Multiplies all elements of this matrix by factor.

QMatrix4x4 &QMatrix4x4::operator+=(const QMatrix4x4 &other)

Adds the contents of other to this matrix.

QMatrix4x4 &QMatrix4x4::operator-=(const QMatrix4x4 &other)

Subtracts the contents of other from this matrix.

QMatrix4x4 &QMatrix4x4::operator/=(float divisor)

This is an overloaded function.

Divides all elements of this matrix by divisor.

bool QMatrix4x4::operator==(const QMatrix4x4 &other) const

Returns true if this matrix is identical to other; false otherwise. This operator uses an exact floating-point comparison.

Related Non-Members

 

QMatrix4x4 operator*(const QMatrix4x4 &m1, const QMatrix4x4 &m2)

Returns the product of m1 and m2.

QVector4D operator*(const QVector4D &vector, const QMatrix4x4 &matrix)

Returns the result of transforming vector according to matrix, with the matrix applied post-vector.

QVector4D operator*(const QMatrix4x4 &matrix, const QVector4D &vector)

Returns the result of transforming vector according to matrix, with the matrix applied pre-vector.

QPoint operator*(const QPoint &point, const QMatrix4x4 &matrix)

Returns the result of transforming point according to matrix, with the matrix applied post-point.

QPointF operator*(const QPointF &point, const QMatrix4x4 &matrix)

Returns the result of transforming point according to matrix, with the matrix applied post-point.

QMatrix4x4 operator*(float factor, const QMatrix4x4 &matrix)

Returns the result of multiplying all elements of matrix by factor.

QMatrix4x4 operator*(const QMatrix4x4 &matrix, float factor)

Returns the result of multiplying all elements of matrix by factor.

QMatrix4x4 operator+(const QMatrix4x4 &m1, const QMatrix4x4 &m2)

Returns the sum of m1 and m2.

QMatrix4x4 operator-(const QMatrix4x4 &m1, const QMatrix4x4 &m2)

Returns the difference of m1 and m2.

QMatrix4x4 operator-(const QMatrix4x4 &matrix)

This is an overloaded function.

Returns the negation of matrix.

QMatrix4x4 operator/(const QMatrix4x4 &matrix, float divisor)

Returns the result of dividing all elements of matrix by divisor.

QDataStream &operator<<(QDataStream &stream, const QMatrix4x4 &matrix)

Writes the given matrix to the given stream and returns a reference to the stream.

See Also

QDataStream &operator>>(QDataStream &stream, QMatrix4x4 &matrix)

Reads a 4x4 matrix from the given stream into the given matrix and returns a reference to the stream.

See Also

Obsolete Members for QMatrix4x4

The following members of class QMatrix4x4 are deprecated. We strongly advise against using them in new code.

Obsolete Member Function Documentation

 
void QMatrix4x4::flipCoordinates()

This function is deprecated. We strongly advise against using it in new code.

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.

See Also

See also ortho()

Obsolete Related Non-Members

 
QVector3D operator*(const QVector3D &vector, const QMatrix4x4 &matrix)

This function is deprecated since 6.1. We strongly advise against using it in new code.

Convert the QVector3D to a QVector4D with 1.0 as the w coordinate, then multiply.

Returns the result of transforming vector according to matrix, with the matrix applied post-vector. The vector is transformed as a point.

QVector3D operator*(const QMatrix4x4 &matrix, const QVector3D &vector)

This function is deprecated since 6.1. We strongly advise against using it in new code.

Use QMatrix4x4::map() instead.

Returns the result of transforming vector according to matrix, with the matrix applied pre-vector. The vector is transformed as a projective point.

QPoint operator*(const QMatrix4x4 &matrix, const QPoint &point)

This function is deprecated since 6.1. We strongly advise against using it in new code.

Use QMatrix4x4::map() instead.

Returns the result of transforming point according to matrix, with the matrix applied pre-point.

QPointF operator*(const QMatrix4x4 &matrix, const QPointF &point)

This function is deprecated since 6.1. We strongly advise against using it in new code.

Use QMatrix4x4::map() instead.

Returns the result of transforming point according to matrix, with the matrix applied pre-point.

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+