我需要通过QMatrix4x4操作QML项目,以便应用一些透视变换。基本上,我定义的类转换到使用对象QMatrix4x4作为参数的QML项目Qt变换矩阵
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;
};
的变换场,其中
void Transform::applyTo(QMatrix4x4 *matrix) const {
*matrix *= m_matrix;
matrix->optimize();
}
然而,似乎QML不“定义”了经典方式的透视矩阵。我的测试主要集中在旋转(http://en.wikipedia.org/wiki/Rotation_matrix)。 比方说,我有一个QML项目在X:200,Y:200和我应用变换
transform: [Transform{matrix:mytra},Rotation { axis { x: 1; y: 0; z: 0 } angle: 90 } ]
其中mytra是单位矩阵。该方法applyTo()接收(旋转)矩阵
1 -0.195312 0 200
0 -0.195312 0 200
0 0 1 0
0 -0.000976562 0 1
但“经典”的一个应该是
1 0 0 200
0 0 -1 200
0 1 0 0
0 0 0 1
我不明白的地方这个矩阵的来源和如何我的矩阵适应QT。 感谢您的帮助。
谢谢......但我不明白4x4矩阵的重点。是否管理z坐标? – lorenzolightsgdwarf 2014-09-19 08:10:16
是的。一个3x3矩阵可以跟踪x和y中的旋转以及x和y中的平移(pos)和比例。一个4×4矩阵可以跟踪x,y和z旋转,缩放和平移(又名pos或位置)。机器人使用4x4矩阵。显卡上的3D渲染也使用4x4矩阵。如果你看看OpenGL,它会在整个地方使用它。 – phyatt 2014-09-19 16:56:56
我们如何翻译沿Z轴的QML矩形? – trusktr 2015-10-28 23:58:50