コード例 #1
0
        /// <summary>
        /// Cals the angle with axis y.
        /// </summary>
        /// <returns>The angle with axis y.</returns>
        /// <param name="forward">Forward.</param>
        public static float CalAngleWithAxisY(UVector3 forward)
        {
            forward.y = 0;
            forward.Normalized();
            var acos = Math.Acos(forward.z) * MathHelper.Rad2Deg;

            if (forward.x > 0)
            {
                return((float)acos);
            }
            else
            {
                return(360f - (float)(acos));
            }
        }
コード例 #2
0
ファイル: UQuaternion.cs プロジェクト: mengtest/UMath
        /// <summary>
        /// Angles the axis.
        /// </summary>
        /// <returns>The axis.</returns>
        /// <param name="angle">Angle.</param>
        /// <param name="axis">Axis.</param>
        public static UQuaternion AngleAxis(float angle, UVector3 axis)
        {
            if (Math.Abs(axis.sqrMagnitude) < MathHelper.Epsilon)
            {
                return(identity);
            }

            axis.Normalized();
            var   sin = (float)Math.Sin(angle * MathHelper.Deg2Rad * 0.5f);
            var   cos = (float)Math.Cos(angle * MathHelper.Deg2Rad * 0.5f);
            float w   = cos;
            float x   = axis.x * sin;
            float y   = axis.y * sin;
            float z   = axis.z * sin;

            return(new UQuaternion(x, y, z, w));
        }