【发布时间】:2009-12-14 22:51:34
【问题描述】:
我正在尝试围绕其中心点在三个维度上旋转 Sprite,并且我正在努力理解 matrix3D 的一些行为。
我已经重写了Sprite的setrotationX、rotationY和rotationZ方法如下:
override public function set rotationX (_rotationX:Number) : void {
this.transform.matrix3D.prependTranslation(this.width/2.0, this.height/2.0, 0);
this.transform.matrix3D.prependRotation(-this.rotationX, Vector3D.X_AXIS);
this.transform.matrix3D.prependRotation(_rotationX, Vector3D.X_AXIS);
this.transform.matrix3D.prependTranslation(-(this.width/2.0), -(this.height/2.0), 0);
}
override public function set rotationY (_rotationY:Number) : void {
this.transform.matrix3D.prependTranslation(this.width/2.0, this.height/2.0, 0);
this.transform.matrix3D.prependRotation(-this.rotationY, Vector3D.Y_AXIS);
this.transform.matrix3D.prependRotation(_rotationY, Vector3D.Y_AXIS);
this.transform.matrix3D.prependTranslation(-(this.width/2.0), -(this.height/2.0), 0);
}
override public function set rotationZ (_rotationZ:Number) : void {
this.transform.matrix3D.prependTranslation(this.width/2.0, this.height/2.0, 0);
this.transform.matrix3D.prependRotation(-this.rotationZ, Vector3D.Z_AXIS);
this.transform.matrix3D.prependRotation(_rotationZ, Vector3D.Z_AXIS);
this.transform.matrix3D.prependTranslation(-(this.width/2.0), -(this.height/2.0), 0);
}
我正在使用 prependTranslation 来校正旋转的中心点,并使用第一个 prependRotation 来取消任何先前应用的旋转。
测试一下,rotationX 完全按照预期工作,Sprite 围绕其水平轴旋转。
rotationY 和 rotationZ 似乎也可以正常工作。但是,有一个问题:每当设置了rotationY 或rotationZ 时,所有其他旋转值也会发生变化。这不是rotationX 的问题——如果我设置了rotationX,其他都不会改变。但是,如果我设置了 rotationY 或 rotationZ,所有的旋转值都会发生变化,这对我的应用程序来说是个问题(它正在尝试保存和恢复值)。
我想我只是对 matrix3D 的情况缺乏一些了解。如何实现这一点,使值之间不存在相互依赖关系?
【问题讨论】:
-
最好的办法是查看UIComponent#transformAround 和相关的AdvancedLayout.as 实现。他们正是这样做的,包装了 Matrix3D。
-
没有查看您的代码,但您是否遇到了 Gimbal Lock 问题? en.wikipedia.org/wiki/Gimbal_lock
标签: apache-flex actionscript-3 3d rotation