Qt的变换矩阵矩阵、Qt

2023-09-07 23:32:42 作者:眉眼如初岁月如故

我需要操纵通过QMatrix4x4 QML项目,以适用于一些透视转换。基本上,我定义的类转换为使用对象QMatrix4x4作为参数的QML项目的改造领域

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;

};

其中

void Transform::applyTo(QMatrix4x4 *matrix) const {
      *matrix *= m_matrix;
       matrix->optimize();
}

然而,似乎QML没有定义在古典方式的立体矩阵。我关注我的测试主要是对旋转( http://en.wikipedia.org/wiki/Rotation_matrix )。 比方说,我有一个QML项目在X:200,Y:200和本人申请转换

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 } ]

其中mytra是单位矩阵。该方法applyTo()接收(旋转)矩阵

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  

我不明白的地方这个矩阵的来源和如何适应我的矩阵QT间期。 感谢您的帮助。

I don't understand where this matrix comes from and how to adapt my matrix to qt. Thanks for the help.

推荐答案

Qt是进行数学是正确的,但参考帧Qt的使用不与你在想什么投其所好。

The math Qt is performing is correct, but the frame of reference that Qt is using doesn't match up with what you are thinking.

矩阵数学:

所以,你所看到的数学添加剪切在x和图像y方向的组成部分。

So the components you are seeing in the math are adding shear in the x and y directions of image.

但是,Qt的做旋转是那些轴线之一。所以,如果你想要做一个标准的二维旋转,无剪切,你需要或者没有规定轴或您指定的Z轴。

But the rotation that Qt does is about one of those axis. So if you want to do a standard 2D rotation, without shearing, you need to either not specify an axis or you specify the z axis.

的轴线成绕。对于围绕一个点简单的(2D)旋转,你并不需要指定一个轴,作为默认的轴是Z轴(轴{X:0,Y:0; Z:1})

The axis to rotate around. For simple (2D) rotation around a point, you do not need to specify an axis, as the default axis is the z axis (axis { x: 0; y: 0; z: 1 }).

http://qt-project.org/doc/qt-5/qml-qtquick-rotation.html

关于y轴的旋转是这样的:

The rotation about the y axis looks like this:

希望有所帮助。