PDA

View Full Version : Can I get current rotation of a QGraphicsView?



bjh
29th September 2008, 19:45
Hi All,

I have a QGraphicsView that I am rotating various amounts based on a passed angle, about 10 times per second. Is there a way I can determine what the current rotational angle of the view is? For example, if I've rotated it 30, then -90, I'd like to know its current rotation is -60.

I've tried to track this in my program, but after a while my tracked angle is quite different than the actual angle. I was tracking the previous angle (pa), subtracting it from the current angle (ca), and then rotating the view by (ca-pa) degrees...

Is current rotation available or deriveable? THANKS!

bjh

caduel
29th September 2008, 20:10
Probably not: if you first translate, then rotate, what is your rotation?

Therefore your best bet will be your initial idea. Try to find out why your code does not work.

Paste your code here if you want us to take a look at it.

maverick_pol
29th September 2008, 20:13
Hi,

Are you talking about View or Scene transform ?
You can always have a var to store current QTransform;

Kacper

bjh
29th September 2008, 20:43
Hi Again,

Disclaimer: I inherited this code from the programmer before me, so I'm sure there are many things about it I don't yet know! We all know how that goes... ;)

maverick_pol - I'm not setting any transformation matrix. Just doing rotations with the painter, having done a centerOn() the center of my view. Can I set an identity matrix, and then call a method to see how it has changed? Thanks for answering!

Caduel - I was afraid that was going to be the case. Guess I'd better dig into the code a little more to see where it is failing. I thought I might get lucky and have an easy way out! :) Thanks for answering!


bjh

caduel
29th September 2008, 21:30
from the Qt docs:

QMatrix rotationMatrix(cosa, sina, -sina, cosa, 0, 0);
with sina being sin(a) and a being the rotation angle and so on.
Assuming that only rotations took place... Using your math skills you can surely calculate a from cosa and sina.

(I still think that keeping book of the rotation angle by pure addition of the deltas should be simpler und easier to understand than that. ;-)

HTH

bjh
2nd October 2008, 22:04
Hi Caduel,

Math skills were not the issue.:D Turns out there was a logic flaw in tracking the previous rotations. Fixed that and all is working as expected!

Appreciate your guidance!

bjh