수색…


통사론

  • Quaternion.LookRotation (Vector3 forward [, Vector3 up]);
  • Quaternion.AngleAxis (float 각도, Vector3 axisOfRotation);
  • float angleBetween = Quaternion.Angle (Quaternion rotation1, Quaternion rotation2);

쿼터니언 대 오일러 소개

오일러 각은 90도, 180도, 45도, 30도와 같은 "도 각도"입니다. 쿼터니온은 단위 구상의 점을 나타내는 점에서 오일러 각과 다릅니다 (반지름은 1 단위 임). 이 구체를 삼각법에서 배운 Unit circle의 3D 버전으로 생각할 수 있습니다. 쿼터니언은 오일 회전 각을 정의하기 위해 허수를 사용한다는 점에서 오일러 각과 다릅니다.

이것이 복잡하게 들릴 수도 있지만 (틀림없이 그것은있을 수 있습니다), Unity는 오일러 각도와 쿼타니언을 전환 할 수있는 훌륭한 내장 함수와 쿼터니언을 수정하는 함수를 제공합니다.

오일러와 쿼터니언 사이의 변환

// Create a quaternion that represents 30 degrees about X, 10 degrees about Y
Quaternion rotation = Quaternion.Euler(30, 10, 0);

// Using a Vector
Vector3 EulerRotation = new Vector3(30, 10, 0);
Quaternion rotation = Quaternion.Euler(EulerRotation);

// Convert a transfroms Quaternion angles to Euler angles
Quaternion quaternionAngles = transform.rotation;
Vector3 eulerAngles = quaternionAngles.eulerAngles;

왜 쿼터니언을 사용 하는가?

쿼터니언은 짐 벌 잠금으로 알려진 문제를 해결합니다. 이것은 회전의 기본 축이 3 차 회전 축과 동일 선상에있을 때 발생합니다. 다음은 시각적 인 예입니다 @ 2:09

쿼터니언보기 회전

Quaternion.LookRotation(Vector3 forward [, Vector3 up]) 은 정방향 벡터를 앞쪽으로 보이고 Y 축을 'up'벡터와 정렬 한 Quaternion 회전을 생성합니다. 위쪽 벡터가 지정되지 않으면 Vector3.up이 사용됩니다.

이 게임 개체를 회전하여 대상 게임 개체를 봅니다.

// Find a game object in the scene named Target
public Transform target = GameObject.Find("Target").GetComponent<Transform>();

// We subtract our position from the target position to create a
// Vector that points from our position to the target position
// If we reverse the order, our rotation would be 180 degrees off.
Vector3 lookVector = target.position - transform.position;
Quaternion rotation = Quaternion.LookRotation(lookVector);
transform.rotation = rotation;


Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow