Le 14 juil. 08 à 18:57, John Clayton a écrit :

Hi All,

I'm setting the rotation values of a CALayer, and notice that when setting the Y component of rotation of a CATransform3D structure via the :
        [layer setValue:someValue forKeyPath:@"transform.rotation.y"]

call, that in certain cases of 'someValue' (the y rotation), the X and Z rotation values are modified as well.

I set the value of the transform.rotation.Y using the standard setValue:forKeyPath: method, and logged the resulting X, Y and Z rotation values. Here's the code and logging results:

- (void) awakeFromNib {
        CALayer* testLayer = [CALayer new];
        NSLog(@"before: x, y, x = %@ / %@ / %@",
                  [testLayer valueForKeyPath:@"transform.rotation.x"],
                  [testLayer valueForKeyPath:@"transform.rotation.y"],
                  [testLayer valueForKeyPath:@"transform.rotation.z"]);

        // but this breaks the X and Z, how come?
[testLayer setValue:[NSNumber numberWithDouble:2.12041] forKeyPath:@"transform.rotation.y"];
        NSLog(@"after: x, y, x = %@ / %@ / %@",
                  [testLayer valueForKeyPath:@"transform.rotation.x"],
                  [testLayer valueForKeyPath:@"transform.rotation.y"],
                  [testLayer valueForKeyPath:@"transform.rotation.z"]);

        [testLayer release];
}

2008-07-14 17:48:23.555 Annotate[42997:10b] before: x, y, x = 0 / -0 / 0 2008-07-14 17:48:23.562 Annotate[42997:10b] after: x, y, x = 3.141593 / 1.021183 / 3.141593

Huh?

Question 1: Why do X and Z get very close to PI?
Question 2: Why does Y end up being 1.02 when I set it to 2.12041?

Does anyone know what's going on here? I'm a little stumped by this one.

Hello,

I never used CALayer but if I understand correctly the rotation, there is no difference between

rotation (A) : x, y, x = 0 / 2.12041 / 0

and

rotation (B) : x, y, x = 3.141593 / 1.021183 / 3.141593

It's because a rotation of pi is a half-circle rotation and 1.021183 is equal to pi-2.12041. So the two transformation are equals. But why the layer transform the rotation like this. It has to be a internal check like in 2D when you want the angle of rotation to stay between - pi and pi.

You can check the equality by doing the transformation for an arbitrary point, or calculating the transformation matrix.

rot(A) : x,y,z = 0 , a , 0

        (cos a  0  -sin a  0)
R(A) =  (    0  1       0  0)
        (sin a  0   cos a  0)
        (    0  0       0  1)

rot(B) : x,y,z = pi, pi-a, pi

(1 0 0 0) (cos pi-a 0 -sin pi-a 0) ( cos pi sin pi 0 0) R(B) = (0 cos pi sin pi 0) ( 0 1 0 0) (-sin pi cos pi 0 0) (0 -sin pi cos pi 0) (sin pi-a 0 cos pi-a 0) ( 0 0 1 0) (0 0 0 1) ( 0 0 0 1) ( 0 0 0 1)

        (1   0   0  0) (-cos a  0  -sin a  0) (-1   0  0  0)
R(B) =  (0  -1   0  0) (     0  1       0  0) ( 0  -1  0  0)
        (0   0  -1  0) ( sin a  0  -cos a  0) ( 0   0  1  0)
        (0   0   0  1) (     0  0       0  1) ( 0   0  0  1)

        (-cos a   0  -sin a  0) (-1   0  0  0)
R(B) =  (     0  -1       0  0) ( 0  -1  0  0)
        (-sin a   0   cos a  0) ( 0   0  1  0)
        (     0   0       0  1) ( 0   0  0  1)

        (cos a  0  -sin a  0)
R(B) =  (    0  1       0  0)
        (sin a  0   cos a  0)
        (    0  0       0  1)

And you have R(A) = R(B)

Frédéric Testuz_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to