コード例 #1
0
ファイル: Vector2F.cs プロジェクト: zwiglm/NeoAxisEngine
        /// <summary>
        /// Converts a vector into a unit vector.
        /// </summary>
        /// <param name="v">The vector to normalize.</param>
        /// <param name="result">When the method completes, contains the normalized vector.</param>
        public static void Normalize(ref Vector2F v, out Vector2F result)
        {
            float invLength = MathEx.InvSqrt(v.X * v.X + v.Y * v.Y);

            result.X = v.X * invLength;
            result.Y = v.Y * invLength;
        }
コード例 #2
0
ファイル: Vector2F.cs プロジェクト: zwiglm/NeoAxisEngine
        /// <summary>
        /// Converts the current instance of <see cref="Vector2F"/> into a unit vector.
        /// </summary>
        /// <returns>Returns the length of the current instance of <see cref="Vector2F"/>.</returns>
        public float Normalize()
        {
            float sqrLength = X * X + Y * Y;
            float invLength = MathEx.InvSqrt(sqrLength);

            X *= invLength;
            Y *= invLength;
            return(invLength * sqrLength);
        }
コード例 #3
0
ファイル: Vector4F.cs プロジェクト: zwiglm/NeoAxisEngine
        /// <summary>
        /// Converts a vector into a unit vector.
        /// </summary>
        /// <param name="v">The vector to normalize.</param>
        /// <param name="result">When the method completes, contains the normalized vector.</param>
        public static void Normalize(ref Vector4F v, out Vector4F result)
        {
            float invLength = MathEx.InvSqrt(v.X * v.X + v.Y * v.Y + v.Z * v.Z + v.W * v.W);

            result.X = v.X * invLength;
            result.Y = v.Y * invLength;
            result.Z = v.Z * invLength;
            result.W = v.W * invLength;
        }
コード例 #4
0
        public static void Slerp(ref QuaternionF from, ref QuaternionF to, float t, out QuaternionF result)
        {
            QuaternionF temp;
            float       omega, cosom, sinom, scale0, scale1;

            if (t <= 0.0f)
            {
                result = from;
            }
            if (t >= 1.0f)
            {
                result = to;
            }
            if (from == to)
            {
                result = to;
            }

            cosom = from.X * to.X + from.Y * to.Y + from.Z * to.Z + from.W * to.W;
            if (cosom < 0.0f)
            {
                temp  = -to;
                cosom = -cosom;
            }
            else
            {
                temp = to;
            }

            if ((1.0f - cosom) > MathEx.Epsilon)
            {
                scale0 = 1.0f - cosom * cosom;
                sinom  = MathEx.InvSqrt(scale0);
                omega  = MathEx.Atan2(scale0 * sinom, cosom);
                scale0 = MathEx.Sin((1.0f - t) * omega) * sinom;
                scale1 = MathEx.Sin(t * omega) * sinom;
            }
            else
            {
                scale0 = 1.0f - t;
                scale1 = t;
            }

            QuaternionF s1, s2;

            QuaternionF.Multiply(scale0, ref from, out s1);
            QuaternionF.Multiply(scale1, ref temp, out s2);
            QuaternionF.Add(ref s1, ref s2, out result);
            //return ( scale0 * from ) + ( scale1 * temp );
        }
コード例 #5
0
ファイル: Vector2F.cs プロジェクト: zwiglm/NeoAxisEngine
        /// <summary>
        /// Converts the current instance of <see cref="Vector2F"/> into a unit vector and returns the normalized vector.
        /// </summary>
        /// <returns>The normalized instance of <see cref="Vector2F"/>.</returns>
        public Vector2F GetNormalize()
        {
            float invLength = MathEx.InvSqrt(X * X + Y * Y);

            return(new Vector2F(X * invLength, Y * invLength));
        }
コード例 #6
0
ファイル: Vector2F.cs プロジェクト: zwiglm/NeoAxisEngine
        /// <summary>
        /// Converts a vector into a unit vector.
        /// </summary>
        /// <param name="v">The vector to normalize.</param>
        /// <returns>The normalized vector.</returns>
        public static Vector2F Normalize(Vector2F v)
        {
            float invLength = MathEx.InvSqrt(v.X * v.X + v.Y * v.Y);

            return(new Vector2F(v.X * invLength, v.Y * invLength));
        }
コード例 #7
0
ファイル: Vector4F.cs プロジェクト: zwiglm/NeoAxisEngine
        /// <summary>
        /// Converts the current instance of <see cref="Vector4F"/> into a unit vector and returns the normalized vector.
        /// </summary>
        /// <returns>The normalized instance of <see cref="Vector4F"/>.</returns>
        public Vector4F GetNormalize()
        {
            float invLength = MathEx.InvSqrt(X * X + Y * Y + Z * Z + W * W);

            return(new Vector4F(X * invLength, Y * invLength, Z * invLength, W * invLength));
        }
コード例 #8
0
ファイル: Vector4F.cs プロジェクト: zwiglm/NeoAxisEngine
        /// <summary>
        /// Converts a vector into a unit vector.
        /// </summary>
        /// <param name="v">The vector to normalize.</param>
        /// <returns>The normalized vector.</returns>
        public static Vector4F Normalize(Vector4F v)
        {
            float invLength = MathEx.InvSqrt(v.X * v.X + v.Y * v.Y + v.Z * v.Z + v.W * v.W);

            return(new Vector4F(v.X * invLength, v.Y * invLength, v.Z * invLength, v.W * invLength));
        }