2017-11-26 14 views
0

이미지 변형 작업 중입니다. x 원점 및 y 원점에서 동시에 이미지의 크기를 조절하고 회전하려고합니다. 별도의 Scale, Rotate를 사용하려고 시도했지만 동시에 하나씩 작동합니다. 여기에 내 코드QT QMatrix4x4 원점 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를 사용하려고하고이 링크 Qt Transform matrix 을 발견,이 솔루션은 QMatrix4x4 것 같다하지만 난 규모와 회전 모두 작동하는 매트릭스를 작성하는 방법을 몰라 회전 행렬이있는 다중 스케일 행렬?

+0

안녕. 코드가 완전하지 않습니다. 회전하려는 객체 (예 : 간단한 'Rectangle')와 회전 및 크기 조정을 적용한 방법 및 해당 함수를 호출하는 위치를 볼 수 없습니다. 또한 기대되는 결과에 대한 작은 그림은 훌륭한 것이므로 게시하기 전에 솔루션을 검증 할 수 있습니다. – derM

+0

그리고 귀하의 의견에 관해서는'회전 매트릭스가있는 다중 스케일 매트릭스를 사용해야합니까? ': 일반적으로 호기심이 큽니다. 당신이 아무것도 파괴하지 않거나 해를 끼치 지 않는 한 - 그냥 시도하십시오! https://en.wikipedia.org/wiki/Transformation_matrix#Composing_and_inverting_transformations – derM

답변

3

내가 지금까지 생각할 수있는 두 가지 해결책이 있습니다. 해결책 1 : Rotation과 Scale을 결합하십시오. 해결 방법 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) 
// } 
} 
+0

대단히 감사합니다. 첫 번째 방법이 효과적이었습니다. –