src/gui/math3d/qmatrix4x4.h
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
    61 class QVariant;
    61 class QVariant;
    62 
    62 
    63 class Q_GUI_EXPORT QMatrix4x4
    63 class Q_GUI_EXPORT QMatrix4x4
    64 {
    64 {
    65 public:
    65 public:
    66     inline QMatrix4x4() { setIdentity(); }
    66     inline QMatrix4x4() { setToIdentity(); }
    67     explicit QMatrix4x4(const qreal *values);
    67     explicit QMatrix4x4(const qreal *values);
    68     inline QMatrix4x4(qreal m11, qreal m12, qreal m13, qreal m14,
    68     inline QMatrix4x4(qreal m11, qreal m12, qreal m13, qreal m14,
    69                       qreal m21, qreal m22, qreal m23, qreal m24,
    69                       qreal m21, qreal m22, qreal m23, qreal m24,
    70                       qreal m31, qreal m32, qreal m33, qreal m34,
    70                       qreal m31, qreal m32, qreal m33, qreal m34,
    71                       qreal m41, qreal m42, qreal m43, qreal m44);
    71                       qreal m41, qreal m42, qreal m43, qreal m44);
    85 
    85 
    86     inline QVector4D row(int index) const;
    86     inline QVector4D row(int index) const;
    87     inline void setRow(int index, const QVector4D& value);
    87     inline void setRow(int index, const QVector4D& value);
    88 
    88 
    89     inline bool isIdentity() const;
    89     inline bool isIdentity() const;
    90     inline void setIdentity();
    90     inline void setToIdentity();
    91 
    91 
    92     inline void fill(qreal value);
    92     inline void fill(qreal value);
    93 
    93 
    94     qreal determinant() const;
    94     qreal determinant() const;
    95     QMatrix4x4 inverted(bool *invertible = 0) const;
    95     QMatrix4x4 inverted(bool *invertible = 0) const;
   125     friend Q_GUI_EXPORT QMatrix4x4 operator/(const QMatrix4x4& matrix, qreal divisor);
   125     friend Q_GUI_EXPORT QMatrix4x4 operator/(const QMatrix4x4& matrix, qreal divisor);
   126 
   126 
   127     friend inline bool qFuzzyCompare(const QMatrix4x4& m1, const QMatrix4x4& m2);
   127     friend inline bool qFuzzyCompare(const QMatrix4x4& m1, const QMatrix4x4& m2);
   128 
   128 
   129 #ifndef QT_NO_VECTOR3D
   129 #ifndef QT_NO_VECTOR3D
   130     QMatrix4x4& scale(const QVector3D& vector);
   130     void scale(const QVector3D& vector);
   131     QMatrix4x4& translate(const QVector3D& vector);
   131     void translate(const QVector3D& vector);
   132     QMatrix4x4& rotate(qreal angle, const QVector3D& vector);
   132     void rotate(qreal angle, const QVector3D& vector);
   133 #endif
   133 #endif
   134     QMatrix4x4& scale(qreal x, qreal y);
   134     void scale(qreal x, qreal y);
   135     QMatrix4x4& scale(qreal x, qreal y, qreal z);
   135     void scale(qreal x, qreal y, qreal z);
   136     QMatrix4x4& scale(qreal factor);
   136     void scale(qreal factor);
   137     QMatrix4x4& translate(qreal x, qreal y);
   137     void translate(qreal x, qreal y);
   138     QMatrix4x4& translate(qreal x, qreal y, qreal z);
   138     void translate(qreal x, qreal y, qreal z);
   139     QMatrix4x4& rotate(qreal angle, qreal x, qreal y, qreal z = 0.0f);
   139     void rotate(qreal angle, qreal x, qreal y, qreal z = 0.0f);
   140 #ifndef QT_NO_QUATERNION
   140 #ifndef QT_NO_QUATERNION
   141     QMatrix4x4& rotate(const QQuaternion& quaternion);
   141     void rotate(const QQuaternion& quaternion);
   142 #endif
   142 #endif
   143 
   143 
       
   144     void ortho(const QRect& rect);
       
   145     void ortho(const QRectF& rect);
       
   146     void ortho(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane);
       
   147     void frustum(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane);
       
   148     void perspective(qreal angle, qreal aspect, qreal nearPlane, qreal farPlane);
   144 #ifndef QT_NO_VECTOR3D
   149 #ifndef QT_NO_VECTOR3D
   145     void extractAxisRotation(qreal &angle, QVector3D &axis) const;
   150     void lookAt(const QVector3D& eye, const QVector3D& center, const QVector3D& up);
   146     QVector3D extractTranslation() const;
   151 #endif
   147 #endif
   152     void flipCoordinates();
   148 
   153 
   149     QMatrix4x4& ortho(const QRect& rect);
   154     void copyDataTo(qreal *values) const;
   150     QMatrix4x4& ortho(const QRectF& rect);
       
   151     QMatrix4x4& ortho(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane);
       
   152     QMatrix4x4& frustum(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane);
       
   153     QMatrix4x4& perspective(qreal angle, qreal aspect, qreal nearPlane, qreal farPlane);
       
   154 #ifndef QT_NO_VECTOR3D
       
   155     QMatrix4x4& lookAt(const QVector3D& eye, const QVector3D& center, const QVector3D& up);
       
   156 #endif
       
   157     QMatrix4x4& flipCoordinates();
       
   158 
       
   159     void toValueArray(qreal *values) const;
       
   160 
   155 
   161     QMatrix toAffine() const;
   156     QMatrix toAffine() const;
   162     QTransform toTransform(qreal distanceToPlane = 1024.0f) const;
   157     QTransform toTransform() const;
       
   158     QTransform toTransform(qreal distanceToPlane) const;
   163 
   159 
   164     QPoint map(const QPoint& point) const;
   160     QPoint map(const QPoint& point) const;
   165     QPointF map(const QPointF& point) const;
   161     QPointF map(const QPointF& point) const;
   166 #ifndef QT_NO_VECTOR3D
   162 #ifndef QT_NO_VECTOR3D
   167     QVector3D map(const QVector3D& point) const;
   163     QVector3D map(const QVector3D& point) const;
   180 
   176 
   181     inline qreal *data();
   177     inline qreal *data();
   182     inline const qreal *data() const { return m[0]; }
   178     inline const qreal *data() const { return m[0]; }
   183     inline const qreal *constData() const { return m[0]; }
   179     inline const qreal *constData() const { return m[0]; }
   184 
   180 
   185     void inferSpecialType();
   181     void optimize();
   186 
   182 
   187     operator QVariant() const;
   183     operator QVariant() const;
   188 
   184 
   189 #ifndef QT_NO_DEBUG_STREAM
   185 #ifndef QT_NO_DEBUG_STREAM
   190     friend Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QMatrix4x4 &m);
   186     friend Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QMatrix4x4 &m);
   204 
   200 
   205     // Construct without initializing identity matrix.
   201     // Construct without initializing identity matrix.
   206     QMatrix4x4(int) { flagBits = General; }
   202     QMatrix4x4(int) { flagBits = General; }
   207 
   203 
   208     QMatrix4x4 orthonormalInverse() const;
   204     QMatrix4x4 orthonormalInverse() const;
       
   205 
       
   206     void projectedRotate(qreal angle, qreal x, qreal y, qreal z);
       
   207 
       
   208     friend class QGraphicsRotation;
   209 };
   209 };
   210 
   210 
   211 inline QMatrix4x4::QMatrix4x4
   211 inline QMatrix4x4::QMatrix4x4
   212         (qreal m11, qreal m12, qreal m13, qreal m14,
   212         (qreal m11, qreal m12, qreal m13, qreal m14,
   213          qreal m21, qreal m22, qreal m23, qreal m24,
   213          qreal m21, qreal m22, qreal m23, qreal m24,
   323     if (m[3][0] != 0.0f || m[3][1] != 0.0f || m[3][2] != 0.0f)
   323     if (m[3][0] != 0.0f || m[3][1] != 0.0f || m[3][2] != 0.0f)
   324         return false;
   324         return false;
   325     return (m[3][3] == 1.0f);
   325     return (m[3][3] == 1.0f);
   326 }
   326 }
   327 
   327 
   328 inline void QMatrix4x4::setIdentity()
   328 inline void QMatrix4x4::setToIdentity()
   329 {
   329 {
   330     m[0][0] = 1.0f;
   330     m[0][0] = 1.0f;
   331     m[0][1] = 0.0f;
   331     m[0][1] = 0.0f;
   332     m[0][2] = 0.0f;
   332     m[0][2] = 0.0f;
   333     m[0][3] = 0.0f;
   333     m[0][3] = 0.0f;