flex – 如何使用matrix3D在AS3中心周围进行3D旋转?

我试图围绕其中心点三维旋转一个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,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),0);   

}

override public function set rotationZ (_rotationZ:Number) : void {

    this.transform.matrix3D.prependTranslation(this.width/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),0);   

}

我正在使用prependTranslation来校正旋转的中心点,并使用第一个prependRotation来取消任何先前应用的旋转.

测试它,rotationX完全按预期工作,并且Sprite围绕其水平轴旋转.

rotationY和rotationZ也似乎工作正常.但是,有一个问题:每当设置rotationY或rotationZ时,所有其他旋转值也会改变.这不是rotateX的问题 – 如果我设置了rotationX,则没有其他任何变化.但是如果我设置了rotationY或者旋转Z,则所有旋转值都会发生变化,这对我的应用程序来说是一个问题(它试图保存和恢复值).

我想我对matrix3D的情况缺乏了解.我怎样才能实现这一点,因此值之间没有相互依存关系?

解决方法

一个简单的解决方案是添加对象并将其置于容器精灵中,并对包含的精灵进行3D变换.

相关文章

一:display:flex布局display:flex是一种布局方式。它即可以...
1. flex设置元素垂直居中对齐在之前的一篇文章中记载过如何...
移动端开发知识点pc端软件和移动端apppc端软件是什么,有哪些...
最近挺忙的,准备考试,还有其他的事,没时间研究东西,快周...
display:flex;把容器设置为弹性盒模型(设置为弹性盒模型之后...
我在网页上运行了一个Flex应用程序,我想使用Command←组合键...