Bis*_*ish 8 apache-flex 3d rotation actionscript-3
我试图围绕其中心点三维旋转一个Sprite,我正在努力理解matrix3D的一些行为.
我已经重写了Sprite的set rotationX,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);
}
Run Code Online (Sandbox Code Playgroud)
我使用prependTranslation来校正旋转的中心点,并使用第一个prependRotation来取消任何先前应用的旋转.
测试它,rotationX完全按预期工作,并且Sprite围绕其水平轴旋转.
rotationY和rotationZ也似乎工作正常.但是,存在一个问题:每当设置rotationY或rotationZ时,所有其他旋转值也会改变.这对rotateX来说不是问题 - 如果我设置了rotationX,则没有其他更改.但是如果我设置了rotationY或者旋转Z,则所有旋转值都会发生变化,这对我的应用程序来说是一个问题(它试图保存和恢复值).
我想我对matrix3D的情况缺乏了解.我如何实现这一点,以便值之间没有相互依赖性?