Advertisement
Glewisguy

Removing parallel MTV's from SAT

Feb 25th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 KB | None | 0 0
  1.         public virtual Vector2 resultantVelocity(List<Vector2> velocities)
  2.         {
  3.             Vector2 resultant = new Vector2(0,0);
  4.  
  5.             for (int i = 0; i < velocities.Count; i++)
  6.             {
  7.                 for (int j = i + 1; j < velocities.Count; j++)
  8.                 {
  9.                     float dot1 = Vector2.Dot(velocities[i], velocities[i]);
  10.                     float dot2 = Vector2.Dot(velocities[j], velocities[j]);
  11.                     float dot3 = Vector2.Dot(velocities[i], velocities[j]);
  12.                     float finalDot = dot1 * dot2 - dot3 * dot3;
  13.  
  14.                     if (finalDot == 0)
  15.                     {
  16.                         if (velocities[i].Length() > velocities[j].Length())
  17.                         {
  18.                             Vector2 newVel = velocities[i] - velocities[j];
  19.                             velocities.Remove(velocities[i]);
  20.                             velocities.Remove(velocities[j]);
  21.                             velocities.Add(newVel);
  22.                         }
  23.                         else
  24.                         {
  25.                             Vector2 newVel = velocities[j] - velocities[i];
  26.                             velocities.Remove(velocities[i]);
  27.                             velocities.Remove(velocities[j]);
  28.                             velocities.Add(newVel);
  29.                         }
  30.                     }
  31.  
  32.                 }
  33.  
  34.                 resultant += velocities[i];
  35.             }
  36.  
  37.  
  38.             return resultant;
  39.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement