Qt 4.8
Public Functions | Private Types | Private Functions | Properties | Friends | Related Functions | List of all members
QMatrix4x4 Class Reference

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

#include <qmatrix4x4.h>

Public Functions

QVector4D column (int index) const
 Returns the elements of column index as a 4D vector. More...
 
const qrealconstData () const
 Returns a constant pointer to the raw data of this matrix. More...
 
void copyDataTo (qreal *values) const
 Retrieves the 16 items in this matrix and copies them to values in row-major order. More...
 
qrealdata ()
 Returns a pointer to the raw data of this matrix. More...
 
const qrealdata () const
 Returns a constant pointer to the raw data of this matrix. More...
 
qreal determinant () const
 Returns the determinant of this matrix. More...
 
void fill (qreal value)
 Fills all elements of this matrx with value. More...
 
void flipCoordinates ()
 Flips between right-handed and left-handed coordinate systems by multiplying the y and z co-ordinates by -1. More...
 
void 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. More...
 
QMatrix4x4 inverted (bool *invertible=0) const
 Returns the inverse of this matrix. More...
 
bool isIdentity () const
 Returns true if this matrix is the identity; false otherwise. More...
 
void lookAt (const QVector3D &eye, const QVector3D &center, const QVector3D &up)
 Multiplies this matrix by another that applies an eye position transformation. More...
 
QPoint map (const QPoint &point) const
 Maps point by multiplying this matrix by point. More...
 
QPointF map (const QPointF &point) const
 Maps point by multiplying this matrix by point. More...
 
QVector3D map (const QVector3D &point) const
 Maps point by multiplying this matrix by point. More...
 
QVector4D map (const QVector4D &point) const
 Maps point by multiplying this matrix by point. More...
 
QRect 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. More...
 
QRectF 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. More...
 
QVector3D mapVector (const QVector3D &vector) const
 Maps vector by multiplying the top 3x3 portion of this matrix by vector. More...
 
QMatrix3x3 normalMatrix () const
 Returns the normal matrix corresponding to this 4x4 transformation. More...
 
 operator QVariant () const
 Returns the matrix as a QVariant. More...
 
bool operator!= (const QMatrix4x4 &other) const
 Returns true if this matrix is not identical to other; false otherwise. More...
 
const qrealoperator() (int row, int column) const
 Returns a constant reference to the element at position (row, column) in this matrix. More...
 
qrealoperator() (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. More...
 
QMatrix4x4operator*= (const QMatrix4x4 &other)
 Multiplies the contents of other by this matrix. More...
 
QMatrix4x4operator*= (qreal factor)
 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. More...
 
QMatrix4x4operator+= (const QMatrix4x4 &other)
 Adds the contents of other to this matrix. More...
 
QMatrix4x4operator-= (const QMatrix4x4 &other)
 Subtracts the contents of other from this matrix. More...
 
QMatrix4x4operator/= (qreal divisor)
 Divides all elements of this matrix by divisor. More...
 
bool operator== (const QMatrix4x4 &other) const
 Returns true if this matrix is identical to other; false otherwise. More...
 
void optimize ()
 Optimize the usage of this matrix from its current elements. More...
 
void ortho (const QRect &rect)
 Multiplies this matrix by another that applies an orthographic projection for a window with boundaries specified by rect. More...
 
void ortho (const QRectF &rect)
 Multiplies this matrix by another that applies an orthographic projection for a window with boundaries specified by rect. More...
 
void 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. More...
 
void perspective (qreal angle, qreal aspect, qreal nearPlane, qreal farPlane)
 Multiplies this matrix by another that applies a perspective projection. More...
 
 QMatrix4x4 ()
 Constructs an identity matrix. More...
 
 QMatrix4x4 (const qreal *values)
 Constructs a matrix from the given 16 floating-point values. More...
 
 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. More...
 
template<int N, int M>
 QMatrix4x4 (const QGenericMatrix< N, M, qreal > &matrix)
 Constructs a 4x4 matrix from the left-most 4 columns and top-most 4 rows of matrix. More...
 
 QMatrix4x4 (const qreal *values, int cols, int rows)
 
 QMatrix4x4 (const QTransform &transform)
 Constructs a 4x4 matrix from the conventional Qt 2D transformation matrix transform. More...
 
 QMatrix4x4 (const QMatrix &matrix)
 Constructs a 4x4 matrix from a conventional Qt 2D affine transformation matrix. More...
 
template<int N, int M>
Q_INLINE_TEMPLATE QMatrix4x4 (const QGenericMatrix< N, M, qreal > &matrix)
 
void rotate (qreal angle, const QVector3D &vector)
 Multiples this matrix by another that rotates coordinates through angle degrees about vector. More...
 
void rotate (qreal angle, qreal x, qreal y, qreal z=0.0f)
 Multiplies this matrix by another that rotates coordinates through angle degrees about the vector (x, y, z). More...
 
void rotate (const QQuaternion &quaternion)
 Multiples this matrix by another that rotates coordinates according to a specified quaternion. More...
 
QVector4D row (int index) const
 Returns the elements of row index as a 4D vector. More...
 
void scale (const QVector3D &vector)
 Multiplies this matrix by another that scales coordinates by the components of vector. More...
 
void scale (qreal x, qreal y)
 Multiplies this matrix by another that scales coordinates by the components x, and y. More...
 
void scale (qreal x, qreal y, qreal z)
 Multiplies this matrix by another that scales coordinates by the components x, y, and z. More...
 
void scale (qreal factor)
 Multiplies this matrix by another that scales coordinates by the given factor. More...
 
void setColumn (int index, const QVector4D &value)
 Sets the elements of column index to the components of value. More...
 
void setRow (int index, const QVector4D &value)
 Sets the elements of row index to the components of value. More...
 
void setToIdentity ()
 Sets this matrix to the identity. More...
 
QMatrix toAffine () const
 Returns the conventional Qt 2D affine transformation matrix that corresponds to this matrix. More...
 
template<int N, int M>
QGenericMatrix< N, M, qrealtoGenericMatrix () const
 Constructs a NxM generic matrix from the left-most N columns and top-most M rows of this 4x4 matrix. More...
 
QTransform toTransform () const
 Returns the conventional Qt 2D transformation matrix that corresponds to this matrix. More...
 
QTransform toTransform (qreal distanceToPlane) const
 Returns the conventional Qt 2D transformation matrix that corresponds to this matrix. More...
 
void translate (const QVector3D &vector)
 Multiplies this matrix by another that translates coordinates by the components of vector. More...
 
void translate (qreal x, qreal y)
 Multiplies this matrix by another that translates coordinates by the components x, and y. More...
 
void translate (qreal x, qreal y, qreal z)
 Multiplies this matrix by another that translates coordinates by the components x, y, and z. More...
 
QMatrix4x4 transposed () const
 Returns this matrix, transposed about its diagonal. More...
 

Private Types

enum  {
  Identity = 0x0001, General = 0x0002, Translation = 0x0004, Scale = 0x0008,
  Rotation = 0x0010
}
 

Private Functions

QMatrix4x4 orthonormalInverse () const
 
void projectedRotate (qreal angle, qreal x, qreal y, qreal z)
 
 QMatrix4x4 (int)
 

Properties

int flagBits
 
qreal m [4][4]
 

Friends

QMatrix4x4 operator* (const QMatrix4x4 &m1, const QMatrix4x4 &m2)
 
QVector3D operator* (const QMatrix4x4 &matrix, const QVector3D &vector)
 
QVector3D operator* (const QVector3D &vector, const QMatrix4x4 &matrix)
 
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)
 
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)
 Returns the sum of m1 and m2. More...
 
QMatrix4x4 operator- (const QMatrix4x4 &m1, const QMatrix4x4 &m2)
 Returns the difference of m1 and m2. More...
 
QMatrix4x4 operator- (const QMatrix4x4 &matrix)
 Returns the negation of matrix. More...
 
Q_GUI_EXPORT QMatrix4x4 operator/ (const QMatrix4x4 &matrix, qreal divisor)
 Returns the result of dividing all elements of matrix by divisor. More...
 
Q_GUI_EXPORT QDebug operator<< (QDebug dbg, const QMatrix4x4 &m)
 
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. More...
 
class QGraphicsRotation
 

Related Functions

(Note that these are not member functions.)

QDataStreamoperator<< (QDataStream &stream, const QMatrix4x4 &matrix)
 Writes the given matrix to the given stream and returns a reference to the stream. More...
 
QDataStreamoperator>> (QDataStream &stream, QMatrix4x4 &matrix)
 Reads a 4x4 matrix from the given stream into the given matrix and returns a reference to the stream. More...
 
QGenericMatrix< N, M, qrealqGenericMatrixFromMatrix4x4 (const QMatrix4x4 &matrix)
 Returns a NxM generic matrix constructed from the left-most N columns and top-most M rows of matrix. More...
 
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. More...
 

Detailed Description

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

Since
4.6
See also
QVector3D, QGenericMatrix

Definition at line 63 of file qmatrix4x4.h.

Enumerations

◆ anonymous enum

anonymous enum
private
Enumerator
Identity 
General 
Translation 
Scale 
Rotation 

Definition at line 191 of file qmatrix4x4.h.

191  {
192  Identity = 0x0001, // Identity matrix
193  General = 0x0002, // General matrix, unknown contents
194  Translation = 0x0004, // Contains a simple translation
195  Scale = 0x0008, // Contains a simple scale
196  Rotation = 0x0010 // Contains a simple rotation
197  };
The Rotation object provides a way to rotate an Item.
The Scale element provides a way to scale an Item.

Constructors and Destructors

◆ QMatrix4x4() [1/9]

QMatrix4x4::QMatrix4x4 ( )
inline

Constructs an identity matrix.

Definition at line 66 of file qmatrix4x4.h.

Referenced by inverted(), and QMatrix4x4().

66 { setToIdentity(); }
void setToIdentity()
Sets this matrix to the identity.
Definition: qmatrix4x4.h:324

◆ QMatrix4x4() [2/9]

QMatrix4x4::QMatrix4x4 ( const qreal values)
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.

See also
copyDataTo(), optimize()

Definition at line 87 of file qmatrix4x4.cpp.

88 {
89  for (int row = 0; row < 4; ++row)
90  for (int col = 0; col < 4; ++col)
91  m[col][row] = values[row * 4 + col];
92  flagBits = General;
93 }
int flagBits
Definition: qmatrix4x4.h:189
QVector4D row(int index) const
Returns the elements of row index as a 4D vector.
Definition: qmatrix4x4.h:289
quint16 values[128]
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ QMatrix4x4() [3/9]

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

See also
optimize()

Definition at line 212 of file qmatrix4x4.h.

216 {
217  m[0][0] = m11; m[0][1] = m21; m[0][2] = m31; m[0][3] = m41;
218  m[1][0] = m12; m[1][1] = m22; m[1][2] = m32; m[1][3] = m42;
219  m[2][0] = m13; m[2][1] = m23; m[2][2] = m33; m[2][3] = m43;
220  m[3][0] = m14; m[3][1] = m24; m[3][2] = m34; m[3][3] = m44;
221  flagBits = General;
222 }
int flagBits
Definition: qmatrix4x4.h:189
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ QMatrix4x4() [4/9]

template<int N, int M>
QMatrix4x4::QMatrix4x4 ( const QGenericMatrix< N, M, qreal > &  matrix)
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.

See also
toGenericMatrix()

◆ QMatrix4x4() [5/9]

QMatrix4x4::QMatrix4x4 ( const qreal values,
int  cols,
int  rows 
)
Warning
This function is not part of the public interface.

Definition at line 175 of file qmatrix4x4.cpp.

176 {
177  for (int col = 0; col < 4; ++col) {
178  for (int row = 0; row < 4; ++row) {
179  if (col < cols && row < rows)
180  m[col][row] = values[col * rows + row];
181  else if (col == row)
182  m[col][row] = 1.0f;
183  else
184  m[col][row] = 0.0f;
185  }
186  }
187  flagBits = General;
188 }
int flagBits
Definition: qmatrix4x4.h:189
QVector4D row(int index) const
Returns the elements of row index as a 4D vector.
Definition: qmatrix4x4.h:289
quint16 values[128]
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ QMatrix4x4() [6/9]

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
toTransform(), optimize()

Definition at line 233 of file qmatrix4x4.cpp.

234 {
235  m[0][0] = transform.m11();
236  m[0][1] = transform.m12();
237  m[0][2] = 0.0f;
238  m[0][3] = transform.m13();
239  m[1][0] = transform.m21();
240  m[1][1] = transform.m22();
241  m[1][2] = 0.0f;
242  m[1][3] = transform.m23();
243  m[2][0] = 0.0f;
244  m[2][1] = 0.0f;
245  m[2][2] = 1.0f;
246  m[2][3] = 0.0f;
247  m[3][0] = transform.dx();
248  m[3][1] = transform.dy();
249  m[3][2] = 0.0f;
250  m[3][3] = transform.m33();
251  flagBits = General;
252 }
int flagBits
Definition: qmatrix4x4.h:189
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
qreal m21() const
Returns the horizontal shearing factor.
Definition: qtransform.h:249
qreal m22() const
Returns the vertical scaling factor.
Definition: qtransform.h:253
qreal m12() const
Returns the vertical shearing factor.
Definition: qtransform.h:241
qreal m[4][4]
Definition: qmatrix4x4.h:188
qreal m23() const
Returns the vertical projection factor.
Definition: qtransform.h:257
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273
qreal m13() const
Returns the horizontal projection factor.
Definition: qtransform.h:245
qreal m11() const
Returns the horizontal scaling factor.
Definition: qtransform.h:237
qreal m33() const
Returns the division factor.
Definition: qtransform.h:269

◆ QMatrix4x4() [7/9]

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

See also
toAffine(), optimize()

Definition at line 201 of file qmatrix4x4.cpp.

