I need to manipulate QML items through QMatrix4x4, in order to apply some perspective transformations. Basically, I defined the class Transform to use an object QMatrix4x4 as argument for the transform field of the QML Item
class Transform : public QQuickTransform{
Q_OBJECT
Q_PROPERTY(QMatrix4x4 matrix READ matrix WRITE setMatrix NOTIFY matrixChanged)
public:
explicit Transform(QQuickItem *parent = 0);
QMatrix4x4 matrix() const;
void setMatrix(QMatrix4x4 matrix);
virtual void applyTo(QMatrix4x4 *matrix) const;
signals:
void matrixChanged();
private:
QMatrix4x4 m_matrix;
};
where
void Transform::applyTo(QMatrix4x4 *matrix) const {
*matrix *= m_matrix;
matrix->optimize();
}
However, it seems that QML doesn't "define" the perspective matrix in the classical way. I've focused my tests mainly on the rotations (http://en.wikipedia.org/wiki/Rotation_matrix). Let's say I have a QML Item in x:200, y:200 and I apply the transform
transform: [Transform{matrix:mytra},Rotation { axis { x: 1; y: 0; z: 0 } angle: 90 } ]
where mytra is the identity matrix. The method applyTo() receives the (rotation) matrix
1 -0.195312 0 200
0 -0.195312 0 200
0 0 1 0
0 -0.000976562 0 1
but the "classical" one should be
1 0 0 200
0 0 -1 200
0 1 0 0
0 0 0 1
I don't understand where this matrix comes from and how to adapt my matrix to qt. Thanks for the help.