kingBook

导航

unity 四元数旋转各元素值的计算方法

// 旋转轴
Vector3 axis = Vector3.up;
// 旋转弧度
float rad = 50f * Mathf.Deg2Rad;

Quaternion quaternion = new Quaternion();
quaternion.x = Mathf.Sin(rad / 2f) * axis.x;
quaternion.y = Mathf.Sin(rad / 2f) * axis.y;
quaternion.z = Mathf.Sin(rad / 2f) * axis.z;
quaternion.w = Mathf.Cos(rad / 2f);

transform.rotation = quaternion;
// 相当于
//transform.rotation = Quaternion.Euler(0f, 50f, 0f);

posted on 2023-02-14 22:50  kingBook  阅读(47)  评论(0编辑  收藏  举报