PDA

View Full Version : Extracting current rotation



Gopala Krishna
11th May 2007, 21:29
Hi,
In my app based entirely on GraphicsView, I have items which can be rotated , mirrored etc. I want to save these states in a file without having to maintain separate variable like currentAngle . I thought of saving the matrix itself but I want to support old file format :(
And hence I need a way to extract only rotation part, mirroring separately!
Is it possible to extract only them from an item ?

mr.costa
13th May 2007, 02:43
You can calculate all you want from the matrix with some math, search the web for it. For example:

http://en.wikipedia.org/wiki/Transformation_matrix

Gopala Krishna
13th May 2007, 11:42
I had seen that link. What I want is to extract only rotation angle from a matrix on which all possible operations could have been done. For eg if i do
item->rotate(23), item->scale(1.3)
I should be able to extract '23' from the item->matrix.

fullmetalcoder
13th May 2007, 12:05
I had seen that link. What I want is to extract only rotation angle from a matrix on which all possible operations could have been done. For eg if i do
item->rotate(23), item->scale(1.3)
I should be able to extract '23' from the item->matrix.
Due to the complexity of computations involved and the combination properties of matrices there's practically no way to extract an angle from a transformation matrix nuless you know ALL the others transformations applied to the matrix... As QMatrix doesn't record successive transformations it can't provide the function you're looking for and I guess you'll have a hard time implementing such an extraction on your own... IMHO, you'd better change your state file format to use QMatrix. It does not mean that you should stop supporting the previous one but just indicates in the file header which version is used (i.e with plain old values or with matrices...)

Gopala Krishna
13th May 2007, 12:13
Thanks for your reply. If that is the case, I'll stick on to using conventional method. :eek:

marcel
13th May 2007, 12:29
The answer to this question is no.

Once you apply another transformation over a rotation you loose the rotation matrix.
I have just tested this in Illustrator. If you rotate a rectangle then the bounding box will alos reflect the items' rotation. If you save it to pdf without "Illustrator editing capabilities", when you load it again, the bounding box will be mapped with an identity matrix ( meaning that the rotation was lost ).

If you really want to do this, you can attach extra information to the item as you edit it ( store it's rotation, scaling, etc ) with the QGraphicsItem::setData function.

Regards