加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 02:13:42 所属栏目:百科 来源:网络整理
导读:我试图围绕其中心点三维旋转一个Sprite,我正在努力理解matrix3D的一些行为. 我已经重写了Sprite的set rotationX,rotationY和rotationZ方法,如下所示: override public function set rotationX (_rotationX:Number) : void { this.transform.matrix3D.prepen
我试图围绕其中心点三维旋转一个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变换.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读