If you always rotate around the same origin, then you could simply accumulate the angle values in another variable.
Cheers,
_
If you always rotate around the same origin, then you could simply accumulate the angle values in another variable.
Cheers,
_
That's what I ended up doing, but it's not very satisfactory as method...
Why not? Keeping information that you have is usually way better and trying to recover information after throwing it away.
Cheers,
_
It seems to me a QTransform should be able to know its rotation, as well as being able to set it to a fixed value. Then the object itself knows its status rather than relaying on an object upper in the hierarchy, like QMainWindow or having to create a wrapping widget to store that value. It feels to me that storing the value separately is error prone, specially because you can't set the rotation, but you have to rotate relative to that one value you stored. But, sure, if you're careful and deal with the visibility of it, it's ok as a
A QTransform is a transformation value matrix.
It does not have anything like a rotation value.
Any transformation step that is applied is a matrix multiplication of the existing matrix values and a matrix with values depending on the type of transformation.
The QTransform object doesn't need the sequence of transformation steps, applying each step on each point would be very wasteful.
Instead it contains the final values that need to be applied to each point.
Cheers,
_
And that's exactly what I was asking for, the final rotation value.
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 01: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