Beispiel #1
0
        public Quaternion Rotate(Vector3 euler)
        {
            var        n      = new Coordinate(this);
            Quaternion result = origin;
            Quaternion rot;

            switch (order)
            {
            case EulerOrder.XYZ:
                Debug.LogError("undefined order");
                break;

            case EulerOrder.XZY:
                Debug.LogError("undefined order");
                break;

            case EulerOrder.YXZ:
                // 动态坐标轴 y x z
                rot    = Quaternion.AngleAxis(euler.y, n.up);
                result = rot * result; n *= rot;
                rot    = Quaternion.AngleAxis(euler.x, n.right);
                result = rot * result; n *= rot;
                rot    = Quaternion.AngleAxis(euler.z, n.forward);
                result = rot * result;
                break;

            case EulerOrder.YZX:
                Debug.LogError("undefined order");
                break;

            case EulerOrder.ZXY:
                // 动态坐标轴 z x y
                rot    = Quaternion.AngleAxis(euler.z, n.forward);
                result = rot * result; n *= rot;

                rot    = Quaternion.AngleAxis(euler.x, n.right);
                result = rot * result; n *= rot;

                rot    = Quaternion.AngleAxis(euler.y, n.up);
                result = rot * result;
                break;

            case EulerOrder.ZYX:
                Debug.LogError("undefined order");
                break;

            default:
                Debug.LogError("undefined order");
                break;
            }

            if (MathTool.IsNaN(result))
            {
                Debug.LogError("Nan");
            }

            return(result);
        }
Beispiel #2
0
        public void Rotate()
        {
            if (MathTool.IsNaN(euler))
            {
                Debug.LogError("Nan");
            }

            euler = DOFLiminator.LimitDOF(euler, dof);

            if (MathTool.IsNaN(euler))
            {
                Debug.LogError("Nan"); // 用于断点
            }

            var rot = coord.Rotate(euler);

            if (MathTool.IsNaN(rot))
            {
                Debug.LogError("Nan");
            }
            transform.localRotation = rot;
        }