1
votes

I'll ask a more simple question. Let's say no matter how but I have calculated the rotation of a line between an object center and a mouse (angle). Starting at North aka 0, going a CW circle to 359 near North. I ask AS3 to "object.rotation = angle;" every frame . I have 2 text areas that show the values "angle" and "object.rotation". After 180 object.rotation becomes -180 and goes backwards to 0. Why so?

Even more simple. I get value A, then say A = B. Then ask computer to show A and show B. At 180 to 360, B=B-360.

Rotation is satisfactory, but the numbers are wrong. Need explanation why numbers misfit. Need an advice on how to make object rotation range 0-360 and be directly determined by a number I input. "angle" in my case.

Meaning if I input rotation 2892 it should be it(yes,8*360+12), not 12, not -348... even though these represent the same rotation visually.

2

2 Answers

3
votes

It looks like you're stuck with it. From the documentation:

Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation. Values outside this range are added to or subtracted from 360 to obtain a value within the range. For example, the statement my_video.rotation = 450 is the same as my_video.rotation = 90.

If you want to store 2892 instead of 12, you'll have to track it manually.

When you enter something nonstandard, they standardize it for you. I would assume this is to make it easier on people using the designer, though maybe some graphical optimization relies on it as well.

3
votes

I expect this is the result of Flash's overflow protection. Imagine a movie clip that's turning for an hour, each frame its rotation gets increased by 50. Without such clipping, its rotation value will end up in millions, which will cause loss of precision and performance (in some cases) if one would take a sinus of 10000000*PI/180. So, in order to prevent undesired or different behavior, the devs of Flash player made it so that the actual rotation is returned in interval -180...180.

You might attempt to override rotation setter/getter functions, in order to preserve the passed result as is.

class RotationTest extends Sprite {
    private var myRotation:Number;
    public override function set rotation(value:Number):void {
        super.rotation=value;
        myRotation=value;
    }
    public override function get rotation():Number { return myRotation; }
}