Esempio n. 1
0
 public void ExecuteTest(Operations operation, int innerIterations, Vector3 v1, Vector3 v2)
 {
     Vector3 res;
     switch (operation)
     {
         case Operations.Add_Operator:
             for (int i = 0; i < innerIterations; i++)
             { res = v1 + v2; res = v1 + v2; res = v1 + v2; res = v1 + v2; res = v1 + v2; res = v1 + v2; res = v1 + v2; res = v1 + v2; res = v1 + v2; res = v1 + v2; }
             break;
         case Operations.Add_Function:
             for (int i = 0; i < innerIterations; i++)
             { Vector3.Add(v1, v2); Vector3.Add(v1, v2); Vector3.Add(v1, v2); Vector3.Add(v1, v2); Vector3.Add(v1, v2); Vector3.Add(v1, v2); Vector3.Add(v1, v2); Vector3.Add(v1, v2); Vector3.Add(v1, v2); Vector3.Add(v1, v2); }
             break;
         case Operations.Sub_Operator:
             for (int i = 0; i < innerIterations; i++)
             { res = v1 - v2; res = v1 - v2; res = v1 - v2; res = v1 - v2; res = v1 - v2; res = v1 - v2; res = v1 - v2; res = v1 - v2; res = v1 - v2; res = v1 - v2; }
             break;
         case Operations.Sub_Function:
             for (int i = 0; i < innerIterations; i++)
             { Vector3.Subtract(v1, v2); Vector3.Subtract(v1, v2); Vector3.Subtract(v1, v2); Vector3.Subtract(v1, v2); Vector3.Subtract(v1, v2); Vector3.Subtract(v1, v2); Vector3.Subtract(v1, v2); Vector3.Subtract(v1, v2); Vector3.Subtract(v1, v2); Vector3.Subtract(v1, v2); }
             break;
         case Operations.Mul_Operator:
             for (int i = 0; i < innerIterations; i++)
             { res = v1 * v2; res = v1 * v2; res = v1 * v2; res = v1 * v2; res = v1 * v2; res = v1 * v2; res = v1 * v2; res = v1 * v2; res = v1 * v2; res = v1 * v2; }
             break;
         case Operations.Mul_Function:
             for (int i = 0; i < innerIterations; i++)
             { Vector3.Multiply(v1, v2); Vector3.Multiply(v1, v2); Vector3.Multiply(v1, v2); Vector3.Multiply(v1, v2); Vector3.Multiply(v1, v2); Vector3.Multiply(v1, v2); Vector3.Multiply(v1, v2); Vector3.Multiply(v1, v2); Vector3.Multiply(v1, v2); Vector3.Multiply(v1, v2); }
             break;
         case Operations.Dot:
             for (int i = 0; i < innerIterations; i++)
             { Vector3.Dot(v1, v2); Vector3.Dot(v1, v2); Vector3.Dot(v1, v2); Vector3.Dot(v1, v2); Vector3.Dot(v1, v2); Vector3.Dot(v1, v2); Vector3.Dot(v1, v2); Vector3.Dot(v1, v2); Vector3.Dot(v1, v2); Vector3.Dot(v1, v2); }
             break;
         case Operations.SquareRoot:
             for (int i = 0; i < innerIterations; i++)
             { Vector3.SquareRoot(v1); Vector3.SquareRoot(v1); Vector3.SquareRoot(v1); Vector3.SquareRoot(v1); Vector3.SquareRoot(v1); Vector3.SquareRoot(v1); Vector3.SquareRoot(v1); Vector3.SquareRoot(v1); Vector3.SquareRoot(v1); Vector3.SquareRoot(v1); }
             break;
         case Operations.Length_Squared:
             for (int i = 0; i < innerIterations; i++)
             { v1.LengthSquared(); v1.LengthSquared(); v1.LengthSquared(); v1.LengthSquared(); v1.LengthSquared(); v1.LengthSquared(); v1.LengthSquared(); v1.LengthSquared(); v1.LengthSquared(); v1.LengthSquared(); }
             break;
         case Operations.Normalize:
             for (int i = 0; i < innerIterations; i++)
             { Vector3.Normalize(v1); Vector3.Normalize(v1); Vector3.Normalize(v1); Vector3.Normalize(v1); Vector3.Normalize(v1); Vector3.Normalize(v1); Vector3.Normalize(v1); Vector3.Normalize(v1); Vector3.Normalize(v1); Vector3.Normalize(v1); }
             break;
         case Operations.Distance_Squared:
             for (int i = 0; i < innerIterations; i++)
             { Vector3.DistanceSquared(v1, v2); Vector3.DistanceSquared(v1, v2); Vector3.DistanceSquared(v1, v2); Vector3.DistanceSquared(v1, v2); Vector3.DistanceSquared(v1, v2); Vector3.DistanceSquared(v1, v2); Vector3.DistanceSquared(v1, v2); Vector3.DistanceSquared(v1, v2); Vector3.DistanceSquared(v1, v2); Vector3.DistanceSquared(v1, v2); }
             break;
         case Operations.Cross:
             for (int i = 0; i < innerIterations; i++)
             { Vector3.Cross(v1, v2); Vector3.Cross(v1, v2); Vector3.Cross(v1, v2); Vector3.Cross(v1, v2); Vector3.Cross(v1, v2); Vector3.Cross(v1, v2); Vector3.Cross(v1, v2); Vector3.Cross(v1, v2); Vector3.Cross(v1, v2); Vector3.Cross(v1, v2); }
             break;
     }
 }
Esempio n. 2
0
    public static Vector3 Random3DNormal()
    {
        // See https://stackoverflow.com/questions/5408276/sampling-uniformly-distributed-random-points-inside-a-spherical-volume
        var phi      = ThreadSafeRandom.NextDouble() * 2 * Math.PI; // Random angle (radians) in [0,360)
        var costheta = ThreadSafeRandom.NextDouble() * 2 - 1;       // Random point in [-1,1)

        var theta  = Math.Acos(costheta);
        var result = new Vector3(
            (float)(Math.Sin(theta) * Math.Cos(phi)),
            (float)(Math.Sin(theta) * Math.Sin(phi)),
            (float)Math.Cos(theta)
            );

        Debug.Assert(MathF.Abs(result.LengthSquared() - 1) < 0.001f);
        return(result);
    }