Keeping the transformation values in your own variables and rebuilding the QTransform when you need it is the simplest way (I would go with that as well).
But if you really need to modify the rotation from the QTransform, the first two values of the first and second rows ( [m11,m12] and [m21,m22]) describe two 2D vectors that are rotated around an origin. One vector represents the horizontal axis and the other the vertical axis of this transformed space.
They're usually perpendicular. When there's shearing involved they're not perpendicular, this is what causes shearing after all.
The length of these vectors is the scale.
Translation is not involved in this, it's the third row.
So if you want to change the rotation while preserving the scale, first obtain the length of each vector (Pythagorean theorem) , rotate the vectors by the desired amount and scale them by the original length.
vecHx = Cos( angle ) * originalScaleH
vecHy = Sin( angle ) * originalScaleH
vecVx = Cos( angle - 90 ) * originalScaleV
vecVy = Sin( angle - 90 ) * originalScaleV
[vecHx,vecHy] = [m11,m12]
[vecVx,vecVy] = [m21,m22]
If I'm not mistaken it's as simple as that. The "-90" might be wrong depending on the orientation expected by Qt (in which case "+90" would be the right choice, or something else).
Last edited by Kryzon; 8th July 2015 at 02:52.
Thanks Kryzon,
Since apparently the object's QTransform doesn't provide it, I'll go for the simple way and store the rotation and scale on my own. I'd play with the transformation affine matrix components if it became cumbersome to track the rotation.
Bookmarks