1

I have 2 DisplayObject, one containing the other like the code below:

var sprite1:Sprite = new Sprite();

sprite1.addChild(loader1); // assume that I have load picture on to loader1

loader1.rotationZ = 30;

sprite1.rotationZ = -30; If I run the code above, the image on loader1 will look just like it hasn't been rotate at all because its container rotate in opposite direction. Which is correct, as what I expected.

But, if I had multiple axis rotation to the code:

loader1.rotationZ = 30;

loader1.rotationY = 50;

sprite1.rotationZ = -30;

sprite1.rotationY = -50;

Now, loader1 will rotate in different angle. My question is, why it doesn't offset each other? Note that, both loader1 and sprite1's x,y,z position are all at 0,0,0. And this problem occurs regardless of rotationX,Y or Z. If you have 1 axis, it works fine. 2 axis, it won't.

I post this sample code because I'm trying to understand how Flash rotate in 3D. In AS3 document, it claims that it rotate around its "3D parent container" What is that?

ohm
  • 43
  • 3
  • 9
  • i'm pretty sure the problem here has to do with the multiplication of matrices, which can be really tricky. hopefully someone with a wider knowledge of 3D will be able to give you a definitive answer. are you not able to load your images as independent display objects positioned above your rotating sprites? – Chunky Chunk Nov 09 '10 at 04:53
  • My actual problem is too complex to explain or put down sample code. But just this point that cause the errors. I would like to understand how it works thorough – ohm Nov 09 '10 at 11:07

1 Answers1

0

Rotation is relative to the parent, and when you rotate the parent object it will change the frame of reference for the child. This doesn't matter when you are only rotating around one axis, but makes a difference when you rotate around two. To undo the rotations, you have to undo all of them, in the reverse order that they were applied.

Try it with a book, or your phone, rotating by 90 degrees on one axis, then a second. You can't get back to where you started and you will always have involved the 3rd axis.

Peter Hall
  • 53,120
  • 14
  • 139
  • 204