Exemplo n.º 1
0
        /// <summary>
        /// 轴向旋转
        /// </summary>
        /// <param name="angle"></param>
        /// <param name="axis"></param>
        /// <returns></returns>
        public static LQuaternion AngleAxis(LFloat angle, LVector3 axis)
        {
            axis  = axis.normalized;
            angle = angle * LMath.Deg2Rad;

            LQuaternion q = new LQuaternion();

            LFloat halfAngle = angle * LFloat.half;
            LFloat s         = LMath.Sin(halfAngle);

            q.w = LMath.Cos(halfAngle);
            q.x = s * axis.x;
            q.y = s * axis.y;
            q.z = s * axis.z;

            return(q);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 欧拉角转四元数
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <returns></returns>
        public static LQuaternion Euler(LFloat x, LFloat y, LFloat z)
        {
            LFloat cX = LMath.Cos(x * LMath.PI / 360);
            LFloat sX = LMath.Sin(x * LMath.PI / 360);

            LFloat cY = LMath.Cos(y * LMath.PI / 360);
            LFloat sY = LMath.Sin(y * LMath.PI / 360);

            LFloat cZ = LMath.Cos(z * LMath.PI / 360);
            LFloat sZ = LMath.Sin(z * LMath.PI / 360);

            LQuaternion qX = new LQuaternion(sX, LFloat.zero, LFloat.zero, cX);
            LQuaternion qY = new LQuaternion(LFloat.zero, sY, LFloat.zero, cY);
            LQuaternion qZ = new LQuaternion(LFloat.zero, LFloat.zero, sZ, cZ);

            LQuaternion q = (qY * qX) * qZ;

            return(q);
        }
Exemplo n.º 3
0
 static void TestLutCos()
 {
     TestLut((i) => i * 0.001f * Mathf.PI * 2 - Mathf.PI, (p) => Mathf.Cos(p), (p) => LMath.Cos(p.ToLFloat()));
 }