Home · All Classes · All Functions · Overviews

QMatrix4x4 Class Reference
[
QtGui module]

The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space. More...

 #include <QMatrix4x4>

This class was introduced in Qt 4.6.


Public Functions

QMatrix4x4 ()
QMatrix4x4 ( const qreal * values )
QMatrix4x4 ( qreal m11, qreal m12, qreal m13, qreal m14, qreal m21, qreal m22, qreal m23, qreal m24, qreal m31, qreal m32, qreal m33, qreal m34, qreal m41, qreal m42, qreal m43, qreal m44 )
QMatrix4x4 ( const QGenericMatrix<N, M, qreal> & matrix )
QMatrix4x4 ( const QTransform & transform )
QMatrix4x4 ( const QMatrix & matrix )
QVector4D column ( int index ) const
const qreal * constData () const
qreal * data ()
const qreal * data () const
qreal determinant () const
void extractAxisRotation ( qreal & angle, QVector3D & axis ) const
QVector3D extractTranslation () const
void fill ( qreal value )
QMatrix4x4 & flipCoordinates ()
QMatrix4x4 & frustum ( qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane )
void inferSpecialType ()
QMatrix4x4 inverted ( bool * invertible = 0 ) const
bool isIdentity () const
QMatrix4x4 & lookAt ( const QVector3D & eye, const QVector3D & center, const QVector3D & up )
QPoint map ( const QPoint & point ) const
QPointF map ( const QPointF & point ) const
QVector3D map ( const QVector3D & point ) const
QVector4D map ( const QVector4D & point ) const
QRect mapRect ( const QRect & rect ) const
QRectF mapRect ( const QRectF & rect ) const
QVector3D mapVector ( const QVector3D & vector ) const
QMatrix3x3 normalMatrix () const
QMatrix4x4 & ortho ( qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane )
QMatrix4x4 & ortho ( const QRect & rect )
QMatrix4x4 & ortho ( const QRectF & rect )
QMatrix4x4 & perspective ( qreal angle, qreal aspect, qreal nearPlane, qreal farPlane )
QMatrix4x4 & rotate ( qreal angle, const QVector3D & vector )
QMatrix4x4 & rotate ( const QQuaternion & quaternion )
QMatrix4x4 & rotate ( qreal angle, qreal x, qreal y, qreal z = 0.0f )
QVector4D row ( int index ) const
QMatrix4x4 & scale ( const QVector3D & vector )
QMatrix4x4 & scale ( qreal x, qreal y )
QMatrix4x4 & scale ( qreal x, qreal y, qreal z )
QMatrix4x4 & scale ( qreal factor )
void setColumn ( int index, const QVector4D & value )
void setIdentity ()
void setRow ( int index, const QVector4D & value )
QMatrix toAffine () const
QGenericMatrix<N, M, qreal> toGenericMatrix () const
QTransform toTransform ( qreal distanceToPlane = 1024.0f ) const
void toValueArray ( qreal * values ) const
QMatrix4x4 & translate ( const QVector3D & vector )
QMatrix4x4 & translate ( qreal x, qreal y )
QMatrix4x4 & translate ( qreal x, qreal y, qreal z )
QMatrix4x4 transposed () const
operator QVariant () const
bool operator!= ( const QMatrix4x4 & other ) const
const qreal & operator() ( int row, int column ) const
qreal & operator() ( int row, int column )
QMatrix4x4 & operator*= ( const QMatrix4x4 & other )
QMatrix4x4 & operator*= ( qreal factor )
QMatrix4x4 & operator+= ( const QMatrix4x4 & other )
QMatrix4x4 & operator-= ( const QMatrix4x4 & other )
QMatrix4x4 & operator/= ( qreal divisor )
bool operator== ( const QMatrix4x4 & other ) const

Related Non-Members

