Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public virtual Vector2 resultantVelocity(List<Vector2> velocities)
- {
- Vector2 resultant = new Vector2(0,0);
- for (int i = 0; i < velocities.Count; i++)
- {
- for (int j = i + 1; j < velocities.Count; j++)
- {
- float dot1 = Vector2.Dot(velocities[i], velocities[i]);
- float dot2 = Vector2.Dot(velocities[j], velocities[j]);
- float dot3 = Vector2.Dot(velocities[i], velocities[j]);
- float finalDot = dot1 * dot2 - dot3 * dot3;
- if (finalDot == 0)
- {
- if (velocities[i].Length() > velocities[j].Length())
- {
- Vector2 newVel = velocities[i] - velocities[j];
- velocities.Remove(velocities[i]);
- velocities.Remove(velocities[j]);
- velocities.Add(newVel);
- }
- else
- {
- Vector2 newVel = velocities[j] - velocities[i];
- velocities.Remove(velocities[i]);
- velocities.Remove(velocities[j]);
- velocities.Add(newVel);
- }
- }
- }
- resultant += velocities[i];
- }
- return resultant;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement