/// <summary>
    /// Smooths out the vector by converging all values to the smallest value
    /// </summary>
    /// <param name="vec"></param>
    /// <param name="smoothness">1 = all values are the same.. 0 = nothing changes</param>
    /// <returns></returns>
    public static Vector3 VectorSmooth(Vector3 vec, float smoothness)
    {
        Vector3 smoothedVector = vec;
        Vector3 signVector     = VectorUtilities.Sign(vec);

        smoothedVector = VectorUtilities.Abs(smoothedVector);

        float minValue = VectorUtilities.VectorMin(smoothedVector);

        smoothedVector.x -= (smoothedVector.x - minValue) * .5f;
        smoothedVector.y -= (smoothedVector.y - minValue) * .5f;
        smoothedVector.z -= (smoothedVector.z - minValue) * .5f;

        smoothedVector.x = signVector.x * smoothedVector.x;
        smoothedVector.y = signVector.y * smoothedVector.y;
        smoothedVector.z = signVector.z * smoothedVector.z;

        return(Vector3.Lerp(vec, smoothedVector, smoothness));
    }
Exemple #2
0
 public static void AbsTest()
 {
     Assert.That(() => VectorUtilities.Abs(Vector128.Create(-1.0f, 2.0f, -3.0f, 4.0f)),
                 Is.EqualTo(Vector128.Create(1.0f, 2.0f, 3.0f, 4.0f))
                 );
 }