PDA

View Full Version : Detecting clock wise and anti clock wise rotation



poomoo
April 3rd, 2005, 12:31 PM
hey troops!

nube's first post.

can you tell me if it is possible to detect if an object is rotating anti clockwise or not?

at present i get x,y co-ords and use the code below to rotate it which is fine. now i could write an if statement to check if rotation is negative or positive but because rotation can be negative and positive when rotating clockwise and anti clockwise this wouldnt work.

any ideas?



theAngle = Math.atan2(diffy , diffx);

this._rotation = theAngle*360/(2*Math.PI);

updateAfterEvent();


cheers in advance

spartan018
April 3rd, 2005, 12:36 PM
why dont u just store the rotation var to a separate variable (old_var), and every frame have the new rotation be stored to another variable (new_var) and then just subtract old_var from new_var, and if its positive, its counter-clockwise, and if its negative, its clockwise.

poomoo
April 3rd, 2005, 01:14 PM
ah cheers man - that works just as you said. didnt think of that one!

cheers!