thats perfect ;)
On Nov 1, 2005, at 7:02 PM, Martin Wood wrote:
actually the solution was simpler than i first thought, if you take
advantage of the fact that _rotation can go above 360 and below 0
then all you need to do is this :
import mx.transitions.Tween;
import mx.transitions.easing.*;
function rotation(dx:Number, dy:Number):Number
{
return Math.atan2(dy, dx) * 180/Math.PI;
}
circle.onRelease = function()
{
var newAngle:Number = rotation(_xmouse - this._x, _ymouse-this._y);
var dist:Number = Math.abs(newAngle - this._rotation);
this._rotation %= 360;
if(dist > 180)
{
if(newAngle > this._rotation)
{
newAngle -= 360;
}
else
{
newAngle += 360;
}
}
new Tween(this, "_rotation", Strong.easeOut, this._rotation,
newAngle, 1, true);
};
//
just mind the formatting.
:)
martin
Eric E. Dolecki wrote:
Hmm yes. Looks like the regular Tween stuff won't work.
Looks like a rotation easing class might be in order. And it
decides whether or not to rotate + or - to get to the
destination. Its a bit of work to do, but it would really be
worth it. The Tween class seems to only want to += until it gets
to the desired rotation - which is understandable. But sometimes
we need tighter control ;)
e.dolecki
On Nov 1, 2005, at 4:16 PM, Martin Wood wrote:
well, what you need to do is work out the shortest route to the
angle you want.
i think it would go something like this
first compute the difference in angles :
angleDiff = abs(destAngle - sourceAngle)
if its greater than 180 degrees, you want to go the other way.
to find that, check which angle is bigger.
goClockwise = sourceAngle > destAngle
So, if you are at 5 degrees and you click at 355 you get :
angleDiff = 355 - 5
= 350
goClockwise = false
and if you are at 355 and want to go to 5
angleDiff = 5 - 355
= 350
goClockwise = true
then find out how far to go :
howFar = 360 - angleDiff
and if you want to go anticlockwise, make it negative
THEN, keep the original angle stored, run the tween from 0 ->
howFar and add it to the original angle at each step.
i think this means you wont be able to get the tween to change
_rotation directly, but rather you'll have to get a callback or
something similar to grab the current tween position. (or you
could do something nifty with nested movieclips and rotate the
parent without tweening first, so you can just modify the
rotation of the child from the tween, but that may be more
trouble than its worth..)
anyway, i think that should work, im just working it out as i go
along so it could fail for some cases...this may be where i was
thinking about the quadrant checks, but im not sure.
i'll give it a try in a while, ive got non-computer things to do
now. :)
thanks,
Martin
eric dolecki wrote:
Its that last part frying me - sometimes it works as expected,
other times,
it decides to rotate the long way around :/
thanks all.
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
--
want to know what i think? probably not
http://relivethefuture.com/choronzon
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders