QT QMatrix4x4矩阵,用于缩放和旋转原点x和y

QT QMatrix4x4矩阵,用于缩放和旋转原点x和y,qt,matrix,rotation,qml,Qt,Matrix,Rotation,Qml,我正在进行图像变换,我想从x原点和y原点同时缩放和旋转图像。我尝试使用单独的缩放、旋转,但它们同时工作。这是我的密码 function setRotation(rotation){ rt.origin.x=imagQuickitem.anchorPoint.x; rt.origin.y=imagQuickitem.anchorPoint.y; rt.angle=rotation image.transform=rt; image.transform=sc;

我正在进行图像变换,我想从x原点和y原点同时缩放和旋转图像。我尝试使用单独的缩放、旋转,但它们同时工作。这是我的密码

function setRotation(rotation){
    rt.origin.x=imagQuickitem.anchorPoint.x;
    rt.origin.y=imagQuickitem.anchorPoint.y;
    rt.angle=rotation
    image.transform=rt;
    image.transform=sc;
}

function setScale(scale){
    sc.origin.x=imagQuickitem.anchorPoint.x;
    sc.origin.y=imagQuickitem.anchorPoint.y;
    sc.xScale=scale;
    sc.yScale=scale;
    image.transform=sc;
}

Scale { id:sc; }
Rotation { id:rt; }
好的,看起来解决方案是QMatrix4x4,我尝试使用QMatrix4x4并找到了这个链接
但是我不知道如何编写矩阵来处理缩放和旋转,我应该使用旋转矩阵来处理多缩放矩阵吗?

到目前为止,我可以想到两种解决方案。解决方案1:将旋转与缩放结合起来。解决方案2:显式计算变换矩阵。请参阅以下代码段:

Image {
    id: img
    source: "Lenna.png"
    property real rotD: 45 // angle (degrees)
    property real rotR:  rotD * Math.PI / 180 // angle (radians)
    property real scale: 2 // scaling value
    property real x0: 264 // origin.x
    property real y0: 264 // origin.y
    // solution 1: combine 2 transforms
    transform: [
        Rotation{origin.x: img.x0; origin.y: img.y0; angle: img.rotD; },
        Scale{origin.x: img.x0; origin.y: img.y0; xScale: img.scale; yScale: img.scale}
    ]
    // solution 2: do the math to calculate the matrix
//    transform: Matrix4x4 {
//    matrix: Qt.matrix4x4(
//        img.scale*Math.cos(img.rotR), -img.scale*Math.sin(img.rotR), 0, -img.scale*Math.cos(img.rotR)*img.x0 + img.scale*Math.sin(img.rotR)*img.y0 + img.x0,
//        img.scale*Math.sin(img.rotR), img.scale*Math.cos(img.rotR),  0, -img.scale*Math.sin(img.rotR)*img.x0 - img.scale*Math.cos(img.rotR)*img.y0 + img.y0,
//        0, 0, 1, 0,
//        0, 0, 0, 1)
//    }
}

你好您的代码不完整。我们看不到要旋转的对象(例如一个简单的
矩形
),看不到如何应用旋转和缩放,也看不到调用这些函数的位置。此外,对预期结果的一个小说明将非常有用,因此我们可以在发布之前验证我们的解决方案。关于您的评论
我是否应该使用旋转矩阵的多尺度矩阵?
:一般来说,好奇心是很强的。只要你不破坏任何东西或造成伤害-就试试吧!