bool qFuzzyCompare ( const QMatrix4x4 & m1, const QMatrix4x4 & m2 )
QGenericMatrix<N, M, qreal> qGenericMatrixFromMatrix4x4 ( const QMatrix4x4 & matrix )
QMatrix4x4 qGenericMatrixToMatrix4x4 ( const QGenericMatrix<N, M, qreal> & matrix )
QPointF operator* ( const QPointF & point, const QMatrix4x4 & matrix )
QPoint operator* ( const QMatrix4x4 & matrix, const QPoint & point )
QPointF operator* ( const QMatrix4x4 & matrix, const QPointF & point )
QMatrix4x4 operator* ( qreal factor, const QMatrix4x4 & matrix )
QMatrix4x4 operator* ( const QMatrix4x4 & matrix, qreal factor )
QMatrix4x4 operator* ( const QMatrix4x4 & m1, const QMatrix4x4 & m2 )
QVector3D operator* ( const QVector3D & vector, const QMatrix4x4 & matrix )
QVector3D operator* ( const QMatrix4x4 & matrix, const QVector3D & vector )
QVector4D operator* ( const QVector4D & vector, const QMatrix4x4 & matrix )
QVector4D operator* ( const QMatrix4x4 & matrix, const QVector4D & vector )
QPoint operator* ( const QPoint & point, const QMatrix4x4 & matrix )
QMatrix4x4 operator+ ( const QMatrix4x4 & m1, const QMatrix4x4 & m2 )
QMatrix4x4 operator- ( const QMatrix4x4 & m1, const QMatrix4x4 & m2 )
QMatrix4x4 operator- ( const QMatrix4x4 & matrix )
QMatrix4x4 operator/ ( const QMatrix4x4 & matrix, qreal divisor )
QDataStream & operator<< ( QDataStream & stream, const QMatrix4x4 & matrix )
QDataStream & operator>> ( QDataStream & stream, QMatrix4x4 & matrix )

Detailed Description

The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.

See also QVector3D and QGenericMatrix.


Member Function Documentation

QMatrix4x4::QMatrix4x4 ()

Constructs an identity matrix.

