【问题标题】:how to do 3D rotation around center in AS3 using matrix3D?如何使用matrix3D在AS3中围绕中心进行3D旋转?
【发布时间】: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 的情况缺乏一些了解。如何实现这一点,使值之间不存在相互依赖关系?

【问题讨论】:

标签: apache-flex actionscript-3 3d rotation


【解决方案1】:

另一个简单的解决方案是在容器精灵中添加对象并将其居中,然后对包含的精灵进行 3D 变换。

【讨论】:

  • 是的,这要容易得多。创建一个支架 Sprite,然后添加带有 x:-mysprite.width*0.5 和 y:-mysprite.height*0.5 的 Sprite,然后旋转支架
【解决方案2】:

我对 AS3 等一无所知。但只是看看你的代码,我想知道你为什么使用我理解的 x 和 y 值(宽度和高度)在 z 轴上进行平移。不应该使用“深度”之类的东西来平移 z 轴吗?

【讨论】:

    【解决方案3】:

    这个很简单,你可以试试下面的代码:

    var matrix3d:Matrix3D = s.transform.matrix3D;
    matrix3d.appendRotation( -1, Vector3D.Z_AXIS , new Vector3D( 390, 360, 0 ) );
    

    虽然s是你的精灵,第三个参数Vector3D表示你的精灵的中心位置。

    上面的代码会使精灵旋转更多-1度。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-07
      • 2018-04-10
      • 2013-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多