Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache flex 如何使用matrix3D在AS3中围绕中心进行三维旋转?_Apache Flex_Actionscript 3_3d_Rotation - Fatal编程技术网

Apache flex 如何使用matrix3D在AS3中围绕中心进行三维旋转?

Apache flex 如何使用matrix3D在AS3中围绕中心进行三维旋转?,apache-flex,actionscript-3,3d,rotation,Apache Flex,Actionscript 3,3d,Rotation,我正试着围绕着一个精灵的中心点旋转一个精灵,我正努力理解matrix3D的一些行为 我覆盖了精灵的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);

我正试着围绕着一个精灵的中心点旋转一个精灵,我正努力理解matrix3D的一些行为

我覆盖了精灵的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);   

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

通过测试,rotationX完全按照预期工作,精灵围绕其水平轴旋转

rotationY和rotationZ也可以正常工作。但是,有一个问题:只要设置了rotationY或rotationZ,所有其他旋转值都会随之更改。这不是rotationX的问题——如果我设置rotationX,其他的都不会改变。但是如果我设置rotationY或rotationZ,所有的旋转值都会改变,这对我的应用程序来说是个问题(它正在尝试保存和恢复值)


我想我只是对matrix3D的进展缺乏一些了解。如何实现这一点,使值之间不存在相互依赖关系?

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

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

这非常简单,您可以尝试使用以下代码:

var matrix3d:Matrix3D = s.transform.matrix3D;
matrix3d.appendRotation( -1, Vector3D.Z_AXIS , new Vector3D( 390, 360, 0 ) );
当s是精灵时,第三个参数,
Vector3D
表示精灵的中心位置


上面的代码将使精灵旋转-1度。

最好的方法是检查和相关的AdvancedLayout.as实现。他们正是这样做的,包装Matrix3D。不查看您的代码,但您是否遇到万向节锁?是的,这容易多了。创建一个支架精灵,然后添加带有x:-mysprite.width*0.5和y:-mysprite.height*0.5的精灵,然后旋转支架