202 {
203  m[0][0] = matrix.m11();
204  m[0][1] = matrix.m12();
205  m[0][2] = 0.0f;
206  m[0][3] = 0.0f;
207  m[1][0] = matrix.m21();
208  m[1][1] = matrix.m22();
209  m[1][2] = 0.0f;
210  m[1][3] = 0.0f;
211  m[2][0] = 0.0f;
212  m[2][1] = 0.0f;
213  m[2][2] = 1.0f;
214  m[2][3] = 0.0f;
215  m[3][0] = matrix.dx();
216  m[3][1] = matrix.dy();
217  m[3][2] = 0.0f;
218  m[3][3] = 1.0f;
219  flagBits = General;
220 }
int flagBits
Definition: qmatrix4x4.h:189
qreal dx() const
Returns the horizontal translation factor.
Definition: qmatrix.h:77
qreal m12() const
Returns the vertical shearing factor.
Definition: qmatrix.h:74
qreal m11() const
Returns the horizontal scaling factor.
Definition: qmatrix.h:73
qreal m21() const
Returns the horizontal shearing factor.
Definition: qmatrix.h:75
qreal m[4][4]
Definition: qmatrix4x4.h:188
qreal dy() const
Returns the vertical translation factor.
Definition: qmatrix.h:78
qreal m22() const
Returns the vertical scaling factor.
Definition: qmatrix.h:76

◆ QMatrix4x4() [8/9]

QMatrix4x4::QMatrix4x4 ( int  )
inlineprivate

Definition at line 200 of file qmatrix4x4.h.

◆ QMatrix4x4() [9/9]

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

Definition at line 226 of file qmatrix4x4.h.

227 {
228  const qreal *values = matrix.constData();
229  for (int matrixCol = 0; matrixCol < 4; ++matrixCol) {
230  for (int matrixRow = 0; matrixRow < 4; ++matrixRow) {
231  if (matrixCol < N && matrixRow < M)
232  m[matrixCol][matrixRow] = values[matrixCol * M + matrixRow];
233  else if (matrixCol == matrixRow)
234  m[matrixCol][matrixRow] = 1.0f;
235  else
236  m[matrixCol][matrixRow] = 0.0f;
237  }
238  }
239  flagBits = General;
240 }
const T * constData() const
Returns a constant pointer to the raw data of this matrix.
int flagBits
Definition: qmatrix4x4.h:189
double qreal
Definition: qglobal.h:1193
#define M(row, col)
quint16 values[128]
qreal m[4][4]
Definition: qmatrix4x4.h:188

Functions

◆ column()

QVector4D QMatrix4x4::column ( int  index) const
inline

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

See also
setColumn(), row()

Definition at line 273 of file qmatrix4x4.h.

274 {
275  Q_ASSERT(index >= 0 && index < 4);
276  return QVector4D(m[index][0], m[index][1], m[index][2], m[index][3]);
277 }
The QVector4D class represents a vector or vertex in 4D space.
Definition: qvector4d.h:60
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
qreal m[4][4]
Definition: qmatrix4x4.h:188
quint16 index

◆ constData()

const qreal * QMatrix4x4::constData ( ) const
inline

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

See also
data()

Definition at line 177 of file qmatrix4x4.h.

Referenced by qGenericMatrixFromMatrix4x4().

177 { return *m; }
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ copyDataTo()

void QMatrix4x4::copyDataTo ( qreal values) const

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

Definition at line 1599 of file qmatrix4x4.cpp.

1600 {
1601  for (int row = 0; row < 4; ++row)
1602  for (int col = 0; col < 4; ++col)
1603  values[row * 4 + col] = qreal(m[col][row]);
1604 }
double qreal
Definition: qglobal.h:1193
QVector4D row(int index) const
Returns the elements of row index as a 4D vector.
Definition: qmatrix4x4.h:289
quint16 values[128]
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ data() [1/2]

qreal * QMatrix4x4::data ( )
inline

Returns a pointer to the raw data of this matrix.

See also
constData(), optimize()

Definition at line 972 of file qmatrix4x4.h.

973 {
974  // We have to assume that the caller will modify the matrix elements,
975  // so we flip it over to "General" mode.
976  flagBits = General;
977  return *m;
978 }
int flagBits
Definition: qmatrix4x4.h:189
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ data() [2/2]

const qreal * QMatrix4x4::data ( ) const
inline

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

See also
constData()

Definition at line 176 of file qmatrix4x4.h.

176 { return *m; }
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ determinant()

qreal QMatrix4x4::determinant ( ) const

Returns the determinant of this matrix.

Definition at line 391 of file qmatrix4x4.cpp.

392 {
393  return qreal(matrixDet4(m));
394 }
double qreal
Definition: qglobal.h:1193
qreal m[4][4]
Definition: qmatrix4x4.h:188
static qreal matrixDet4(const qreal m[4][4])
Definition: qmatrix4x4.cpp:378

◆ fill()

void QMatrix4x4::fill ( qreal  value)
inline

Fills all elements of this matrx with value.

Definition at line 345 of file qmatrix4x4.h.

346 {
347  m[0][0] = value;
348  m[0][1] = value;
349  m[0][2] = value;
350  m[0][3] = value;
351  m[1][0] = value;
352  m[1][1] = value;
353  m[1][2] = value;
354  m[1][3] = value;
355  m[2][0] = value;
356  m[2][1] = value;
357  m[2][2] = value;
358  m[2][3] = value;
359  m[3][0] = value;
360  m[3][1] = value;
361  m[3][2] = value;
362  m[3][3] = value;
363  flagBits = General;
364 }
int flagBits
Definition: qmatrix4x4.h:189
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ flipCoordinates()

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

See also
ortho()

Definition at line 1569 of file qmatrix4x4.cpp.

1570 {
1571  if (flagBits == Scale || flagBits == (Scale | Translation)) {
1572  m[1][1] = -m[1][1];
1573  m[2][2] = -m[2][2];
1574  } else if (flagBits == Translation) {
1575  m[1][1] = -m[1][1];
1576  m[2][2] = -m[2][2];
1577  flagBits |= Scale;
1578  } else if (flagBits == Identity) {
1579  m[1][1] = -1.0f;
1580  m[2][2] = -1.0f;
1581  flagBits = Scale;
1582  } else {
1583  m[1][0] = -m[1][0];
1584  m[1][1] = -m[1][1];
1585  m[1][2] = -m[1][2];
1586  m[1][3] = -m[1][3];
1587  m[2][0] = -m[2][0];
1588  m[2][1] = -m[2][1];
1589  m[2][2] = -m[2][2];
1590  m[2][3] = -m[2][3];
1591  flagBits = General;
1592  }
1593 }
int flagBits
Definition: qmatrix4x4.h:189
qreal m[4][4]
Definition: qmatrix4x4.h:188
The Scale element provides a way to scale an Item.

◆ frustum()

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

See also
ortho(), perspective()

Definition at line 1447 of file qmatrix4x4.cpp.

1448 {
1449  // Bail out if the projection volume is zero-sized.
1450  if (left == right || bottom == top || nearPlane == farPlane)
1451  return;
1452 
1453  // Construct the projection.
1454  QMatrix4x4 m(1);
1455  qreal width = right - left;
1456  qreal invheight = top - bottom;
1457  qreal clip = farPlane - nearPlane;
1458  m.m[0][0] = 2.0f * nearPlane / width;
1459  m.m[1][0] = 0.0f;
1460  m.m[2][0] = (left + right) / width;
1461  m.m[3][0] = 0.0f;
1462  m.m[0][1] = 0.0f;
1463  m.m[1][1] = 2.0f * nearPlane / invheight;
1464  m.m[2][1] = (top + bottom) / invheight;
1465  m.m[3][1] = 0.0f;
1466  m.m[0][2] = 0.0f;
1467  m.m[1][2] = 0.0f;
1468  m.m[2][2] = -(nearPlane + farPlane) / clip;
1469  m.m[3][2] = -2.0f * nearPlane * farPlane / clip;
1470  m.m[0][3] = 0.0f;
1471  m.m[1][3] = 0.0f;
1472  m.m[2][3] = -1.0f;
1473  m.m[3][3] = 0.0f;
1474 
1475  // Apply the projection.
1476  *this *= m;
1477 }
double qreal
Definition: qglobal.h:1193
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:63
qreal m[4][4]
Definition: qmatrix4x4.h:188
Q_CORE_EXPORT QTextStream & left(QTextStream &s)

◆ inverted()

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(), normalMatrix()

Definition at line 408 of file qmatrix4x4.cpp.

409 {
410  // Handle some of the easy cases first.
411  if (flagBits == Identity) {
412  if (invertible)
413  *invertible = true;
414  return QMatrix4x4();
415  } else if (flagBits == Translation) {
416  QMatrix4x4 inv;
417  inv.m[3][0] = -m[3][0];
418  inv.m[3][1] = -m[3][1];
419  inv.m[3][2] = -m[3][2];
420  inv.flagBits = Translation;
421  if (invertible)
422  *invertible = true;
423  return inv;
424  } else if (flagBits == Rotation || flagBits == (Rotation | Translation)) {
425  if (invertible)
426  *invertible = true;
427  return orthonormalInverse();
428  }
429 
430  QMatrix4x4 inv(1); // The "1" says to not load the identity.
431 
432  qreal det = matrixDet4(m);
433  if (det == 0.0f) {
434  if (invertible)
435  *invertible = false;
436  return QMatrix4x4();
437  }
438  det = 1.0f / det;
439 
440  inv.m[0][0] = matrixDet3(m, 1, 2, 3, 1, 2, 3) * det;
441  inv.m[0][1] = -matrixDet3(m, 0, 2, 3, 1, 2, 3) * det;
442  inv.m[0][2] = matrixDet3(m, 0, 1, 3, 1, 2, 3) * det;
443  inv.m[0][3] = -matrixDet3(m, 0, 1, 2, 1, 2, 3) * det;
444  inv.m[1][0] = -matrixDet3(m, 1, 2, 3, 0, 2, 3) * det;
445  inv.m[1][1] = matrixDet3(m, 0, 2, 3, 0, 2, 3) * det;
446  inv.m[1][2] = -matrixDet3(m, 0, 1, 3, 0, 2, 3) * det;
447  inv.m[1][3] = matrixDet3(m, 0, 1, 2, 0, 2, 3) * det;
448  inv.m[2][0] = matrixDet3(m, 1, 2, 3, 0, 1, 3) * det;
449  inv.m[2][1] = -matrixDet3(m, 0, 2, 3, 0, 1, 3) * det;
450  inv.m[2][2] = matrixDet3(m, 0, 1, 3, 0, 1, 3) * det;
451  inv.m[2][3] = -matrixDet3(m, 0, 1, 2, 0, 1, 3) * det;
452  inv.m[3][0] = -matrixDet3(m, 1, 2, 3, 0, 1, 2) * det;
453  inv.m[3][1] = matrixDet3(m, 0, 2, 3, 0, 1, 2) * det;
454  inv.m[3][2] = -matrixDet3(m, 0, 1, 3, 0, 1, 2) * det;
455  inv.m[3][3] = matrixDet3(m, 0, 1, 2, 0, 1, 2) * det;
456 
457  if (invertible)
458  *invertible = true;
459  return inv;
460 }
int flagBits
Definition: qmatrix4x4.h:189
double qreal
Definition: qglobal.h:1193
QMatrix4x4()
Constructs an identity matrix.
Definition: qmatrix4x4.h:66
static const uchar inv
Definition: qisciicodec.cpp:91
The Rotation object provides a way to rotate an Item.
QMatrix4x4 orthonormalInverse() const
static qreal matrixDet3(const qreal m[4][4], int col0, int col1, int col2, int row0, int row1, int row2)
Definition: qmatrix4x4.cpp:363
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:63
qreal m[4][4]
Definition: qmatrix4x4.h:188
static qreal matrixDet4(const qreal m[4][4])
Definition: qmatrix4x4.cpp:378

◆ isIdentity()

bool QMatrix4x4::isIdentity ( ) const
inline

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

See also
setToIdentity()

Definition at line 307 of file qmatrix4x4.h.

308 {
309  if (flagBits == Identity)
310  return true;
311  if (m[0][0] != 1.0f || m[0][1] != 0.0f || m[0][2] != 0.0f)
312  return false;
313  if (m[0][3] != 0.0f || m[1][0] != 0.0f || m[1][1] != 1.0f)
314  return false;
315  if (m[1][2] != 0.0f || m[1][3] != 0.0f || m[2][0] != 0.0f)
316  return false;
317  if (m[2][1] != 0.0f || m[2][2] != 1.0f || m[2][3] != 0.0f)
318  return false;
319  if (m[3][0] != 0.0f || m[3][1] != 0.0f || m[3][2] != 0.0f)
320  return false;
321  return (m[3][3] == 1.0f);
322 }
int flagBits
Definition: qmatrix4x4.h:189
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ lookAt()

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

Definition at line 1530 of file qmatrix4x4.cpp.

1531 {
1532  QVector3D forward = (center - eye).normalized();
1533  QVector3D side = QVector3D::crossProduct(forward, up).normalized();
1534  QVector3D upVector = QVector3D::crossProduct(side, forward);
1535 
1536  QMatrix4x4 m(1);
1537 
1538  m.m[0][0] = side.x();
1539  m.m[1][0] = side.y();
1540  m.m[2][0] = side.z();
1541  m.m[3][0] = 0.0f;
1542  m.m[0][1] = upVector.x();
1543  m.m[1][1] = upVector.y();
1544  m.m[2][1] = upVector.z();
1545  m.m[3][1] = 0.0f;
1546  m.m[0][2] = -forward.x();
1547  m.m[1][2] = -forward.y();
1548  m.m[2][2] = -forward.z();
1549  m.m[3][2] = 0.0f;
1550  m.m[0][3] = 0.0f;
1551  m.m[1][3] = 0.0f;
1552  m.m[2][3] = 0.0f;
1553  m.m[3][3] = 1.0f;
1554 
1555  *this *= m;
1556  translate(-eye);
1557 }
void translate(const QVector3D &vector)
Multiplies this matrix by another that translates coordinates by the components of vector...
Definition: qmatrix4x4.cpp:944
The QVector3D class represents a vector or vertex in 3D space.
Definition: qvector3d.h:60
qreal x() const
Returns the x coordinate of this point.
Definition: qvector3d.h:161
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:63
QVector3D normalized() const
Returns the normalized unit vector form of this vector.
Definition: qvector3d.cpp:247
qreal z() const
Returns the z coordinate of this point.
Definition: qvector3d.h:163
qreal m[4][4]
Definition: qmatrix4x4.h:188
qreal y() const
Returns the y coordinate of this point.
Definition: qvector3d.h:162
static QVector3D crossProduct(const QVector3D &v1, const QVector3D &v2)
Returns the cross-product of vectors v1 and v2, which corresponds to the normal vector of a plane def...
Definition: qvector3d.cpp:352

