Exemplo n.º 1
0
 public static void GenerateVectors([In][IsReadOnly] ref int size, [In][IsReadOnly] ref float[] distanceField, ref Vector2[] vectorField)
 {
     for (int i = 1; i < size - 1; i++)
     {
         for (int j = 1; j < size - 1; j++)
         {
             float   single   = DistanceField.SampleClamped(distanceField, size, i - 1, j - 1);
             float   single1  = DistanceField.SampleClamped(distanceField, size, i - 1, j);
             float   single2  = DistanceField.SampleClamped(distanceField, size, i - 1, j + 1);
             float   single3  = DistanceField.SampleClamped(distanceField, size, i, j - 1);
             float   single4  = DistanceField.SampleClamped(distanceField, size, i, j + 1);
             float   single5  = DistanceField.SampleClamped(distanceField, size, i + 1, j - 1);
             float   single6  = DistanceField.SampleClamped(distanceField, size, i + 1, j);
             float   single7  = DistanceField.SampleClamped(distanceField, size, i + 1, j + 1);
             float   single8  = single2 + 2f * single4 + single7 - (single + 2f * single3 + single5);
             Vector2 vector2  = new Vector2(-(single5 + 2f * single6 + single7 - (single + 2f * single1 + single2)), -single8);
             Vector2 vector21 = vector2.normalized;
             vectorField[j * size + i] = new Vector2(vector21.x, vector21.y);
         }
     }
     for (int k = 1; k < size - 1; k++)
     {
         vectorField[k] = DistanceField.SampleClamped(vectorField, size, k, 1);
         vectorField[(size - 1) * size + k] = DistanceField.SampleClamped(vectorField, size, k, size - 2);
     }
     for (int l = 0; l < size; l++)
     {
         vectorField[l * size]            = DistanceField.SampleClamped(vectorField, size, 1, l);
         vectorField[l * size + size - 1] = DistanceField.SampleClamped(vectorField, size, size - 2, l);
     }
 }