PySide6.QtGui.QMatrix4x4¶
- class QMatrix4x4¶
- The - QMatrix4x4class represents a 4x4 transformation matrix in 3D space. More…- Added in version 4.6. - Synopsis¶- Methods¶- def - __init__()
- def - __dummy()
- def - __mgetitem__()
- def - __reduce__()
- def - __repr__()
- def - column()
- def - copyDataTo()
- def - determinant()
- def - fill()
- def - flags()
- def - frustum()
- def - inverted()
- def - isAffine()
- def - isIdentity()
- def - lookAt()
- def - map()
- def - mapRect()
- def - mapVector()
- def - normalMatrix()
- def - __ne__()
- def - __mul__()
- def - __imul__()
- def - __add__()
- def - __iadd__()
- def - __sub__()
- def - __isub__()
- def - __div__()
- def - operator/=()
- def - __eq__()
- def - optimize()
- def - ortho()
- def - perspective()
- def - rotate()
- def - row()
- def - scale()
- def - setColumn()
- def - setRow()
- def - setToIdentity()
- def - toTransform()
- def - translate()
- def - transposed()
- def - viewport()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- The - QMatrix4x4class 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: - data()
- constData()
 - See also - QVector3D- QGenericMatrix- class Flag¶
 - __init__()¶
 - Constructs an identity matrix. - __init__(transform)
- Parameters:
- transform – - QTransform
 
 - Constructs a 4x4 matrix from the conventional Qt 2D transformation matrix - transform.- If - transformhas a special type (identity, translate, scale, etc), the programmer should follow this constructor with a call to- optimize()if they wish- QMatrix4x4to optimize further calls to- translate(),- scale(), etc.- See also - __init__(values)
- Parameters:
- values – float 
 
 - Constructs a matrix from the given 16 floating-point - values. The contents of the array- valuesis 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- QMatrix4x4to optimize further calls to- translate(),- scale(), etc.- See also - __init__(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44)
- Parameters:
- 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 – float 
 
 
 - 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- QMatrix4x4to optimize further calls to- translate(),- scale(), etc.- See also - __dummy(arg__1)¶
- Parameters:
- arg__1 – .list of float 
 
 - __mgetitem__()¶
- Return type:
- object 
 
 - __reduce__()¶
- Return type:
- str 
 
 - __repr__()¶
- Return type:
- str 
 
 - Returns the elements of column - indexas a 4D vector.- See also - copyDataTo()¶
- Return type:
- Tuple 
 
 - Retrieves the 16 items in this matrix and copies them to - valuesin row-major order.- determinant()¶
- Return type:
- float 
 
 - Returns the determinant of this matrix. - fill(value)¶
- Parameters:
- value – float 
 
 - Fills all elements of this matrx with - value.- 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.- See also - frustum(left, right, bottom, top, nearPlane, farPlane)¶
- Parameters:
- left – float 
- right – float 
- bottom – float 
- top – float 
- nearPlane – float 
- farPlane – float 
 
 
 - 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- nearPlaneand- farPlaneclipping planes.- See also - inverted()¶
- Return type:
- PyTuple 
 
 - Returns the inverse of this matrix. Returns the identity if this matrix cannot be inverted; i.e. - determinant()is zero. If- invertibleis 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 - isAffine()¶
- Return type:
- bool 
 
 - Returns - trueif 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. - See also - isIdentity()¶
- Return type:
- bool 
 
 - Returns - trueif this matrix is the identity; false otherwise.- See also - Multiplies this matrix by a viewing matrix derived from an eye point. The - centervalue indicates the center of the view that the- eyeis looking at. The- upvalue indicates which direction should be considered up with respect to the- eye.- Note - The - upvector must not be parallel to the line of sight from- eyeto- center.- Maps - pointby multiplying this matrix by- point. The matrix is applied pre-point.- See also - Maps - pointby post-multiplying this matrix by- point. The matrix is applied pre-point.- See also - Maps - pointby multiplying this matrix by- pointextended to a 4D vector by assuming 1.0 for the w coordinate. The matrix is applied pre-point.- Note - This function is not the same as - mapVector(). For points, always use- map().- mapVector()is suitable for vectors (directions) only.- See also - Maps - pointby multiplying this matrix by- point. The matrix is applied pre-point.- See also - Maps - rectby multiplying this matrix by the corners of- rectand 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 - Maps - rectby multiplying this matrix by the corners of- rectand 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 - Maps - vectorby 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 - normalMatrix()¶
- Return type:
 
 - 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 - __ne__(other)¶
- Parameters:
- other – - QMatrix4x4
- Return type:
- bool 
 
 - Returns - trueif this matrix is not identical to- other; false otherwise. This operator uses an exact floating-point comparison.- __mul__(m2)¶
- Parameters:
- m2 – - QMatrix4x4
- Return type:
 
 - Returns the product of - m1and- m2.- __mul__(factor)
- Parameters:
- factor – float 
- Return type:
 
 - Returns the result of multiplying all elements of - matrixby- factor.- __mul__(factor)
- Parameters:
- factor – float 
- Return type:
 
 - Returns the result of multiplying all elements of - matrixby- factor.- __imul__(other)¶
- Parameters:
- other – - QMatrix4x4
- Return type:
 
 - Multiplies the contents of - otherby this matrix.- __imul__(factor)
- Parameters:
- factor – float 
- Return type:
 
 - This is an overloaded function. - Multiplies all elements of this matrix by - factor.- __add__(m2)¶
