Actionscript 在 2 个轴上的旋转与 1 个轴不同
我有 2 个 DisplayObject,其中一个包含另一个,如下代码所示:
var sprite1:Sprite = new Sprite();
sprite1.addChild(loader1); // 假设我已将图片加载到 loader1
loader1.rotationZ = 30;
sprite1.rotationZ = -30; 如果我运行上面的代码,loader1 上的图像看起来就像根本没有旋转一样,因为它的容器以相反的方向旋转。这是正确的,正如我所期望的那样。
但是,如果我对代码进行多轴旋转:
loader1.rotationZ = 30;
loader1.rotationY = 50;
sprite1.rotationZ = -30;
sprite1.rotationY = -50;
现在,loader1 将以不同的角度旋转。我的问题是,为什么它不相互抵消? 请注意,loader1 和 sprite1 的 x,y,z 位置均位于 0,0,0。无论 X、Y 或 Z 旋转如何,都会出现此问题。如果您有 1 个轴,则可以正常工作。 2轴就不行了
我发布此示例代码是因为我试图了解 Flash 如何在 3D 中旋转。在AS3文档中,它声称它围绕其“3D父容器”旋转那是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
旋转是相对于父对象的,当您旋转父对象时,它会更改子对象的参考系。当您仅绕一个轴旋转时,这并不重要,但当您绕两个轴旋转时,就会产生影响。要撤消旋转,您必须按照与应用顺序相反的顺序撤消所有旋转。
尝试用一本书或手机沿一个轴旋转 90 度,然后再旋转一秒。你无法回到起点,你将永远涉及第三轴。
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.