◆ map() [1/4]

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

Maps point by multiplying this matrix by point.

See also
mapRect()

Definition at line 923 of file qmatrix4x4.h.

Referenced by mapRect().

924 {
925  return *this * point;
926 }

◆ map() [2/4]

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

Maps point by multiplying this matrix by point.

See also
mapRect()

Definition at line 928 of file qmatrix4x4.h.

929 {
930  return *this * point;
931 }

◆ map() [3/4]

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

Maps point by multiplying this matrix by point.

See also
mapRect(), mapVector()

Definition at line 935 of file qmatrix4x4.h.

936 {
937  return *this * point;
938 }

◆ map() [4/4]

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

Maps point by multiplying this matrix by point.

See also
mapRect()

Definition at line 965 of file qmatrix4x4.h.

966 {
967  return *this * point;
968 }

◆ mapRect() [1/2]

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

Definition at line 1758 of file qmatrix4x4.cpp.

1759 {
1760  if (flagBits == (Translation | Scale) || flagBits == Scale) {
1761  qreal x = rect.x() * m[0][0] + m[3][0];
1762  qreal y = rect.y() * m[1][1] + m[3][1];
1763  qreal w = rect.width() * m[0][0];
1764  qreal h = rect.height() * m[1][1];
1765  if (w < 0) {
1766  w = -w;
1767  x -= w;
1768  }
1769  if (h < 0) {
1770  h = -h;
1771  y -= h;
1772  }
1773  return QRect(qRound(x), qRound(y), qRound(w), qRound(h));
1774  } else if (flagBits == Translation) {
1775  return QRect(qRound(rect.x() + m[3][0]),
1776  qRound(rect.y() + m[3][1]),
1777  rect.width(), rect.height());
1778  }
1779 
1780  QPoint tl = map(rect.topLeft());
1781  QPoint tr = map(QPoint(rect.x() + rect.width(), rect.y()));
1782  QPoint bl = map(QPoint(rect.x(), rect.y() + rect.height()));
1783  QPoint br = map(QPoint(rect.x() + rect.width(),
1784  rect.y() + rect.height()));
1785 
1786  int xmin = qMin(qMin(tl.x(), tr.x()), qMin(bl.x(), br.x()));
1787  int xmax = qMax(qMax(tl.x(), tr.x()), qMax(bl.x(), br.x()));
1788  int ymin = qMin(qMin(tl.y(), tr.y()), qMin(bl.y(), br.y()));
1789  int ymax = qMax(qMax(tl.y(), tr.y()), qMax(bl.y(), br.y()));
1790 
1791  return QRect(xmin, ymin, xmax - xmin, ymax - ymin);
1792 }
int flagBits
Definition: qmatrix4x4.h:189
double qreal
Definition: qglobal.h:1193
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
QPoint map(const QPoint &point) const
Maps point by multiplying this matrix by point.
Definition: qmatrix4x4.h:923
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
qreal m[4][4]
Definition: qmatrix4x4.h:188
The Scale element provides a way to scale an Item.
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288

◆ mapRect() [2/2]

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

Definition at line 1802 of file qmatrix4x4.cpp.

