Actionscript 在 2 个轴上的旋转与 1 个轴不同

发布于 2024-10-01 10:37:13 字数 694 浏览 4 评论 0原文

我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深陷 2024-10-08 10:37:13

旋转是相对于父对象的,当您旋转父对象时,它会更改子对象的参考系。当您仅绕一个轴旋转时,这并不重要,但当您绕两个轴旋转时,就会产生影响。要撤消旋转,您必须按照与应用顺序相反的顺序撤消所有旋转。

尝试用一本书或手机沿一个轴旋转 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文