- Parameters:
- m2 – - QMatrix4x4
- Return type:
 
 - Returns the sum of - m1and- m2.- __iadd__(other)¶
- Parameters:
- other – - QMatrix4x4
- Return type:
 
 - Adds the contents of - otherto this matrix.- __sub__()¶
- Return type:
 
 - This is an overloaded function. - Returns the negation of - matrix.- __sub__(m2)
- Parameters:
- m2 – - QMatrix4x4
- Return type:
 
 - Returns the difference of - m1and- m2.- __isub__(other)¶
- Parameters:
- other – - QMatrix4x4
- Return type:
 
 - Subtracts the contents of - otherfrom this matrix.- __div__(divisor)¶
- Parameters:
- divisor – float 
- Return type:
 
 - Returns the result of dividing all elements of - matrixby- divisor.- operator/=(divisor)
- Parameters:
- divisor – float 
- Return type:
 
 - This is an overloaded function. - Divides all elements of this matrix by - divisor.- __eq__(other)¶
- Parameters:
- other – - QMatrix4x4
- Return type:
- bool 
 
 - Returns - trueif this matrix is identical to- other; false otherwise. This operator uses an exact floating-point comparison.- 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 - QMatrix4x4class 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- QMatrix4x4will 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 - QMatrix4x4to recover the special type if the elements appear to conform to one of the known optimized types.- See also - operator()(int, int)- data()- translate()- 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 - ortho(rect)
- Parameters:
- rect – - QRectF
 
 - 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 - ortho(left, right, bottom, top, nearPlane, farPlane)
- Parameters:
- left – float 
- right – float 
- bottom – float 
- top – float 
- nearPlane – float 
- farPlane – float 
 
 
 - 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- nearPlaneand- farPlaneclipping planes.- See also - perspective(verticalAngle, aspectRatio, nearPlane, farPlane)¶
- Parameters:
- verticalAngle – float 
- aspectRatio – float 
- nearPlane – float 
- farPlane – float 
 
 
 - Multiplies this matrix by another that applies a perspective projection. The vertical field of view will be - verticalAngledegrees within a window with a given- aspectRatiothat determines the horizontal field of view. The projection will have the specified- nearPlaneand- farPlaneclipping planes which are the distances from the viewer to the corresponding planes.- projectedRotate(angle, x, y, z)¶
- Parameters:
- angle – float 
- x – float 
- y – float 
- z – float 
 
 
 - projectedRotate(angle, x, y, z, distanceToPlane)
- Parameters:
- angle – float 
- x – float 
- y – float 
- z – float 
- distanceToPlane – float 
 
 
 - rotate(quaternion)¶
- Parameters:
- quaternion – - QQuaternion
 
 - Multiples this matrix by another that rotates coordinates according to a specified - quaternion. The- quaternionis assumed to have been normalized.- See also - rotate(angle, vector)
- Parameters:
- angle – float 
- vector – - QVector3D
 
 
 - Multiples this matrix by another that rotates coordinates through - angledegrees about- vector.- See also - rotate(angle, x, y[, z=0.0f])
- Parameters:
- angle – float 
- x – float 
- y – float 
- z – float 
 
 
 - This is an overloaded function. - Multiplies this matrix by another that rotates coordinates through - angledegrees about the vector (- x,- y,- z).- See also - Returns the elements of row - indexas a 4D vector.- Multiplies this matrix by another that scales coordinates by the components of - vector.- See also - scale(factor)
- Parameters:
- factor – float 
 
 - This is an overloaded function. - Multiplies this matrix by another that scales coordinates by the given - factor.- See also - scale(x, y)
- Parameters:
- x – float 
- y – float 
 
 
 - This is an overloaded function. - Multiplies this matrix by another that scales coordinates by the components - x, and- y.- See also - scale(x, y, z)
- Parameters:
- x – float 
- y – float 
- z – float 
 
 
 - This is an overloaded function. - Multiplies this matrix by another that scales coordinates by the components - x,- y, and- z.- See also - Sets the elements of column - indexto the components of- value.- Sets the elements of row - indexto the components of- value.- See also - setToIdentity()¶
 - Sets this matrix to the identity. - See also - toTransform()¶
- Return type:
 
 - Returns the conventional Qt 2D transformation matrix that corresponds to this matrix. - The returned - QTransformis 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.- toTransform(distanceToPlane)
- Parameters:
- distanceToPlane – float 
- Return type:
 
 - Returns the conventional Qt 2D transformation matrix that corresponds to this matrix. - If - distanceToPlaneis 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- rotate()for the x and y axes.- If - distanceToPlaneis zero, then the returned- QTransformis 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.- Multiplies this matrix by another that translates coordinates by the components of - vector.- translate(x, y)
- Parameters:
- x – float 
- y – float 
 
 
 - This is an overloaded function. - Multiplies this matrix by another that translates coordinates by the components - x, and- y.- translate(x, y, z)
- Parameters:
- x – float 
- y – float 
- z – float 
 
 
 - This is an overloaded function. - Multiplies this matrix by another that translates coordinates by the components - x,- y, and- z.- transposed()¶
- Return type:
 
 - Returns this matrix, transposed about its diagonal. - This is an overloaded function. - Sets up viewport transform for viewport bounded by - rectand with near and far set to 0 and 1 respectively.- viewport(left, bottom, width, height[, nearPlane=0.0f[, farPlane=1.0f]])
- Parameters:
- left – float 
- bottom – float 
- width – float 
- height – float 
- nearPlane – float 
- farPlane – float 
 
 
 - 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().