Example #1
0
        private static bool FindMinSepAxis(
      VoltPolygon poly1,
      VoltPolygon poly2,
      out Axis axis)
        {
            axis = new Axis(Vector2.zero, float.NegativeInfinity);

              for (int i = 0; i < poly1.countWorld; i++)
              {
            Axis a = poly1.worldAxes[i];
            float min = float.PositiveInfinity;
            for (int j = 0; j < poly2.countWorld; j++)
            {
              Vector2 v = poly2.worldVertices[j];
              min = Mathf.Min(min, Vector2.Dot(a.Normal, v));
            }
            min -= a.Width;

            if (min > 0)
              return false;
            if (min > axis.Width)
              axis = new Axis(a.Normal, min);
              }

              return true;
        }
Example #2
0
 internal Axis BodyToWorldAxis(Axis axis)
 {
     Vector2 normal = axis.Normal.Rotate(this.facing);
       float width = Vector2.Dot(normal, this.position) + axis.Width;
       return new Axis(normal, width);
 }
Example #3
0
        /// <summary>
        /// Returns the index of the nearest axis on the poly to a point.
        /// Outputs the minimum distance between the axis and the point.
        /// </summary>
        internal static int FindAxisShortestDistance(
      Vector2 point,
      Axis[] axes,
      out float minDistance)
        {
            int ix = 0;
              minDistance = float.PositiveInfinity;
              bool inside = true;

              for (int i = 0; i < axes.Length; i++)
              {
            float dot = Vector2.Dot(axes[i].Normal, point);
            float dist = axes[i].Width - dot;

            if (dist < 0.0f)
              inside = false;

            if (dist < minDistance)
            {
              minDistance = dist;
              ix = i;
            }
              }

              if (inside == true)
              {
            minDistance = 0.0f;
            ix = -1;
              }

              return ix;
        }
Example #4
0
        private static void ComputeAxes(
      Vector2[] vertices,
      int count,
      ref Axis[] destination)
        {
            if (destination.Length < count)
            destination = new Axis[count];

              for (int i = 0; i < count; i++)
              {
            Vector2 u = vertices[i];
            Vector2 v = vertices[(i + 1) % count];
            Vector2 normal = (v - u).Left().normalized;
            destination[i] = new Axis(normal, Vector2.Dot(normal, u));
              }
        }