微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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变换.

原文地址:https://www.jb51.cc/flex/174241.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