2009-12-14 4 views
8

스프라이트를 중심점을 중심으로 3 차원으로 회전하려고하는데 matrix3D의 일부 동작을 이해하려고 애 쓰고 있습니다.matrix3D를 사용하여 AS3에서 중심을 중심으로 3D 회전을 수행하는 방법은 무엇입니까?

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 어떤 previously-을 취소하려면 다음과 같이

필자는 스프라이트 세트의 rotationX,의 rotationY 및 rotationZ 방법을 오버라이드 (override) 적용된 회전.

테스트 결과, rotationX는 예상대로 작동하고 Sprite는 수평 축을 중심으로 회전합니다.

rotateY 및 rotationZ도 정상적으로 작동하는 것으로 보입니다. 그러나 rotationY 또는 rotationZ가 설정 될 때마다 다른 모든 회전 값도 변경됩니다. 이 문제는 rotationX에서는 문제가되지 않습니다. rotationX를 설정하면 아무 것도 변경되지 않습니다. 그러나 rotateY 또는 rotationZ를 설정하면 회전 값이 모두 변경됩니다. 이는 내 앱 (값을 저장하고 복원하려고 시도하는 경우)의 문제입니다.

matrix3D에서 어떤 일이 벌어지고 있는지에 대한 이해가 부족하다고 생각합니다. 이 값을 상호 의존성이 없도록 구현하려면 어떻게해야합니까?

+0

가장 좋은 것은 [UIComponent # transformAround] (http://opensource.adobe.com/svn/opensource/flex/sdk/trunk/frameworks/projects/framework/src/mx/core/UIComponent.as)를 확인하는 것입니다.) 및 관련 AdvancedLayout.as 구현. Matrix3D를 감싸는 것과 똑같습니다. –

+0

코드를 살펴 보지 않았지만 Gimbal Lock을 경험하고 있습니까? http://en.wikipedia.org/wiki/Gimbal_lock –

답변

3

또 다른 쉬운 해결책은 객체를 추가하고 컨테이너 스프라이트에 센터를 배치하고 포함하는 스프라이트에 3D 변형을 수행하는 것입니다.

+0

예. 이것은 훨씬 쉽습니다. 홀더 Sprite를 만든 다음 x : -mysprite.width * 0.5 및 y : -mysprite.height * 0.5를 사용하여 Sprite를 추가 한 다음 홀더를 회전합니다 – daidai

1

AS3 등은 아무것도 모르지만 코드를 보면 x 및 y 값 (너비 및 높이)으로 이해하는 것을 사용하여 왜 z 축에서 변환하는지 궁금합니다. "깊이"와 같은 것을 사용하여 z 축을 변환해서는 안됩니까?

0

이 매우 간단합니다, 당신은 다음 코드를 사용하여 시도 할 수 있습니다 :

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

동안의 당신의 스프라이트, 세 번째 매개 변수입니다 Vector3D은 스프라이트의 중심 위치를 나타냅니다.

위의 코드는 스프라이트가 -1도 회전하도록합니다.

관련 문제