QMatrix4x4::QMatrix4x4 ( const qreal * 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 inferSpecialType() if they wish QMatrix4x4 to optimize further calls to translate(), scale(), etc.

See also toValueArray() and inferSpecialType().

QMatrix4x4::QMatrix4x4 ( qreal m11, qreal m12, qreal m13, qreal m14, qreal m21, qreal m22, qreal m23, qreal m24, qreal m31, qreal m32, qreal m33, qreal m34, qreal m41, qreal m42, qreal m43, qreal 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 inferSpecialType() if they wish QMatrix4x4 to optimize further calls to translate(), scale(), etc.

See also inferSpecialType().

QMatrix4x4::QMatrix4x4 ( const QGenericMatrix<N, M, qreal> & matrix )

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 toGenericMatrix() and qGenericMatrixToMatrix4x4().

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 inferSpecialType() if they wish QMatrix4x4 to optimize further calls to translate(), scale(), etc.

See also toTransform() and inferSpecialType().

QMatrix4x4::QMatrix4x4 ( const QMatrix & matrix )

Constructs a 4x4 matrix from a conventional Qt 2D affine transformation matrix.

If matrix has a special type (identity, translate, scale, etc), the programmer should follow this constructor with a call to inferSpecialType() if they wish QMatrix4x4 to optimize further calls to translate(), scale(), etc.

See also toAffine() and inferSpecialType().

QVector4D QMatrix4x4::column ( int index ) const

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

See also setColumn() and row().

const qreal * QMatrix4x4::constData () const

Returns a constant pointer to the raw data of this matrix.

See also data().

qreal * QMatrix4x4::data ()

Returns a pointer to the raw data of this matrix.

See also constData() and inferSpecialType().

const qreal * QMatrix4x4::data () const

Returns a constant pointer to the raw data of this matrix.

See also constData().

qreal QMatrix4x4::determinant () const

Returns the determinant of this matrix.

void QMatrix4x4::extractAxisRotation ( qreal & angle, QVector3D & axis ) const

Decomposes the current rotation matrix into an axis of rotation plus an angle. The result can be used to construct an equivalent rotation matrix using glRotate(). It is assumed that the homogenous coordinate is 1.0. The returned vector is guaranteed to be normalized.

 qreal angle;
 QVector3D axis;

 matrix.extractAxisAngle(angle, axis);
 glRotate(angle, axis[0], axis[1], axis[2]);

See also rotate().

QVector3D QMatrix4x4::extractTranslation () const

If this is an orthonormal transformation matrix (e.g. only rotations and translations have been applied to the matrix, no scaling, or shearing) then the world translational component can be obtained by calling this function.

This is most useful for camera matrices, where the negation of this vector is effectively the camera world coordinates.

void QMatrix4x4::fill ( qreal value )

Fills all elements of this matrx with value.

QMatrix4x4 & QMatrix4x4::flipCoordinates ()

Flips between right-handed and left-handed coordinate systems by multiplying the y and z co-ordinates by -1. This is normally used to create a left-handed orthographic view without scaling the viewport as ortho() does. Returns this matrix.

See also ortho().

QMatrix4x4 & QMatrix4x4::frustum ( qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal 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. Returns this matrix.

See also ortho() and perspective().

void QMatrix4x4::inferSpecialType ()

Infers the special type 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()() or data(), then QMatrix4x4 will lose track of the special type and will revert to the safest but least efficient operations thereafter.

By calling inferSpecialType() 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 operator()(), data(), and translate().

QMatrix4x4 QMatrix4x4::inverted ( bool * invertible = 0 ) 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 determinant() and normalMatrix().

bool QMatrix4x4::isIdentity () const

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

See also setIdentity().

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

Multiplies this matrix by another that applies an eye position transformation. 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. Returns this matrix.

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

Maps point by multiplying this matrix by point.

See also mapRect().

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

Maps point by multiplying this matrix by point.

See also mapRect().

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

Maps point by multiplying this matrix by point.

See also mapRect() and mapVector().

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

Maps point by multiplying this matrix by point.

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

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

QMatrix4x4 & QMatrix4x4::ortho ( qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal 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. Returns this matrix.

See also frustum() and perspective().

QMatrix4x4 & 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. Returns this matrix.

See also frustum() and perspective().

QMatrix4x4 & 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. Returns this matrix.

See also frustum() and perspective().

QMatrix4x4 & QMatrix4x4::perspective ( qreal angle, qreal aspect, qreal nearPlane, qreal farPlane )

Multiplies this matrix by another that applies a perspective projection. The field of view will be angle degrees within a window with a given aspect ratio. The projection will have the specified nearPlane and farPlane clipping planes. Returns this matrix.

See also ortho() and frustum().

QMatrix4x4 & QMatrix4x4::rotate ( qreal angle, const QVector3D & vector )

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

See also scale() and translate().

QMatrix4x4 & 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. Returns this matrix.

See also scale(), translate(), and QQuaternion.

QMatrix4x4 & QMatrix4x4::rotate ( qreal angle, qreal x, qreal y, qreal 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). Returns this matrix.

See also scale() and translate().

QVector4D QMatrix4x4::row ( int index ) const

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

See also setRow() and column().

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

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

See also translate() and rotate().

QMatrix4x4 & QMatrix4x4::scale ( qreal x, qreal y )

This is an overloaded function.

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

See also translate() and rotate().

QMatrix4x4 & QMatrix4x4::scale ( qreal x, qreal y, qreal z )

This is an overloaded function.

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

See also translate() and rotate().

QMatrix4x4 & QMatrix4x4::scale ( qreal factor )

This is an overloaded function.

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

See also translate() and rotate().

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

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

See also column() and setRow().

void QMatrix4x4::setIdentity ()

Sets this matrix to the identity.

See also isIdentity().

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

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

See also row() and setColumn().

QMatrix QMatrix4x4::toAffine () const

Returns the conventional Qt 2D affine transformation matrix that corresponds to this matrix. It is assumed that this matrix only contains 2D affine transformation elements.

See also toTransform().

QGenericMatrix<N, M, qreal> 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.

See also qGenericMatrixFromMatrix4x4().

QTransform QMatrix4x4::toTransform ( qreal distanceToPlane = 1024.0f ) 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 co-ordinate. The default 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 co-ordinate should be dropped rather than projected.

See also toAffine().

void QMatrix4x4::toValueArray ( qreal * values ) const

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

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

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

See also scale() and rotate().

QMatrix4x4 & QMatrix4x4::translate ( qreal x, qreal y )

This is an overloaded function.

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

See also scale() and rotate().

QMatrix4x4 & QMatrix4x4::translate ( qreal x, qreal y, qreal z )

This is an overloaded function.

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

See also scale() and rotate().

QMatrix4x4 QMatrix4x4::transposed () const

Returns this matrix, transposed about its diagonal.

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 qreal & QMatrix4x4::operator() ( int row, int column ) const

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

See also column() and row().

qreal & 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 inferSpecialType(), setColumn(), and setRow().

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

Multiplies the contents of other by this matrix.

QMatrix4x4 & QMatrix4x4::operator*= ( qreal 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/= ( qreal 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

bool qFuzzyCompare ( const QMatrix4x4 & m1, const QMatrix4x4 & m2 )

Returns true if m1 and m2 are equal, allowing for a small fuzziness factor for floating-point comparisons; false otherwise.

QGenericMatrix<N, M, qreal> qGenericMatrixFromMatrix4x4 ( const QMatrix4x4 & matrix )

Returns a NxM generic matrix constructed from the left-most N columns and top-most M rows of matrix. If N or M is greater than 4, then the remaining elements are filled with elements from the identity matrix.

See also qGenericMatrixToMatrix4x4() and QMatrix4x4::toGenericMatrix().

QMatrix4x4 qGenericMatrixToMatrix4x4 ( const QGenericMatrix<N, M, qreal> & matrix )

Returns a 4x4 matrix constructed 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 qGenericMatrixFromMatrix4x4().

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

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

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

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

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

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

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

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

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

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

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

Returns the product of m1 and m2.

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

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

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

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

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.

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, qreal 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 Format of the QDataStream Operators.

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 Format of the QDataStream Operators.


Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies) Trademarks
Qt 4.6.0