Quaternion 四元数

Unity内部使用Quaternion来表示旋转,因为它比Matrix更精简,同时也没有Euler的gimbal lock问题。

Quaternion间的运算

transform.rotation *= target.rotation;

Quaternion与Vector3的运算

void Update()
{
    Vector3 worldForward = transform.rotaion * Vector3.forward;
    transform.position += worldForward * Time.deltaTime;
}

常用方法:

public static Quaternion LookRotation(Vector3 forward, Vector3 upwards = Vector3.up);

public static Quaternion FromToRotation(Vector3 fromDirection, Vector3 toDirection);

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

public static Quaternion Slerp(Quaternion a, Quaternion b, float t);

public static float Angle(Quaternion a, Quaternion b);

你可能感兴趣的:(Quaternion 四元数)