1803 {
1804  if (flagBits == (Translation | Scale) || flagBits == Scale) {
1805  qreal x = rect.x() * m[0][0] + m[3][0];
1806  qreal y = rect.y() * m[1][1] + m[3][1];
1807  qreal w = rect.width() * m[0][0];
1808  qreal h = rect.height() * m[1][1];
1809  if (w < 0) {
1810  w = -w;
1811  x -= w;
1812  }
1813  if (h < 0) {
1814  h = -h;
1815  y -= h;
1816  }
1817  return QRectF(x, y, w, h);
1818  } else if (flagBits == Translation) {
1819  return rect.translated(m[3][0], m[3][1]);
1820  }
1821 
1822  QPointF tl = map(rect.topLeft()); QPointF tr = map(rect.topRight());
1823  QPointF bl = map(rect.bottomLeft()); QPointF br = map(rect.bottomRight());
1824 
1825  qreal xmin = qMin(qMin(tl.x(), tr.x()), qMin(bl.x(), br.x()));
1826  qreal xmax = qMax(qMax(tl.x(), tr.x()), qMax(bl.x(), br.x()));
1827  qreal ymin = qMin(qMin(tl.y(), tr.y()), qMin(bl.y(), br.y()));
1828  qreal ymax = qMax(qMax(tl.y(), tr.y()), qMax(bl.y(), br.y()));
1829 
1830  return QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax));
1831 }
QPointF bottomRight() const
Returns the position of the rectangle&#39;s bottom-right corner.
Definition: qrect.h:540
int flagBits
Definition: qmatrix4x4.h:189
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
double qreal
Definition: qglobal.h:1193
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QPointF topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:539
QPointF bottomLeft() const
Returns the position of the rectangle&#39;s bottom-left corner.
Definition: qrect.h:542
QPoint map(const QPoint &point) const
Maps point by multiplying this matrix by point.
Definition: qmatrix4x4.h:923
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
qreal m[4][4]
Definition: qmatrix4x4.h:188
The Scale element provides a way to scale an Item.
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
QRectF translated(qreal dx, qreal dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:740
QPointF topRight() const
Returns the position of the rectangle&#39;s top-right corner.
Definition: qrect.h:541

◆ mapVector()

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

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

Definition at line 940 of file qmatrix4x4.h.

941 {
942  if (flagBits == Identity || flagBits == Translation) {
943  return vector;
944  } else if (flagBits == Scale || flagBits == (Translation | Scale)) {
945  return QVector3D(vector.x() * m[0][0],
946  vector.y() * m[1][1],
947  vector.z() * m[2][2]);
948  } else {
949  return QVector3D(vector.x() * m[0][0] +
950  vector.y() * m[1][0] +
951  vector.z() * m[2][0],
952  vector.x() * m[0][1] +
953  vector.y() * m[1][1] +
954  vector.z() * m[2][1],
955  vector.x() * m[0][2] +
956  vector.y() * m[1][2] +
957  vector.z() * m[2][2]);
958  }
959 }
int flagBits
Definition: qmatrix4x4.h:189
The QVector3D class represents a vector or vertex in 3D space.
Definition: qvector3d.h:60
qreal x() const
Returns the x coordinate of this point.
Definition: qvector3d.h:161
qreal z() const
Returns the z coordinate of this point.
Definition: qvector3d.h:163
qreal m[4][4]
Definition: qmatrix4x4.h:188
The Scale element provides a way to scale an Item.
qreal y() const
Returns the y coordinate of this point.
Definition: qvector3d.h:162

◆ normalMatrix()

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

Definition at line 470 of file qmatrix4x4.cpp.

471 {
472  QMatrix3x3 inv;
473 
474  // Handle the simple cases first.
475  if (flagBits == Identity || flagBits == Translation) {
476  return inv;
477  } else if (flagBits == Scale || flagBits == (Translation | Scale)) {
478  if (m[0][0] == 0.0f || m[1][1] == 0.0f || m[2][2] == 0.0f)
479  return inv;
480  inv.data()[0] = 1.0f / m[0][0];
481  inv.data()[4] = 1.0f / m[1][1];
482  inv.data()[8] = 1.0f / m[2][2];
483  return inv;
484  }
485 
486  qreal det = matrixDet3(m, 0, 1, 2, 0, 1, 2);
487  if (det == 0.0f)
488  return inv;
489  det = 1.0f / det;
490 
491  qreal *invm = inv.data();
492 
493  // Invert and transpose in a single step.
494  invm[0 + 0 * 3] = (m[1][1] * m[2][2] - m[2][1] * m[1][2]) * det;
495  invm[1 + 0 * 3] = -(m[1][0] * m[2][2] - m[1][2] * m[2][0]) * det;
496  invm[2 + 0 * 3] = (m[1][0] * m[2][1] - m[1][1] * m[2][0]) * det;
497  invm[0 + 1 * 3] = -(m[0][1] * m[2][2] - m[2][1] * m[0][2]) * det;
498  invm[1 + 1 * 3] = (m[0][0] * m[2][2] - m[0][2] * m[2][0]) * det;
499  invm[2 + 1 * 3] = -(m[0][0] * m[2][1] - m[0][1] * m[2][0]) * det;
500  invm[0 + 2 * 3] = (m[0][1] * m[1][2] - m[0][2] * m[1][1]) * det;
501  invm[1 + 2 * 3] = -(m[0][0] * m[1][2] - m[0][2] * m[1][0]) * det;
502  invm[2 + 2 * 3] = (m[0][0] * m[1][1] - m[1][0] * m[0][1]) * det;
503 
504  return inv;
505 }
T * data()
Returns a pointer to the raw data of this matrix.
int flagBits
Definition: qmatrix4x4.h:189
double qreal
Definition: qglobal.h:1193
The QGenericMatrix class is a template class that represents a NxM transformation matrix with N colum...
static const uchar inv
Definition: qisciicodec.cpp:91
static qreal matrixDet3(const qreal m[4][4], int col0, int col1, int col2, int row0, int row1, int row2)
Definition: qmatrix4x4.cpp:363
qreal m[4][4]
Definition: qmatrix4x4.h:188
The Scale element provides a way to scale an Item.

◆ operator QVariant()

QMatrix4x4::operator QVariant ( ) const

Returns the matrix as a QVariant.

Definition at line 1948 of file qmatrix4x4.cpp.

1949 {
1950  return QVariant(QVariant::Matrix4x4, this);
1951 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92

◆ operator!=()

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

Returns true if this matrix is not identical to other; false otherwise.

This operator uses an exact floating-point comparison.

Definition at line 465 of file qmatrix4x4.h.

466 {
467  return m[0][0] != other.m[0][0] ||
468  m[0][1] != other.m[0][1] ||
469  m[0][2] != other.m[0][2] ||
470  m[0][3] != other.m[0][3] ||
471  m[1][0] != other.m[1][0] ||
472  m[1][1] != other.m[1][1] ||
473  m[1][2] != other.m[1][2] ||
474  m[1][3] != other.m[1][3] ||
475  m[2][0] != other.m[2][0] ||
476  m[2][1] != other.m[2][1] ||
477  m[2][2] != other.m[2][2] ||
478  m[2][3] != other.m[2][3] ||
479  m[3][0] != other.m[3][0] ||
480  m[3][1] != other.m[3][1] ||
481  m[3][2] != other.m[3][2] ||
482  m[3][3] != other.m[3][3];
483 }
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ operator()() [1/2]

const qreal & QMatrix4x4::operator() ( int  row,
int  column 
) const
inline

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

See also
column(), row()

Definition at line 260 of file qmatrix4x4.h.

261 {
262  Q_ASSERT(aRow >= 0 && aRow < 4 && aColumn >= 0 && aColumn < 4);
263  return m[aColumn][aRow];
264 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ operator()() [2/2]

qreal & QMatrix4x4::operator() ( int  row,
int  column 
)
inline

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

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

Definition at line 266 of file qmatrix4x4.h.

267 {
268  Q_ASSERT(aRow >= 0 && aRow < 4 && aColumn >= 0 && aColumn < 4);
269  flagBits = General;
270  return m[aColumn][aRow];
271 }
int flagBits
Definition: qmatrix4x4.h:189
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ operator*=() [1/2]

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

Multiplies the contents of other by this matrix.

Definition at line 410 of file qmatrix4x4.h.

411 {
412  if (flagBits == Identity) {
413  *this = other;
414  return *this;
415  } else if (other.flagBits == Identity) {
416  return *this;
417  } else {
418  *this = *this * other;
419  return *this;
420  }
421 }
int flagBits
Definition: qmatrix4x4.h:189

◆ operator*=() [2/2]

QMatrix4x4 & QMatrix4x4::operator*= ( qreal  factor)
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 423 of file qmatrix4x4.h.

424 {
425  m[0][0] *= factor;
426  m[0][1] *= factor;
427  m[0][2] *= factor;
428  m[0][3] *= factor;
429  m[1][0] *= factor;
430  m[1][1] *= factor;
431  m[1][2] *= factor;
432  m[1][3] *= factor;
433  m[2][0] *= factor;
434  m[2][1] *= factor;
435  m[2][2] *= factor;
436  m[2][3] *= factor;
437  m[3][0] *= factor;
438  m[3][1] *= factor;
439  m[3][2] *= factor;
440  m[3][3] *= factor;
441  flagBits = General;
442  return *this;
443 }
int flagBits
Definition: qmatrix4x4.h:189
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ operator+=()

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

Adds the contents of other to this matrix.

Definition at line 366 of file qmatrix4x4.h.

367 {
368  m[0][0] += other.m[0][0];
369  m[0][1] += other.m[0][1];
370  m[0][2] += other.m[0][2];
371  m[0][3] += other.m[0][3];
372  m[1][0] += other.m[1][0];
373  m[1][1] += other.m[1][1];
374  m[1][2] += other.m[1][2];
375  m[1][3] += other.m[1][3];
376  m[2][0] += other.m[2][0];
377  m[2][1] += other.m[2][1];
378  m[2][2] += other.m[2][2];
379  m[2][3] += other.m[2][3];
380  m[3][0] += other.m[3][0];
381  m[3][1] += other.m[3][1];
382  m[3][2] += other.m[3][2];
383  m[3][3] += other.m[3][3];
384  flagBits = General;
385  return *this;
386 }
int flagBits
Definition: qmatrix4x4.h:189
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ operator-=()

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

Subtracts the contents of other from this matrix.

Definition at line 388 of file qmatrix4x4.h.

389 {
390  m[0][0] -= other.m[0][0];
391  m[0][1] -= other.m[0][1];
392  m[0][2] -= other.m[0][2];
393  m[0][3] -= other.m[0][3];
394  m[1][0] -= other.m[1][0];
395  m[1][1] -= other.m[1][1];
396  m[1][2] -= other.m[1][2];
397  m[1][3] -= other.m[1][3];
398  m[2][0] -= other.m[2][0];
399  m[2][1] -= other.m[2][1];
400  m[2][2] -= other.m[2][2];
401  m[2][3] -= other.m[2][3];
402  m[3][0] -= other.m[3][0];
403  m[3][1] -= other.m[3][1];
404  m[3][2] -= other.m[3][2];
405  m[3][3] -= other.m[3][3];
406  flagBits = General;
407  return *this;
408 }
int flagBits
Definition: qmatrix4x4.h:189
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ operator/=()

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

Divides all elements of this matrix by divisor.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 560 of file qmatrix4x4.cpp.

561 {
562  m[0][0] /= divisor;
563  m[0][1] /= divisor;
564  m[0][2] /= divisor;
565  m[0][3] /= divisor;
566  m[1][0] /= divisor;
567  m[1][1] /= divisor;
568  m[1][2] /= divisor;
569  m[1][3] /= divisor;
570  m[2][0] /= divisor;
571  m[2][1] /= divisor;
572  m[2][2] /= divisor;
573  m[2][3] /= divisor;
574  m[3][0] /= divisor;
575  m[3][1] /= divisor;
576  m[3][2] /= divisor;
577  m[3][3] /= divisor;
578  flagBits = General;
579  return *this;
580 }
int flagBits
Definition: qmatrix4x4.h:189
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ operator==()

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

Returns true if this matrix is identical to other; false otherwise.

This operator uses an exact floating-point comparison.

Definition at line 445 of file qmatrix4x4.h.

446 {
447  return m[0][0] == other.m[0][0] &&
448  m[0][1] == other.m[0][1] &&
449  m[0][2] == other.m[0][2] &&
450  m[0][3] == other.m[0][3] &&
451  m[1][0] == other.m[1][0] &&
452  m[1][1] == other.m[1][1] &&
453  m[1][2] == other.m[1][2] &&
454  m[1][3] == other.m[1][3] &&
455  m[2][0] == other.m[2][0] &&
456  m[2][1] == other.m[2][1] &&
457  m[2][2] == other.m[2][2] &&
458  m[2][3] == other.m[2][3] &&
459  m[3][0] == other.m[3][0] &&
460  m[3][1] == other.m[3][1] &&
461  m[3][2] == other.m[3][2] &&
462  m[3][3] == other.m[3][3];
463 }
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ optimize()

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()() 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
operator()(), data(), translate()

Definition at line 1907 of file qmatrix4x4.cpp.

Referenced by operator>>().

1908 {
1909  // If the last element is not 1, then it can never be special.
1910  if (m[3][3] != 1.0f) {
1911  flagBits = General;
1912  return;
1913  }
1914 
1915  // If the upper three elements m12, m13, and m21 are not all zero,
1916  // or the lower elements below the diagonal are not all zero, then
1917  // the matrix can never be special.
1918  if (m[1][0] != 0.0f || m[2][0] != 0.0f || m[2][1] != 0.0f) {
1919  flagBits = General;
1920  return;
1921  }
1922  if (m[0][1] != 0.0f || m[0][2] != 0.0f || m[0][3] != 0.0f ||
1923  m[1][2] != 0.0f || m[1][3] != 0.0f || m[2][3] != 0.0f) {
1924  flagBits = General;
1925  return;
1926  }
1927 
1928  // Determine what we have in the remaining regions of the matrix.
1929  bool identityAlongDiagonal
1930  = (m[0][0] == 1.0f && m[1][1] == 1.0f && m[2][2] == 1.0f);
1931  bool translationPresent
1932  = (m[3][0] != 0.0f || m[3][1] != 0.0f || m[3][2] != 0.0f);
1933 
1934  // Now determine the special matrix type.
1935  if (translationPresent && identityAlongDiagonal)
1937  else if (translationPresent)
1938  flagBits = (Translation | Scale);
1939  else if (identityAlongDiagonal)
1940  flagBits = Identity;
1941  else
1942  flagBits = Scale;
1943 }
int flagBits
Definition: qmatrix4x4.h:189
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ ortho() [1/3]

void QMatrix4x4::ortho ( const QRect rect)

Multiplies this matrix by another that applies an orthographic projection for a window with boundaries specified by rect.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

The near and far clipping planes will be -1 and 1 respectively.

See also
frustum(), perspective()

Definition at line 1356 of file qmatrix4x4.cpp.

Referenced by ortho().

1357 {
1358  // Note: rect.right() and rect.bottom() subtract 1 in QRect,
1359  // which gives the location of a pixel within the rectangle,
1360  // instead of the extent of the rectangle. We want the extent.
1361  // QRectF expresses the extent properly.
1362  ortho(rect.x(), rect.x() + rect.width(), rect.y() + rect.height(), rect.y(), -1.0f, 1.0f);
1363 }
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
void ortho(const QRect &rect)
Multiplies this matrix by another that applies an orthographic projection for a window with boundarie...

◆ ortho() [2/3]

void QMatrix4x4::ortho ( const QRectF rect)

Multiplies this matrix by another that applies an orthographic projection for a window with boundaries specified by rect.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

The near and far clipping planes will be -1 and 1 respectively.

See also
frustum(), perspective()

Definition at line 1377 of file qmatrix4x4.cpp.

1378 {
1379  ortho(rect.left(), rect.right(), rect.bottom(), rect.top(), -1.0f, 1.0f);
1380 }
qreal right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:527
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
void ortho(const QRect &rect)
Multiplies this matrix by another that applies an orthographic projection for a window with boundarie...
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528

◆ ortho() [3/3]

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

See also
frustum(), perspective()

Definition at line 1390 of file qmatrix4x4.cpp.

1391 {
1392  // Bail out if the projection volume is zero-sized.
1393  if (left == right || bottom == top || nearPlane == farPlane)
1394  return;
1395 
1396  // Construct the projection.
1397  qreal width = right - left;
1398  qreal invheight = top - bottom;
1399  qreal clip = farPlane - nearPlane;
1400 #ifndef QT_NO_VECTOR3D
1401  if (clip == 2.0f && (nearPlane + farPlane) == 0.0f) {
1402  // We can express this projection as a translate and scale
1403  // which will be more efficient to modify with further
1404  // transformations than producing a "General" matrix.
1406  (-(left + right) / width,
1407  -(top + bottom) / invheight,
1408  0.0f));
1410  (2.0f / width,
1411  2.0f / invheight,
1412  -1.0f));
1413  return;
1414  }
1415 #endif
1416  QMatrix4x4 m(1);
1417  m.m[0][0] = 2.0f / width;
1418  m.m[1][0] = 0.0f;
1419  m.m[2][0] = 0.0f;
1420  m.m[3][0] = -(left + right) / width;
1421  m.m[0][1] = 0.0f;
1422  m.m[1][1] = 2.0f / invheight;
1423  m.m[2][1] = 0.0f;
1424  m.m[3][1] = -(top + bottom) / invheight;
1425  m.m[0][2] = 0.0f;
1426  m.m[1][2] = 0.0f;
1427  m.m[2][2] = -2.0f / clip;
1428  m.m[3][2] = -(nearPlane + farPlane) / clip;
1429  m.m[0][3] = 0.0f;
1430  m.m[1][3] = 0.0f;
1431  m.m[2][3] = 0.0f;
1432  m.m[3][3] = 1.0f;
1433 
1434  // Apply the projection.
1435  *this *= m;
1436  return;
1437 }
void translate(const QVector3D &vector)
Multiplies this matrix by another that translates coordinates by the components of vector...
Definition: qmatrix4x4.cpp:944
The QVector3D class represents a vector or vertex in 3D space.
Definition: qvector3d.h:60
double qreal
Definition: qglobal.h:1193
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:63
qreal m[4][4]
Definition: qmatrix4x4.h:188
void scale(const QVector3D &vector)
Multiplies this matrix by another that scales coordinates by the components of vector.
Definition: qmatrix4x4.cpp:775
Q_CORE_EXPORT QTextStream & left(QTextStream &s)

◆ orthonormalInverse()

QMatrix4x4 QMatrix4x4::orthonormalInverse ( ) const
private

Definition at line 1859 of file qmatrix4x4.cpp.

Referenced by inverted().

1860 {
1861  QMatrix4x4 result(1); // The '1' says not to load identity
1862 
1863  result.m[0][0] = m[0][0];
1864  result.m[1][0] = m[0][1];
1865  result.m[2][0] = m[0][2];
1866 
1867  result.m[0][1] = m[1][0];
1868  result.m[1][1] = m[1][1];
1869  result.m[2][1] = m[1][2];
1870 
1871  result.m[0][2] = m[2][0];
1872  result.m[1][2] = m[2][1];
1873  result.m[2][2] = m[2][2];
1874 
1875  result.m[0][3] = 0.0f;
1876  result.m[1][3] = 0.0f;
1877  result.m[2][3] = 0.0f;
1878 
1879  result.m[3][0] = -(result.m[0][0] * m[3][0] + result.m[1][0] * m[3][1] + result.m[2][0] * m[3][2]);
1880  result.m[3][1] = -(result.m[0][1] * m[3][0] + result.m[1][1] * m[3][1] + result.m[2][1] * m[3][2]);
1881  result.m[3][2] = -(result.m[0][2] * m[3][0] + result.m[1][2] * m[3][1] + result.m[2][2] * m[3][2]);
1882  result.m[3][3] = 1.0f;
1883 
1884  return result;
1885 }
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:63
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ perspective()

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

See also
ortho(), frustum()

Definition at line 1487 of file qmatrix4x4.cpp.

1488 {
1489  // Bail out if the projection volume is zero-sized.
1490  if (nearPlane == farPlane || aspect == 0.0f)
1491  return;
1492 
1493  // Construct the projection.
1494  QMatrix4x4 m(1);
1495  qreal radians = (angle / 2.0f) * M_PI / 180.0f;
1496  qreal sine = qSin(radians);
1497  if (sine == 0.0f)
1498  return;
1499  qreal cotan = qCos(radians) / sine;
1500  qreal clip = farPlane - nearPlane;
1501  m.m[0][0] = cotan / aspect;
1502  m.m[1][0] = 0.0f;
1503  m.m[2][0] = 0.0f;
1504  m.m[3][0] = 0.0f;
1505  m.m[0][1] = 0.0f;
1506  m.m[1][1] = cotan;
1507  m.m[2][1] = 0.0f;
1508  m.m[3][1] = 0.0f;
1509  m.m[0][2] = 0.0f;
1510  m.m[1][2] = 0.0f;
1511  m.m[2][2] = -(nearPlane + farPlane) / clip;
1512  m.m[3][2] = -(2.0f * nearPlane * farPlane) / clip;
1513  m.m[0][3] = 0.0f;
1514  m.m[1][3] = 0.0f;
1515  m.m[2][3] = -1.0f;
1516  m.m[3][3] = 0.0f;
1517 
1518  // Apply the projection.
1519  *this *= m;
1520 }
double qreal
Definition: qglobal.h:1193
#define M_PI
Definition: qmath.h:261
qreal qSin(qreal v)
Definition: qmath.h:93
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:63
qreal m[4][4]
Definition: qmatrix4x4.h:188
qreal angle(const QPointF &p1, const QPointF &p2)
qreal qCos(qreal v)
Definition: qmath.h:109

◆ projectedRotate()

void QMatrix4x4::projectedRotate ( qreal  angle,
qreal  x,
qreal  y,
qreal  z 
)
private
Warning
This function is not part of the public interface.

Definition at line 1195 of file qmatrix4x4.cpp.

Referenced by QGraphicsRotation::applyTo().

1196 {
1197  // Used by QGraphicsRotation::applyTo() to perform a rotation
1198  // and projection back to 2D in a single step.
1199  if (angle == 0.0f)
1200  return;
1201  QMatrix4x4 m(1); // The "1" says to not load the identity.
1202  qreal c, s, ic;
1203  if (angle == 90.0f || angle == -270.0f) {
1204  s = 1.0f;
1205  c = 0.0f;
1206  } else if (angle == -90.0f || angle == 270.0f) {
1207  s = -1.0f;
1208  c = 0.0f;
1209  } else if (angle == 180.0f || angle == -180.0f) {
1210  s = 0.0f;
1211  c = -1.0f;
1212  } else {
1213  qreal a = angle * M_PI / 180.0f;
1214  c = qCos(a);
1215  s = qSin(a);
1216  }
1217  bool quick = false;
1218  if (x == 0.0f) {
1219  if (y == 0.0f) {
1220  if (z != 0.0f) {
1221  // Rotate around the Z axis.
1222  m.setToIdentity();
1223  m.m[0][0] = c;
1224  m.m[1][1] = c;
1225  if (z < 0.0f) {
1226  m.m[1][0] = s;
1227  m.m[0][1] = -s;
1228  } else {
1229  m.m[1][0] = -s;
1230  m.m[0][1] = s;
1231  }
1232  m.flagBits = General;
1233  quick = true;
1234  }
1235  } else if (z == 0.0f) {
1236  // Rotate around the Y axis.
1237  m.setToIdentity();
1238  m.m[0][0] = c;
1239  m.m[2][2] = 1.0f;
1240  if (y < 0.0f) {
1241  m.m[0][3] = -s * inv_dist_to_plane;
1242  } else {
1243  m.m[0][3] = s * inv_dist_to_plane;
1244  }
1245  m.flagBits = General;
1246  quick = true;
1247  }
1248  } else if (y == 0.0f && z == 0.0f) {
1249  // Rotate around the X axis.
1250  m.setToIdentity();
1251  m.m[1][1] = c;
1252  m.m[2][2] = 1.0f;
1253  if (x < 0.0f) {
1254  m.m[1][3] = s * inv_dist_to_plane;
1255  } else {
1256  m.m[1][3] = -s * inv_dist_to_plane;
1257  }
1258  m.flagBits = General;
1259  quick = true;
1260  }
1261  if (!quick) {
1262  qreal len = x * x + y * y + z * z;
1263  if (!qFuzzyIsNull(len - 1.0f) && !qFuzzyIsNull(len)) {
1264  len = qSqrt(len);
1265  x /= len;
1266  y /= len;
1267  z /= len;
1268  }
1269  ic = 1.0f - c;
1270  m.m[0][0] = x * x * ic + c;
1271  m.m[1][0] = x * y * ic - z * s;
1272  m.m[2][0] = 0.0f;
1273  m.m[3][0] = 0.0f;
1274  m.m[0][1] = y * x * ic + z * s;
1275  m.m[1][1] = y * y * ic + c;
1276  m.m[2][1] = 0.0f;
1277  m.m[3][1] = 0.0f;
1278  m.m[0][2] = 0.0f;
1279  m.m[1][2] = 0.0f;
1280  m.m[2][2] = 1.0f;
1281  m.m[3][2] = 0.0f;
1282  m.m[0][3] = (x * z * ic - y * s) * -inv_dist_to_plane;
1283  m.m[1][3] = (y * z * ic + x * s) * -inv_dist_to_plane;
1284  m.m[2][3] = 0.0f;
1285  m.m[3][3] = 1.0f;
1286  }
1287  int flags = flagBits;
1288  *this *= m;
1289  if (flags != Identity)
1290  flagBits = flags | Rotation;
1291  else
1292  flagBits = Rotation;
1293 }
int flagBits
Definition: qmatrix4x4.h:189
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
long ASN1_INTEGER_get ASN1_INTEGER * a
#define M_PI
Definition: qmath.h:261
qreal qSin(qreal v)
Definition: qmath.h:93
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:63
qreal m[4][4]
Definition: qmatrix4x4.h:188
qreal angle(const QPointF &p1, const QPointF &p2)
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
qreal qCos(qreal v)
Definition: qmath.h:109
qreal qSqrt(qreal v)
Definition: qmath.h:205
static const qreal inv_dist_to_plane
Definition: qmatrix4x4.cpp:64

◆ rotate() [1/3]

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

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

See also
scale(), translate()

Definition at line 1072 of file qmatrix4x4.cpp.

1073 {
1074  rotate(angle, vector.x(), vector.y(), vector.z());
1075 }
qreal x() const
Returns the x coordinate of this point.
Definition: qvector3d.h:161
qreal z() const
Returns the z coordinate of this point.
Definition: qvector3d.h:163
qreal angle(const QPointF &p1, const QPointF &p2)
void rotate(qreal angle, const QVector3D &vector)
Multiples this matrix by another that rotates coordinates through angle degrees about vector...
qreal y() const
Returns the y coordinate of this point.
Definition: qvector3d.h:162

◆ rotate() [2/3]

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

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

See also
scale(), translate()

Definition at line 1090 of file qmatrix4x4.cpp.

1091 {
1092  if (angle == 0.0f)
1093  return;
1094  QMatrix4x4 m(1); // The "1" says to not load the identity.
1095  qreal c, s, ic;
1096  if (angle == 90.0f || angle == -270.0f) {
1097  s = 1.0f;
1098  c = 0.0f;
1099  } else if (angle == -90.0f || angle == 270.0f) {
1100  s = -1.0f;
1101  c = 0.0f;
1102  } else if (angle == 180.0f || angle == -180.0f) {
1103  s = 0.0f;
1104  c = -1.0f;
1105  } else {
1106  qreal a = angle * M_PI / 180.0f;
1107  c = qCos(a);
1108  s = qSin(a);
1109  }
1110  bool quick = false;
1111  if (x == 0.0f) {
1112  if (y == 0.0f) {
1113  if (z != 0.0f) {
1114  // Rotate around the Z axis.
1115  m.setToIdentity();
1116  m.m[0][0] = c;
1117  m.m[1][1] = c;
1118  if (z < 0.0f) {
1119  m.m[1][0] = s;
1120  m.m[0][1] = -s;
1121  } else {
1122  m.m[1][0] = -s;
1123  m.m[0][1] = s;
1124  }
1125  m.flagBits = General;
1126  quick = true;
1127  }
1128  } else if (z == 0.0f) {
1129  // Rotate around the Y axis.
1130  m.setToIdentity();
1131  m.m[0][0] = c;
1132  m.m[2][2] = c;
1133  if (y < 0.0f) {
1134  m.m[2][0] = -s;
1135  m.m[0][2] = s;
1136  } else {
1137  m.m[2][0] = s;
1138  m.m[0][2] = -s;
1139  }
1140  m.flagBits = General;
1141  quick = true;
1142  }
1143  } else if (y == 0.0f && z == 0.0f) {
1144  // Rotate around the X axis.
1145  m.setToIdentity();
1146  m.m[1][1] = c;
1147  m.m[2][2] = c;
1148  if (x < 0.0f) {
1149  m.m[2][1] = s;
1150  m.m[1][2] = -s;
1151  } else {
1152  m.m[2][1] = -s;
1153  m.m[1][2] = s;
1154  }
1155  m.flagBits = General;
1156  quick = true;
1157  }
1158  if (!quick) {
1159  qreal len = x * x + y * y + z * z;
1160  if (!qFuzzyIsNull(len - 1.0f) && !qFuzzyIsNull(len)) {
1161  len = qSqrt(len);
1162  x /= len;
1163  y /= len;
1164  z /= len;
1165  }
1166  ic = 1.0f - c;
1167  m.m[0][0] = x * x * ic + c;
1168  m.m[1][0] = x * y * ic - z * s;
1169  m.m[2][0] = x * z * ic + y * s;
1170  m.m[3][0] = 0.0f;
1171  m.m[0][1] = y * x * ic + z * s;
1172  m.m[1][1] = y * y * ic + c;
1173  m.m[2][1] = y * z * ic - x * s;
1174  m.m[3][1] = 0.0f;
1175  m.m[0][2] = x * z * ic - y * s;
1176  m.m[1][2] = y * z * ic + x * s;
1177  m.m[2][2] = z * z * ic + c;
1178  m.m[3][2] = 0.0f;
1179  m.m[0][3] = 0.0f;
1180  m.m[1][3] = 0.0f;
1181  m.m[2][3] = 0.0f;
1182  m.m[3][3] = 1.0f;
1183  }
1184  int flags = flagBits;
1185  *this *= m;
1186  if (flags != Identity)
1187  flagBits = flags | Rotation;
1188  else
1189  flagBits = Rotation;
1190 }
int flagBits
Definition: qmatrix4x4.h:189
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
long ASN1_INTEGER_get ASN1_INTEGER * a
#define M_PI
Definition: qmath.h:261
qreal qSin(qreal v)
Definition: qmath.h:93
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:63
qreal m[4][4]
Definition: qmatrix4x4.h:188
qreal angle(const QPointF &p1, const QPointF &p2)
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
qreal qCos(qreal v)
Definition: qmath.h:109
qreal qSqrt(qreal v)
Definition: qmath.h:205

◆ rotate() [3/3]

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
scale(), translate(), QQuaternion

Definition at line 1304 of file qmatrix4x4.cpp.

1305 {
1306  // Algorithm from:
1307  // http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q54
1308  QMatrix4x4 m(1);
1309  qreal xx = quaternion.x() * quaternion.x();
1310  qreal xy = quaternion.x() * quaternion.y();
1311  qreal xz = quaternion.x() * quaternion.z();
1312  qreal xw = quaternion.x() * quaternion.scalar();
1313  qreal yy = quaternion.y() * quaternion.y();
1314  qreal yz = quaternion.y() * quaternion.z();
1315  qreal yw = quaternion.y() * quaternion.scalar();
1316  qreal zz = quaternion.z() * quaternion.z();
1317  qreal zw = quaternion.z() * quaternion.scalar();
1318  m.m[0][0] = 1.0f - 2 * (yy + zz);
1319  m.m[1][0] = 2 * (xy - zw);
1320  m.m[2][0] = 2 * (xz + yw);
1321  m.m[3][0] = 0.0f;
1322  m.m[0][1] = 2 * (xy + zw);
1323  m.m[1][1] = 1.0f - 2 * (xx + zz);
1324  m.m[2][1] = 2 * (yz - xw);
1325  m.m[3][1] = 0.0f;
1326  m.m[0][2] = 2 * (xz - yw);
1327  m.m[1][2] = 2 * (yz + xw);
1328  m.m[2][2] = 1.0f - 2 * (xx + yy);
1329  m.m[3][2] = 0.0f;
1330  m.m[0][3] = 0.0f;
1331  m.m[1][3] = 0.0f;
1332  m.m[2][3] = 0.0f;
1333  m.m[3][3] = 1.0f;
1334  int flags = flagBits;
1335  *this *= m;
1336  if (flags != Identity)
1337  flagBits = flags | Rotation;
1338  else
1339  flagBits = Rotation;
1340 }
int flagBits
Definition: qmatrix4x4.h:189
double qreal
Definition: qglobal.h:1193
qreal x() const
Returns the x coordinate of this quaternion&#39;s vector.
Definition: qquaternion.h:156
qreal scalar() const
Returns the scalar component of this quaternion.
Definition: qquaternion.h:159
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:63
qreal m[4][4]
Definition: qmatrix4x4.h:188
qreal y() const
Returns the y coordinate of this quaternion&#39;s vector.
Definition: qquaternion.h:157
qreal z() const
Returns the z coordinate of this quaternion&#39;s vector.
Definition: qquaternion.h:158

◆ row()

QVector4D QMatrix4x4::row ( int  index) const
inline

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

See also
setRow(), column()

Definition at line 289 of file qmatrix4x4.h.

Referenced by copyDataTo(), operator<<(), operator>>(), QMatrix4x4(), and transposed().

290 {
291  Q_ASSERT(index >= 0 && index < 4);
292  return QVector4D(m[0][index], m[1][index], m[2][index], m[3][index]);
293 }
The QVector4D class represents a vector or vertex in 4D space.
Definition: qvector4d.h:60
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
qreal m[4][4]
Definition: qmatrix4x4.h:188
quint16 index

◆ scale() [1/4]

void QMatrix4x4::scale ( const QVector3D vector)

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

See also
translate(), rotate()

Definition at line 775 of file qmatrix4x4.cpp.

Referenced by QGraphicsScale::applyTo(), ortho(), and ShaderEffectItem::renderEffect().

776 {
777  qreal vx = vector.x();
778  qreal vy = vector.y();
779  qreal vz = vector.z();
780  if (flagBits == Identity) {
781  m[0][0] = vx;
782  m[1][1] = vy;
783  m[2][2] = vz;
784  flagBits = Scale;
785  } else if (flagBits == Scale || flagBits == (Scale | Translation)) {
786  m[0][0] *= vx;
787  m[1][1] *= vy;
788  m[2][2] *= vz;
789  } else if (flagBits == Translation) {
790  m[0][0] = vx;
791  m[1][1] = vy;
792  m[2][2] = vz;
793  flagBits |= Scale;
794  } else {
795  m[0][0] *= vx;
796  m[0][1] *= vx;
797  m[0][2] *= vx;
798  m[0][3] *= vx;
799  m[1][0] *= vy;
800  m[1][1] *= vy;
801  m[1][2] *= vy;
802  m[1][3] *= vy;
803  m[2][0] *= vz;
804  m[2][1] *= vz;
805  m[2][2] *= vz;
806  m[2][3] *= vz;
807  flagBits = General;
808  }
809 }
int flagBits
Definition: qmatrix4x4.h:189
double qreal
Definition: qglobal.h:1193
qreal x() const
Returns the x coordinate of this point.
Definition: qvector3d.h:161
qreal z() const
Returns the z coordinate of this point.
Definition: qvector3d.h:163
qreal m[4][4]
Definition: qmatrix4x4.h:188
The Scale element provides a way to scale an Item.
qreal y() const
Returns the y coordinate of this point.
Definition: qvector3d.h:162

◆ scale() [2/4]

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

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

See also
translate(), rotate()

Definition at line 823 of file qmatrix4x4.cpp.

824 {
825  if (flagBits == Identity) {
826  m[0][0] = x;
827  m[1][1] = y;
828  flagBits = Scale;
829  } else if (flagBits == Scale || flagBits == (Scale | Translation)) {
830  m[0][0] *= x;
831  m[1][1] *= y;
832  } else if (flagBits == Translation) {
833  m[0][0] = x;
834  m[1][1] = y;
835  flagBits |= Scale;
836  } else {
837  m[0][0] *= x;
838  m[0][1] *= x;
839  m[0][2] *= x;
840  m[0][3] *= x;
841  m[1][0] *= y;
842  m[1][1] *= y;
843  m[1][2] *= y;
844  m[1][3] *= y;
845  flagBits = General;
846  }
847 }
int flagBits
Definition: qmatrix4x4.h:189
qreal m[4][4]
Definition: qmatrix4x4.h:188
The Scale element provides a way to scale an Item.

◆ scale() [3/4]

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

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

See also
translate(), rotate()

Definition at line 860 of file qmatrix4x4.cpp.

861 {
862  if (flagBits == Identity) {
863  m[0][0] = x;
864  m[1][1] = y;
865  m[2][2] = z;
866  flagBits = Scale;
867  } else if (flagBits == Scale || flagBits == (Scale | Translation)) {
868  m[0][0] *= x;
869  m[1][1] *= y;
870  m[2][2] *= z;
871  } else if (flagBits == Translation) {
872  m[0][0] = x;
873  m[1][1] = y;
874  m[2][2] = z;
875  flagBits |= Scale;
876  } else {
877  m[0][0] *= x;
878  m[0][1] *= x;
879  m[0][2] *= x;
880  m[0][3] *= x;
881  m[1][0] *= y;
882  m[1][1] *= y;
883  m[1][2] *= y;
884  m[1][3] *= y;
885  m[2][0] *= z;
886  m[2][1] *= z;
887  m[2][2] *= z;
888  m[2][3] *= z;
889  flagBits = General;
890  }
891 }
int flagBits
Definition: qmatrix4x4.h:189
qreal m[4][4]
Definition: qmatrix4x4.h:188
The Scale element provides a way to scale an Item.

◆ scale() [4/4]

void QMatrix4x4::scale ( qreal  factor)

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

See also
translate(), rotate()

Definition at line 904 of file qmatrix4x4.cpp.

905 {
906  if (flagBits == Identity) {
907  m[0][0] = factor;
908  m[1][1] = factor;
909  m[2][2] = factor;
910  flagBits = Scale;
911  } else if (flagBits == Scale || flagBits == (Scale | Translation)) {
912  m[0][0] *= factor;
913  m[1][1] *= factor;
914  m[2][2] *= factor;
915  } else if (flagBits == Translation) {
916  m[0][0] = factor;
917  m[1][1] = factor;
918  m[2][2] = factor;
919  flagBits |= Scale;
920  } else {
921  m[0][0] *= factor;
922  m[0][1] *= factor;
923  m[0][2] *= factor;
924  m[0][3] *= factor;
925  m[1][0] *= factor;
926  m[1][1] *= factor;
927  m[1][2] *= factor;
928  m[1][3] *= factor;
929  m[2][0] *= factor;
930  m[2][1] *= factor;
931  m[2][2] *= factor;
932  m[2][3] *= factor;
933  flagBits = General;
934  }
935 }
int flagBits
Definition: qmatrix4x4.h:189
qreal m[4][4]
Definition: qmatrix4x4.h:188
The Scale element provides a way to scale an Item.

◆ setColumn()

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

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

See also
column(), setRow()

Definition at line 279 of file qmatrix4x4.h.

280 {
281  Q_ASSERT(index >= 0 && index < 4);
282  m[index][0] = value.x();
283  m[index][1] = value.y();
284  m[index][2] = value.z();
285  m[index][3] = value.w();
286  flagBits = General;
287 }
int flagBits
Definition: qmatrix4x4.h:189
qreal w() const
Returns the w coordinate of this point.
Definition: qvector4d.h:161
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
qreal x() const
Returns the x coordinate of this point.
Definition: qvector4d.h:158
qreal m[4][4]
Definition: qmatrix4x4.h:188
quint16 index
qreal z() const
Returns the z coordinate of this point.
Definition: qvector4d.h:160
qreal y() const
Returns the y coordinate of this point.
Definition: qvector4d.h:159

◆ setRow()

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

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

See also
row(), setColumn()

Definition at line 295 of file qmatrix4x4.h.

296 {
297  Q_ASSERT(index >= 0 && index < 4);
298  m[0][index] = value.x();
299  m[1][index] = value.y();
300  m[2][index] = value.z();
301  m[3][index] = value.w();
302  flagBits = General;
303 }
int flagBits
Definition: qmatrix4x4.h:189
qreal w() const
Returns the w coordinate of this point.
Definition: qvector4d.h:161
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
qreal x() const
Returns the x coordinate of this point.
Definition: qvector4d.h:158
qreal m[4][4]
Definition: qmatrix4x4.h:188
quint16 index
qreal z() const
Returns the z coordinate of this point.
Definition: qvector4d.h:160
qreal y() const
Returns the y coordinate of this point.
Definition: qvector4d.h:159

◆ setToIdentity()

void QMatrix4x4::setToIdentity ( )
inline

Sets this matrix to the identity.

See also
isIdentity()

Definition at line 324 of file qmatrix4x4.h.

Referenced by projectedRotate(), and rotate().

325 {
326  m[0][0] = 1.0f;
327  m[0][1] = 0.0f;
328  m[0][2] = 0.0f;
329  m[0][3] = 0.0f;
330  m[1][0] = 0.0f;
331  m[1][1] = 1.0f;
332  m[1][2] = 0.0f;
333  m[1][3] = 0.0f;
334  m[2][0] = 0.0f;
335  m[2][1] = 0.0f;
336  m[2][2] = 1.0f;
337  m[2][3] = 0.0f;
338  m[3][0] = 0.0f;
339  m[3][1] = 0.0f;
340  m[3][2] = 0.0f;
341  m[3][3] = 1.0f;
342  flagBits = Identity;
343 }
int flagBits
Definition: qmatrix4x4.h:189
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ toAffine()

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

Definition at line 1613 of file qmatrix4x4.cpp.

1614 {
1615  return QMatrix(m[0][0], m[0][1],
1616  m[1][0], m[1][1],
1617  m[3][0], m[3][1]);
1618 }
The QMatrix class specifies 2D transformations of a coordinate system.
Definition: qmatrix.h:61
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ toGenericMatrix()

template<int N, int M>
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.

Definition at line 243 of file qmatrix4x4.h.

244 {
246  qreal *values = result.data();
247  for (int matrixCol = 0; matrixCol < N; ++matrixCol) {
248  for (int matrixRow = 0; matrixRow < M; ++matrixRow) {
249  if (matrixCol < 4 && matrixRow < 4)
250  values[matrixCol * M + matrixRow] = m[matrixCol][matrixRow];
251  else if (matrixCol == matrixRow)
252  values[matrixCol * M + matrixRow] = 1.0f;
253  else
254  values[matrixCol * M + matrixRow] = 0.0f;
255  }
256  }
257  return result;
258 }
T * data()
Returns a pointer to the raw data of this matrix.
double qreal
Definition: qglobal.h:1193
The QGenericMatrix class is a template class that represents a NxM transformation matrix with N colum...
#define M(row, col)
quint16 values[128]
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ toTransform() [1/2]

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 co-ordinate should be dropped rather than projected.

See also
toAffine()

Definition at line 1631 of file qmatrix4x4.cpp.

Referenced by QGraphicsItemGroup::addToGroup(), QGraphicsItemPrivate::TransformData::computedFullTransform(), and QGraphicsItemGroup::removeFromGroup().

1632 {
1633  return QTransform(m[0][0], m[0][1], m[0][3],
1634  m[1][0], m[1][1], m[1][3],
1635  m[3][0], m[3][1], m[3][3]);
1636 }
qreal m[4][4]
Definition: qmatrix4x4.h:188
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ toTransform() [2/2]

QTransform QMatrix4x4::toTransform ( qreal  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 co-ordinate. 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 co-ordinate should be dropped rather than projected.

See also
toAffine()

Definition at line 1655 of file qmatrix4x4.cpp.

1656 {
1657  if (distanceToPlane == 1024.0f) {
1658  // Optimize the common case with constants.
1659  return QTransform(m[0][0], m[0][1],
1660  m[0][3] - m[0][2] * inv_dist_to_plane,
1661  m[1][0], m[1][1],
1662  m[1][3] - m[1][2] * inv_dist_to_plane,
1663  m[3][0], m[3][1],
1664  m[3][3] - m[3][2] * inv_dist_to_plane);
1665  } else if (distanceToPlane != 0.0f) {
1666  // The following projection matrix is pre-multiplied with "matrix":
1667  // | 1 0 0 0 |
1668  // | 0 1 0 0 |
1669  // | 0 0 1 0 |
1670  // | 0 0 d 1 |
1671  // where d = -1 / distanceToPlane. After projection, row 3 and
1672  // column 3 are dropped to form the final QTransform.
1673  qreal d = 1.0f / distanceToPlane;
1674  return QTransform(m[0][0], m[0][1], m[0][3] - m[0][2] * d,
1675  m[1][0], m[1][1], m[1][3] - m[1][2] * d,
1676  m[3][0], m[3][1], m[3][3] - m[3][2] * d);
1677  } else {
1678  // Orthographic projection: drop row 3 and column 3.
1679  return QTransform(m[0][0], m[0][1], m[0][3],
1680  m[1][0], m[1][1], m[1][3],
1681  m[3][0], m[3][1], m[3][3]);
1682  }
1683 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
qreal m[4][4]
Definition: qmatrix4x4.h:188
static const qreal inv_dist_to_plane
Definition: qmatrix4x4.cpp:64
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ translate() [1/3]

void QMatrix4x4::translate ( const QVector3D vector)

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

See also
scale(), rotate()

Definition at line 944 of file qmatrix4x4.cpp.

Referenced by QDeclarativeTranslate::applyTo(), QGraphicsScale::applyTo(), QGraphicsRotation::applyTo(), lookAt(), ortho(), and ShaderEffectItem::renderEffect().

945 {
946  qreal vx = vector.x();
947  qreal vy = vector.y();
948  qreal vz = vector.z();
949  if (flagBits == Identity) {
950  m[3][0] = vx;
951  m[3][1] = vy;
952  m[3][2] = vz;
954  } else if (flagBits == Translation) {
955  m[3][0] += vx;
956  m[3][1] += vy;
957  m[3][2] += vz;
958  } else if (flagBits == Scale) {
959  m[3][0] = m[0][0] * vx;
960  m[3][1] = m[1][1] * vy;
961  m[3][2] = m[2][2] * vz;
963  } else if (flagBits == (Scale | Translation)) {
964  m[3][0] += m[0][0] * vx;
965  m[3][1] += m[1][1] * vy;
966  m[3][2] += m[2][2] * vz;
967  } else {
968  m[3][0] += m[0][0] * vx + m[1][0] * vy + m[2][0] * vz;
969  m[3][1] += m[0][1] * vx + m[1][1] * vy + m[2][1] * vz;
970  m[3][2] += m[0][2] * vx + m[1][2] * vy + m[2][2] * vz;
971  m[3][3] += m[0][3] * vx + m[1][3] * vy + m[2][3] * vz;
972  if (flagBits == Rotation)
974  else if (flagBits != (Rotation | Translation))
975  flagBits = General;
976  }
977 }
int flagBits
Definition: qmatrix4x4.h:189
double qreal
Definition: qglobal.h:1193
The Rotation object provides a way to rotate an Item.
qreal x() const
Returns the x coordinate of this point.
Definition: qvector3d.h:161
qreal z() const
Returns the z coordinate of this point.
Definition: qvector3d.h:163
qreal m[4][4]
Definition: qmatrix4x4.h:188
The Scale element provides a way to scale an Item.
qreal y() const
Returns the y coordinate of this point.
Definition: qvector3d.h:162

◆ translate() [2/3]

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

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

See also
scale(), rotate()

Definition at line 992 of file qmatrix4x4.cpp.

993 {
994  if (flagBits == Identity) {
995  m[3][0] = x;
996  m[3][1] = y;
998  } else if (flagBits == Translation) {
999  m[3][0] += x;
1000  m[3][1] += y;
1001  } else if (flagBits == Scale) {
1002  m[3][0] = m[0][0] * x;
1003  m[3][1] = m[1][1] * y;
1004  m[3][2] = 0.;
1005  flagBits |= Translation;
1006  } else if (flagBits == (Scale | Translation)) {
1007  m[3][0] += m[0][0] * x;
1008  m[3][1] += m[1][1] * y;
1009  } else {
1010  m[3][0] += m[0][0] * x + m[1][0] * y;
1011  m[3][1] += m[0][1] * x + m[1][1] * y;
1012  m[3][2] += m[0][2] * x + m[1][2] * y;
1013  m[3][3] += m[0][3] * x + m[1][3] * y;
1014  if (flagBits == Rotation)
1015  flagBits |= Translation;
1016  else if (flagBits != (Rotation | Translation))
1017  flagBits = General;
1018  }
1019 }
int flagBits
Definition: qmatrix4x4.h:189
The Rotation object provides a way to rotate an Item.
qreal m[4][4]
Definition: qmatrix4x4.h:188
The Scale element provides a way to scale an Item.

◆ translate() [3/3]

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

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

See also
scale(), rotate()

Definition at line 1032 of file qmatrix4x4.cpp.

1033 {
1034  if (flagBits == Identity) {
1035  m[3][0] = x;
1036  m[3][1] = y;
1037  m[3][2] = z;
1039  } else if (flagBits == Translation) {
1040  m[3][0] += x;
1041  m[3][1] += y;
1042  m[3][2] += z;
1043  } else if (flagBits == Scale) {
1044  m[3][0] = m[0][0] * x;
1045  m[3][1] = m[1][1] * y;
1046  m[3][2] = m[2][2] * z;
1047  flagBits |= Translation;
1048  } else if (flagBits == (Scale | Translation)) {
1049  m[3][0] += m[0][0] * x;
1050  m[3][1] += m[1][1] * y;
1051  m[3][2] += m[2][2] * z;
1052  } else {
1053  m[3][0] += m[0][0] * x + m[1][0] * y + m[2][0] * z;
1054  m[3][1] += m[0][1] * x + m[1][1] * y + m[2][1] * z;
1055  m[3][2] += m[0][2] * x + m[1][2] * y + m[2][2] * z;
1056  m[3][3] += m[0][3] * x + m[1][3] * y + m[2][3] * z;
1057  if (flagBits == Rotation)
1058  flagBits |= Translation;
1059  else if (flagBits != (Rotation | Translation))
1060  flagBits = General;
1061  }
1062 }
int flagBits
Definition: qmatrix4x4.h:189
The Rotation object provides a way to rotate an Item.
qreal m[4][4]
Definition: qmatrix4x4.h:188
The Scale element provides a way to scale an Item.

◆ transposed()

QMatrix4x4 QMatrix4x4::transposed ( ) const

Returns this matrix, transposed about its diagonal.

Definition at line 510 of file qmatrix4x4.cpp.

511 {
512  QMatrix4x4 result(1); // The "1" says to not load the identity.
513  for (int row = 0; row < 4; ++row) {
514  for (int col = 0; col < 4; ++col) {
515  result.m[col][row] = m[row][col];
516  }
517  }
518  return result;
519 }
QVector4D row(int index) const
Returns the elements of row index as a 4D vector.
Definition: qmatrix4x4.h:289
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:63
qreal m[4][4]
Definition: qmatrix4x4.h:188

Friends and Related Functions

◆ operator* [1/11]

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

Returns the product of m1 and m2.

Definition at line 529 of file qmatrix4x4.h.

530 {
531  if (m1.flagBits == QMatrix4x4::Identity)
532  return m2;
533  else if (m2.flagBits == QMatrix4x4::Identity)
534  return m1;
535 
536  QMatrix4x4 m(1);
537  m.m[0][0] = m1.m[0][0] * m2.m[0][0] +
538  m1.m[1][0] * m2.m[0][1] +
539  m1.m[2][0] * m2.m[0][2] +
540  m1.m[3][0] * m2.m[0][3];
541  m.m[0][1] = m1.m[0][1] * m2.m[0][0] +
542  m1.m[1][1] * m2.m[0][1] +
543  m1.m[2][1] * m2.m[0][2] +
544  m1.m[3][1] * m2.m[0][3];
545  m.m[0][2] = m1.m[0][2] * m2.m[0][0] +
546  m1.m[1][2] * m2.m[0][1] +
547  m1.m[2][2] * m2.m[0][2] +
548  m1.m[3][2] * m2.m[0][3];
549  m.m[0][3] = m1.m[0][3] * m2.m[0][0] +
550  m1.m[1][3] * m2.m[0][1] +
551  m1.m[2][3] * m2.m[0][2] +
552  m1.m[3][3] * m2.m[0][3];
553  m.m[1][0] = m1.m[0][0] * m2.m[1][0] +
554  m1.m[1][0] * m2.m[1][1] +
555  m1.m[2][0] * m2.m[1][2] +
556  m1.m[3][0] * m2.m[1][3];
557  m.m[1][1] = m1.m[0][1] * m2.m[1][0] +
558  m1.m[1][1] * m2.m[1][1] +
559  m1.m[2][1] * m2.m[1][2] +
560  m1.m[3][1] * m2.m[1][3];
561  m.m[1][2] = m1.m[0][2] * m2.m[1][0] +
562  m1.m[1][2] * m2.m[1][1] +
563  m1.m[2][2] * m2.m[1][2] +
564  m1.m[3][2] * m2.m[1][3];
565  m.m[1][3] = m1.m[0][3] * m2.m[1][0] +
566  m1.m[1][3] * m2.m[1][1] +
567  m1.m[2][3] * m2.m[1][2] +
568  m1.m[3][3] * m2.m[1][3];
569  m.m[2][0] = m1.m[0][0] * m2.m[2][0] +
570  m1.m[1][0] * m2.m[2][1] +
571  m1.m[2][0] * m2.m[2][2] +
572  m1.m[3][0] * m2.m[2][3];
573  m.m[2][1] = m1.m[0][1] * m2.m[2][0] +
574  m1.m[1][1] * m2.m[2][1] +
575  m1.m[2][1] * m2.m[2][2] +
576  m1.m[3][1] * m2.m[2][3];
577  m.m[2][2] = m1.m[0][2] * m2.m[2][0] +
578  m1.m[1][2] * m2.m[2][1] +
579  m1.m[2][2] * m2.m[2][2] +
580  m1.m[3][2] * m2.m[2][3];
581  m.m[2][3] = m1.m[0][3] * m2.m[2][0] +
582  m1.m[1][3] * m2.m[2][1] +
583  m1.m[2][3] * m2.m[2][2] +
584  m1.m[3][3] * m2.m[2][3];
585  m.m[3][0] = m1.m[0][0] * m2.m[3][0] +
586  m1.m[1][0] * m2.m[3][1] +
587  m1.m[2][0] * m2.m[3][2] +
588  m1.m[3][0] * m2.m[3][3];
589  m.m[3][1] = m1.m[0][1] * m2.m[3][0] +
590  m1.m[1][1] * m2.m[3][1] +
591  m1.m[2][1] * m2.m[3][2] +
592  m1.m[3][1] * m2.m[3][3];
593  m.m[3][2] = m1.m[0][2] * m2.m[3][0] +
594  m1.m[1][2] * m2.m[3][1] +
595  m1.m[2][2] * m2.m[3][2] +
596  m1.m[3][2] * m2.m[3][3];
597  m.m[3][3] = m1.m[0][3] * m2.m[3][0] +
598  m1.m[1][3] * m2.m[3][1] +
599  m1.m[2][3] * m2.m[3][2] +
600  m1.m[3][3] * m2.m[3][3];
601  return m;
602 }
int flagBits
Definition: qmatrix4x4.h:189
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:63
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ operator* [2/11]

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

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

Definition at line 631 of file qmatrix4x4.h.

632 {
633  qreal x, y, z, w;
634  if (matrix.flagBits == QMatrix4x4::Identity) {
635  return vector;
636  } else if (matrix.flagBits == QMatrix4x4::Translation) {
637  return QVector3D(vector.x() + matrix.m[3][0],
638  vector.y() + matrix.m[3][1],
639  vector.z() + matrix.m[3][2]);
640  } else if (matrix.flagBits ==
642  return QVector3D(vector.x() * matrix.m[0][0] + matrix.m[3][0],
643  vector.y() * matrix.m[1][1] + matrix.m[3][1],
644  vector.z() * matrix.m[2][2] + matrix.m[3][2]);
645  } else if (matrix.flagBits == QMatrix4x4::Scale) {
646  return QVector3D(vector.x() * matrix.m[0][0],
647  vector.y() * matrix.m[1][1],
648  vector.z() * matrix.m[2][2]);
649  } else {
650  x = vector.x() * matrix.m[0][0] +
651  vector.y() * matrix.m[1][0] +
652  vector.z() * matrix.m[2][0] +
653  matrix.m[3][0];
654  y = vector.x() * matrix.m[0][1] +
655  vector.y() * matrix.m[1][1] +
656  vector.z() * matrix.m[2][1] +
657  matrix.m[3][1];
658  z = vector.x() * matrix.m[0][2] +
659  vector.y() * matrix.m[1][2] +
660  vector.z() * matrix.m[2][2] +
661  matrix.m[3][2];
662  w = vector.x() * matrix.m[0][3] +
663  vector.y() * matrix.m[1][3] +
664  vector.z() * matrix.m[2][3] +
665  matrix.m[3][3];
666  if (w == 1.0f)
667  return QVector3D(x, y, z);
668  else
669  return QVector3D(x / w, y / w, z / w);
670  }
671 }
int flagBits
Definition: qmatrix4x4.h:189
The QVector3D class represents a vector or vertex in 3D space.
Definition: qvector3d.h:60
double qreal
Definition: qglobal.h:1193
qreal x() const
Returns the x coordinate of this point.
Definition: qvector3d.h:161
qreal z() const
Returns the z coordinate of this point.
Definition: qvector3d.h:163
qreal m[4][4]
Definition: qmatrix4x4.h:188
qreal y() const
Returns the y coordinate of this point.
Definition: qvector3d.h:162

◆ operator* [3/11]

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

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

Definition at line 606 of file qmatrix4x4.h.

607 {
608  qreal x, y, z, w;
609  x = vector.x() * matrix.m[0][0] +
610  vector.y() * matrix.m[0][1] +
611  vector.z() * matrix.m[0][2] +
612  matrix.m[0][3];
613  y = vector.x() * matrix.m[1][0] +
614  vector.y() * matrix.m[1][1] +
615  vector.z() * matrix.m[1][2] +
616  matrix.m[1][3];
617  z = vector.x() * matrix.m[2][0] +
618  vector.y() * matrix.m[2][1] +
619  vector.z() * matrix.m[2][2] +
620  matrix.m[2][3];
621  w = vector.x() * matrix.m[3][0] +
622  vector.y() * matrix.m[3][1] +
623  vector.z() * matrix.m[3][2] +
624  matrix.m[3][3];
625  if (w == 1.0f)
626  return QVector3D(x, y, z);
627  else
628  return QVector3D(x / w, y / w, z / w);
629 }
The QVector3D class represents a vector or vertex in 3D space.
Definition: qvector3d.h:60
double qreal
Definition: qglobal.h:1193
qreal x() const
Returns the x coordinate of this point.
Definition: qvector3d.h:161
qreal z() const
Returns the z coordinate of this point.
Definition: qvector3d.h:163
qreal m[4][4]
Definition: qmatrix4x4.h:188
qreal y() const
Returns the y coordinate of this point.
Definition: qvector3d.h:162

◆ operator* [4/11]

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

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

Definition at line 677 of file qmatrix4x4.h.

678 {
679  qreal x, y, z, w;
680  x = vector.x() * matrix.m[0][0] +
681  vector.y() * matrix.m[0][1] +
682  vector.z() * matrix.m[0][2] +
683  vector.w() * matrix.m[0][3];
684  y = vector.x() * matrix.m[1][0] +
685  vector.y() * matrix.m[1][1] +
686  vector.z() * matrix.m[1][2] +
687  vector.w() * matrix.m[1][3];
688  z = vector.x() * matrix.m[2][0] +
689  vector.y() * matrix.m[2][1] +
690  vector.z() * matrix.m[2][2] +
691  vector.w() * matrix.m[2][3];
692  w = vector.x() * matrix.m[3][0] +
693  vector.y() * matrix.m[3][1] +
694  vector.z() * matrix.m[3][2] +
695  vector.w() * matrix.m[3][3];
696  return QVector4D(x, y, z, w);
697 }
double qreal
Definition: qglobal.h:1193
qreal w() const
Returns the w coordinate of this point.
Definition: qvector4d.h:161
The QVector4D class represents a vector or vertex in 4D space.
Definition: qvector4d.h:60
qreal x() const
Returns the x coordinate of this point.
Definition: qvector4d.h:158
qreal m[4][4]
Definition: qmatrix4x4.h:188
qreal z() const
Returns the z coordinate of this point.
Definition: qvector4d.h:160
qreal y() const
Returns the y coordinate of this point.
Definition: qvector4d.h:159

◆ operator* [5/11]

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

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

Definition at line 699 of file qmatrix4x4.h.

700 {
701  qreal x, y, z, w;
702  x = vector.x() * matrix.m[0][0] +
703  vector.y() * matrix.m[1][0] +
704  vector.z() * matrix.m[2][0] +
705  vector.w() * matrix.m[3][0];
706  y = vector.x() * matrix.m[0][1] +
707  vector.y() * matrix.m[1][1] +
708  vector.z() * matrix.m[2][1] +
709  vector.w() * matrix.m[3][1];
710  z = vector.x() * matrix.m[0][2] +
711  vector.y() * matrix.m[1][2] +
712  vector.z() * matrix.m[2][2] +
713  vector.w() * matrix.m[3][2];
714  w = vector.x() * matrix.m[0][3] +
715  vector.y() * matrix.m[1][3] +
716  vector.z() * matrix.m[2][3] +
717  vector.w() * matrix.m[3][3];
718  return QVector4D(x, y, z, w);
719 }
double qreal
Definition: qglobal.h:1193
qreal w() const
Returns the w coordinate of this point.
Definition: qvector4d.h:161
The QVector4D class represents a vector or vertex in 4D space.
Definition: qvector4d.h:60
qreal x() const
Returns the x coordinate of this point.
Definition: qvector4d.h:158
qreal m[4][4]
Definition: qmatrix4x4.h:188
qreal z() const
Returns the z coordinate of this point.
Definition: qvector4d.h:160
qreal y() const
Returns the y coordinate of this point.
Definition: qvector4d.h:159

◆ operator* [6/11]

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

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

Definition at line 723 of file qmatrix4x4.h.

724 {
725  qreal xin, yin;
726  qreal x, y, w;
727  xin = point.x();
728  yin = point.y();
729  x = xin * matrix.m[0][0] +
730  yin * matrix.m[0][1] +
731  matrix.m[0][3];
732  y = xin * matrix.m[1][0] +
733  yin * matrix.m[1][1] +
734  matrix.m[1][3];
735  w = xin * matrix.m[3][0] +
736  yin * matrix.m[3][1] +
737  matrix.m[3][3];
738  if (w == 1.0f)
739  return QPoint(qRound(x), qRound(y));
740  else
741  return QPoint(qRound(x / w), qRound(y / w));
742 }
double qreal
Definition: qglobal.h:1193
qreal m[4][4]
Definition: qmatrix4x4.h:188
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ operator* [7/11]

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

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

Definition at line 744 of file qmatrix4x4.h.

745 {
746  qreal xin, yin;
747  qreal x, y, w;
748  xin = point.x();
749  yin = point.y();
750  x = xin * matrix.m[0][0] +
751  yin * matrix.m[0][1] +
752  matrix.m[0][3];
753  y = xin * matrix.m[1][0] +
754  yin * matrix.m[1][1] +
755  matrix.m[1][3];
756  w = xin * matrix.m[3][0] +
757  yin * matrix.m[3][1] +
758  matrix.m[3][3];
759  if (w == 1.0f) {
760  return QPointF(qreal(x), qreal(y));
761  } else {
762  return QPointF(qreal(x / w), qreal(y / w));
763  }
764 }
double qreal
Definition: qglobal.h:1193
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
qreal m[4][4]
Definition: qmatrix4x4.h:188
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287

◆ operator* [8/11]

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

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

Definition at line 766 of file qmatrix4x4.h.

767 {
768  qreal xin, yin;
769  qreal x, y, w;
770  xin = point.x();
771  yin = point.y();
772  if (matrix.flagBits == QMatrix4x4::Identity) {
773  return point;
774  } else if (matrix.flagBits == QMatrix4x4::Translation) {
775  return QPoint(qRound(xin + matrix.m[3][0]),
776  qRound(yin + matrix.m[3][1]));
777  } else if (matrix.flagBits ==
779  return QPoint(qRound(xin * matrix.m[0][0] + matrix.m[3][0]),
780  qRound(yin * matrix.m[1][1] + matrix.m[3][1]));
781  } else if (matrix.flagBits == QMatrix4x4::Scale) {
782  return QPoint(qRound(xin * matrix.m[0][0]),
783  qRound(yin * matrix.m[1][1]));
784  } else {
785  x = xin * matrix.m[0][0] +
786  yin * matrix.m[1][0] +
787  matrix.m[3][0];
788  y = xin * matrix.m[0][1] +
789  yin * matrix.m[1][1] +
790  matrix.m[3][1];
791  w = xin * matrix.m[0][3] +
792  yin * matrix.m[1][3] +
793  matrix.m[3][3];
794  if (w == 1.0f)
795  return QPoint(qRound(x), qRound(y));
796  else
797  return QPoint(qRound(x / w), qRound(y / w));
798  }
799 }
int flagBits
Definition: qmatrix4x4.h:189
double qreal
Definition: qglobal.h:1193
qreal m[4][4]
Definition: qmatrix4x4.h:188
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ operator* [9/11]

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

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

Definition at line 801 of file qmatrix4x4.h.

802 {
803  qreal xin, yin;
804  qreal x, y, w;
805  xin = point.x();
806  yin = point.y();
807  if (matrix.flagBits == QMatrix4x4::Identity) {
808  return point;
809  } else if (matrix.flagBits == QMatrix4x4::Translation) {
810  return QPointF(xin + matrix.m[3][0],
811  yin + matrix.m[3][1]);
812  } else if (matrix.flagBits ==
814  return QPointF(xin * matrix.m[0][0] + matrix.m[3][0],
815  yin * matrix.m[1][1] + matrix.m[3][1]);
816  } else if (matrix.flagBits == QMatrix4x4::Scale) {
817  return QPointF(xin * matrix.m[0][0],
818  yin * matrix.m[1][1]);
819  } else {
820  x = xin * matrix.m[0][0] +
821  yin * matrix.m[1][0] +
822  matrix.m[3][0];
823  y = xin * matrix.m[0][1] +
824  yin * matrix.m[1][1] +
825  matrix.m[3][1];
826  w = xin * matrix.m[0][3] +
827  yin * matrix.m[1][3] +
828  matrix.m[3][3];
829  if (w == 1.0f) {
830  return QPointF(qreal(x), qreal(y));
831  } else {
832  return QPointF(qreal(x / w), qreal(y / w));
833  }
834  }
835 }
int flagBits
Definition: qmatrix4x4.h:189
double qreal
Definition: qglobal.h:1193
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
qreal m[4][4]
Definition: qmatrix4x4.h:188
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287

◆ operator* [10/11]

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

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

Definition at line 859 of file qmatrix4x4.h.

860 {
861  QMatrix4x4 m(1);
862  m.m[0][0] = matrix.m[0][0] * factor;
863  m.m[0][1] = matrix.m[0][1] * factor;
864  m.m[0][2] = matrix.m[0][2] * factor;
865  m.m[0][3] = matrix.m[0][3] * factor;
866  m.m[1][0] = matrix.m[1][0] * factor;
867  m.m[1][1] = matrix.m[1][1] * factor;
868  m.m[1][2] = matrix.m[1][2] * factor;
869  m.m[1][3] = matrix.m[1][3] * factor;
870  m.m[2][0] = matrix.m[2][0] * factor;
871  m.m[2][1] = matrix.m[2][1] * factor;
872  m.m[2][2] = matrix.m[2][2] * factor;
873  m.m[2][3] = matrix.m[2][3] * factor;
874  m.m[3][0] = matrix.m[3][0] * factor;
875  m.m[3][1] = matrix.m[3][1] * factor;
876  m.m[3][2] = matrix.m[3][2] * factor;
877  m.m[3][3] = matrix.m[3][3] * factor;
878  return m;
879 }
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:63
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ operator* [11/11]

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

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

Definition at line 881 of file qmatrix4x4.h.

882 {
883  QMatrix4x4 m(1);
884  m.m[0][0] = matrix.m[0][0] * factor;
885  m.m[0][1] = matrix.m[0][1] * factor;
886  m.m[0][2] = matrix.m[0][2] * factor;
887  m.m[0][3] = matrix.m[0][3] * factor;
888  m.m[1][0] = matrix.m[1][0] * factor;
889  m.m[1][1] = matrix.m[1][1] * factor;
890  m.m[1][2] = matrix.m[1][2] * factor;
891  m.m[1][3] = matrix.m[1][3] * factor;
892  m.m[2][0] = matrix.m[2][0] * factor;
893  m.m[2][1] = matrix.m[2][1] * factor;
894  m.m[2][2] = matrix.m[2][2] * factor;
895  m.m[2][3] = matrix.m[2][3] * factor;
896  m.m[3][0] = matrix.m[3][0] * factor;
897  m.m[3][1] = matrix.m[3][1] * factor;
898  m.m[3][2] = matrix.m[3][2] * factor;
899  m.m[3][3] = matrix.m[3][3] * factor;
900  return m;
901 }
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:63
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ operator+

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

Returns the sum of m1 and m2.

Definition at line 485 of file qmatrix4x4.h.

486 {
487  QMatrix4x4 m(1);
488  m.m[0][0] = m1.m[0][0] + m2.m[0][0];
489  m.m[0][1] = m1.m[0][1] + m2.m[0][1];
490  m.m[0][2] = m1.m[0][2] + m2.m[0][2];
491  m.m[0][3] = m1.m[0][3] + m2.m[0][3];
492  m.m[1][0] = m1.m[1][0] + m2.m[1][0];
493  m.m[1][1] = m1.m[1][1] + m2.m[1][1];
494  m.m[1][2] = m1.m[1][2] + m2.m[1][2];
495  m.m[1][3] = m1.m[1][3] + m2.m[1][3];
496  m.m[2][0] = m1.m[2][0] + m2.m[2][0];
497  m.m[2][1] = m1.m[2][1] + m2.m[2][1];
498  m.m[2][2] = m1.m[2][2] + m2.m[2][2];
499  m.m[2][3] = m1.m[2][3] + m2.m[2][3];
500  m.m[3][0] = m1.m[3][0] + m2.m[3][0];
501  m.m[3][1] = m1.m[3][1] + m2.m[3][1];
502  m.m[3][2] = m1.m[3][2] + m2.m[3][2];
503  m.m[3][3] = m1.m[3][3] + m2.m[3][3];
504  return m;
505 }
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:63
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ operator- [1/2]

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

Returns the difference of m1 and m2.

Definition at line 507 of file qmatrix4x4.h.

508 {
509  QMatrix4x4 m(1);
510  m.m[0][0] = m1.m[0][0] - m2.m[0][0];
511  m.m[0][1] = m1.m[0][1] - m2.m[0][1];
512  m.m[0][2] = m1.m[0][2] - m2.m[0][2];
513  m.m[0][3] = m1.m[0][3] - m2.m[0][3];
514  m.m[1][0] = m1.m[1][0] - m2.m[1][0];
515  m.m[1][1] = m1.m[1][1] - m2.m[1][1];
516  m.m[1][2] = m1.m[1][2] - m2.m[1][2];
517  m.m[1][3] = m1.m[1][3] - m2.m[1][3];
518  m.m[2][0] = m1.m[2][0] - m2.m[2][0];
519  m.m[2][1] = m1.m[2][1] - m2.m[2][1];
520  m.m[2][2] = m1.m[2][2] - m2.m[2][2];
521  m.m[2][3] = m1.m[2][3] - m2.m[2][3];
522  m.m[3][0] = m1.m[3][0] - m2.m[3][0];
523  m.m[3][1] = m1.m[3][1] - m2.m[3][1];
524  m.m[3][2] = m1.m[3][2] - m2.m[3][2];
525  m.m[3][3] = m1.m[3][3] - m2.m[3][3];
526  return m;
527 }
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:63
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ operator- [2/2]

QMatrix4x4 operator- ( const QMatrix4x4 matrix)
friend

Returns the negation of matrix.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 837 of file qmatrix4x4.h.

838 {
839  QMatrix4x4 m(1);
840  m.m[0][0] = -matrix.m[0][0];
841  m.m[0][1] = -matrix.m[0][1];
842  m.m[0][2] = -matrix.m[0][2];
843  m.m[0][3] = -matrix.m[0][3];
844  m.m[1][0] = -matrix.m[1][0];
845  m.m[1][1] = -matrix.m[1][1];
846  m.m[1][2] = -matrix.m[1][2];
847  m.m[1][3] = -matrix.m[1][3];
848  m.m[2][0] = -matrix.m[2][0];
849  m.m[2][1] = -matrix.m[2][1];
850  m.m[2][2] = -matrix.m[2][2];
851  m.m[2][3] = -matrix.m[2][3];
852  m.m[3][0] = -matrix.m[3][0];
853  m.m[3][1] = -matrix.m[3][1];
854  m.m[3][2] = -matrix.m[3][2];
855  m.m[3][3] = -matrix.m[3][3];
856  return m;
857 }
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:63
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ operator/

QMatrix4x4 operator/ ( const QMatrix4x4 matrix,
qreal  divisor 
)
friend

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

Definition at line 734 of file qmatrix4x4.cpp.

735 {
736  QMatrix4x4 m(1); // The "1" says to not load the identity.
737  m.m[0][0] = matrix.m[0][0] / divisor;
738  m.m[0][1] = matrix.m[0][1] / divisor;
739  m.m[0][2] = matrix.m[0][2] / divisor;
740  m.m[0][3] = matrix.m[0][3] / divisor;
741  m.m[1][0] = matrix.m[1][0] / divisor;
742  m.m[1][1] = matrix.m[1][1] / divisor;
743  m.m[1][2] = matrix.m[1][2] / divisor;
744  m.m[1][3] = matrix.m[1][3] / divisor;
745  m.m[2][0] = matrix.m[2][0] / divisor;
746  m.m[2][1] = matrix.m[2][1] / divisor;
747  m.m[2][2] = matrix.m[2][2] / divisor;
748  m.m[2][3] = matrix.m[2][3] / divisor;
749  m.m[3][0] = matrix.m[3][0] / divisor;
750  m.m[3][1] = matrix.m[3][1] / divisor;
751  m.m[3][2] = matrix.m[3][2] / divisor;
752  m.m[3][3] = matrix.m[3][3] / divisor;
753  return m;
754 }
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:63
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ operator<< [1/2]

Q_GUI_EXPORT QDebug operator<< ( QDebug  dbg,
const QMatrix4x4 m 
)
friend

Definition at line 1955 of file qmatrix4x4.cpp.

1956 {
1957  // Create a string that represents the matrix type.
1958  QByteArray bits;
1959  if ((m.flagBits & QMatrix4x4::Identity) != 0)
1960  bits += "Identity,";
1961  if ((m.flagBits & QMatrix4x4::General) != 0)
1962  bits += "General,";
1963  if ((m.flagBits & QMatrix4x4::Translation) != 0)
1964  bits += "Translation,";
1965  if ((m.flagBits & QMatrix4x4::Scale) != 0)
1966  bits += "Scale,";
1967  if ((m.flagBits & QMatrix4x4::Rotation) != 0)
1968  bits += "Rotation,";
1969  if (bits.size() > 0)
1970  bits = bits.left(bits.size() - 1);
1971 
1972  // Output in row-major order because it is more human-readable.
1973  dbg.nospace() << "QMatrix4x4(type:" << bits.constData() << endl
1974  << qSetFieldWidth(10)
1975  << m(0, 0) << m(0, 1) << m(0, 2) << m(0, 3) << endl
1976  << m(1, 0) << m(1, 1) << m(1, 2) << m(1, 3) << endl
1977  << m(2, 0) << m(2, 1) << m(2, 2) << m(2, 3) << endl
1978  << m(3, 0) << m(3, 1) << m(3, 2) << m(3, 3) << endl
1979  << qSetFieldWidth(0) << ')';
1980  return dbg.space();
1981 }
int flagBits
Definition: qmatrix4x4.h:189
QDebug & nospace()
Clears the stream&#39;s internal flag that records whether the last character was a space and returns a r...
Definition: qdebug.h:92
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QByteArray left(int len) const
Returns a byte array that contains the leftmost len bytes of this byte array.
qreal m[4][4]
Definition: qmatrix4x4.h:188
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QTextStreamManipulator qSetFieldWidth(int width)
Definition: qtextstream.h:329
QDebug & space()
Writes a space character to the debug stream and returns a reference to the stream.
Definition: qdebug.h:91
Q_CORE_EXPORT QTextStream & endl(QTextStream &s)

◆ operator<<() [2/2]

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

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

See also
{Serializing Qt Data Types}

Definition at line 2000 of file qmatrix4x4.cpp.

2001 {
2002  for (int row = 0; row < 4; ++row)
2003  for (int col = 0; col < 4; ++col)
2004  stream << double(matrix(row, col));
2005  return stream;
2006 }
static FILE * stream
QVector4D row(int index) const
Returns the elements of row index as a 4D vector.
Definition: qmatrix4x4.h:289

◆ operator>>()

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

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

See also
{Serializing Qt Data Types}

Definition at line 2021 of file qmatrix4x4.cpp.

2022 {
2023  double x;
2024  for (int row = 0; row < 4; ++row) {
2025  for (int col = 0; col < 4; ++col) {
2026  stream >> x;
2027  matrix(row, col) = qreal(x);
2028  }
2029  }
2030  matrix.optimize();
2031  return stream;
2032 }
double qreal
Definition: qglobal.h:1193
void optimize()
Optimize the usage of this matrix from its current elements.
static FILE * stream
QVector4D row(int index) const
Returns the elements of row index as a 4D vector.
Definition: qmatrix4x4.h:289

◆ qFuzzyCompare

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

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

Definition at line 903 of file qmatrix4x4.h.

904 {
905  return qFuzzyCompare(m1.m[0][0], m2.m[0][0]) &&
906  qFuzzyCompare(m1.m[0][1], m2.m[0][1]) &&
907  qFuzzyCompare(m1.m[0][2], m2.m[0][2]) &&
908  qFuzzyCompare(m1.m[0][3], m2.m[0][3]) &&
909  qFuzzyCompare(m1.m[1][0], m2.m[1][0]) &&
910  qFuzzyCompare(m1.m[1][1], m2.m[1][1]) &&
911  qFuzzyCompare(m1.m[1][2], m2.m[1][2]) &&
912  qFuzzyCompare(m1.m[1][3], m2.m[1][3]) &&
913  qFuzzyCompare(m1.m[2][0], m2.m[2][0]) &&
914  qFuzzyCompare(m1.m[2][1], m2.m[2][1]) &&
915  qFuzzyCompare(m1.m[2][2], m2.m[2][2]) &&
916  qFuzzyCompare(m1.m[2][3], m2.m[2][3]) &&
917  qFuzzyCompare(m1.m[3][0], m2.m[3][0]) &&
918  qFuzzyCompare(m1.m[3][1], m2.m[3][1]) &&
919  qFuzzyCompare(m1.m[3][2], m2.m[3][2]) &&
920  qFuzzyCompare(m1.m[3][3], m2.m[3][3]);
921 }
qreal m[4][4]
Definition: qmatrix4x4.h:188
friend 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 compari...
Definition: qmatrix4x4.h:903

◆ qGenericMatrixFromMatrix4x4()

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

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
QMatrix4x4::toGenericMatrix()

Definition at line 997 of file qmatrix4x4.h.

998 {
1000  const qreal *m = matrix.constData();
1001  qreal *values = result.data();
1002  for (int col = 0; col < N; ++col) {
1003  for (int row = 0; row < M; ++row) {
1004  if (col < 4 && row < 4)
1005  values[col * M + row] = m[col * 4 + row];
1006  else if (col == row)
1007  values[col * M + row] = 1.0f;
1008  else
1009  values[col * M + row] = 0.0f;
1010  }
1011  }
1012  return result;
1013 }
T * data()
Returns a pointer to the raw data of this matrix.
double qreal
Definition: qglobal.h:1193
The QGenericMatrix class is a template class that represents a NxM transformation matrix with N colum...
#define M(row, col)
QVector4D row(int index) const
Returns the elements of row index as a 4D vector.
Definition: qmatrix4x4.h:289
quint16 values[128]
const qreal * constData() const
Returns a constant pointer to the raw data of this matrix.
Definition: qmatrix4x4.h:177
qreal m[4][4]
Definition: qmatrix4x4.h:188

◆ qGenericMatrixToMatrix4x4()

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

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
QMatrix4x4(const QGenericMatrix &)

Definition at line 991 of file qmatrix4x4.h.

992 {
993  return QMatrix4x4(matrix.constData(), N, M);
994 }
const T * constData() const
Returns a constant pointer to the raw data of this matrix.
QMatrix4x4()
Constructs an identity matrix.
Definition: qmatrix4x4.h:66
#define M(row, col)

◆ QGraphicsRotation

friend class QGraphicsRotation
friend

Definition at line 206 of file qmatrix4x4.h.

Properties

◆ flagBits

int QMatrix4x4::flagBits
private

◆ m

qreal QMatrix4x4::m[4][4]
private

The documentation for this class was generated from the following files: