쫑가 과정

(Euler) 각을 (Quaternion) 값으로 바꾸기 / Quaternion.Euler 본문

Unity/이론

(Euler) 각을 (Quaternion) 값으로 바꾸기 / Quaternion.Euler

쫑가 2022. 1. 13. 19:40

3. Quaternion.Euler


https://docs.unity3d.com/ScriptReference/Quaternion.Euler.html

 

Unity - Scripting API: Quaternion.Euler

Description Returns a rotation that rotates z degrees around the z axis, x degrees around the x axis, and y degrees around the y axis; applied in that order. Description Returns a rotation that rotates z degrees around the z axis, x degrees around the x ax

docs.unity3d.com

public static Quaternion Euler(float x, float y, float z);

z 축을 중심으로 z도, x축을 중심으로 x도, y축을 중심으로 y도 회전하는(Euler angle) 회전(Quaternion)을 반환(return). 

그 순서대로 적용된다.

 

Vector3 회전 값을 Quaternion 값으로 변경한다.


예 1) 설정한 Vector3 회전 값으로 게임 오브젝트 회전하기.

2022.01.12 - [Unity/이론] - 두 회전 사이의 각 구하기 / Quaternion.Angle

 

예 2) Euler <-> Quaternion 변환

Quaternion rotationQuaternion = Quaternion.Euler(new Vector3(0, 30, 0));
Debug.Log(rotationQuaternion);

// QuaternionToEuler.FromQ2는 링크에서 찾아온 함수
Vector3 rotationVector = QuaternionToEuler.FromQ2(rotationQuaternion); 
Debug.Log(rotationVector);
--------------------------
// rotationQuaternion = (0.0, 0.3, 0.0, 0.1)
// rotationVector = (0, 30.0, 0.0)

Quaternion에서 Euler각으로 변환 함수는 아래 링크 참조

https://stackoverflow.com/questions/12088610/conversion-between-euler-quaternion-like-in-unity3d-engine

 

Comments