Beispiel #1
0
        private static bool FindMinSepAxis(
            VoltPolygon poly1,
            VoltPolygon poly2,
            out Axis axis)
        {
            axis = new Axis(TSVector2.zero, FP.NegativeInfinity);

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

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

            return(true);
        }
Beispiel #2
0
 public static VoltAABB CreateMerged(VoltAABB aabb1, VoltAABB aabb2)
 {
     return(new VoltAABB(
                TSMath.Max(aabb1.top, aabb2.top),
                TSMath.Min(aabb1.bottom, aabb2.bottom),
                TSMath.Min(aabb1.left, aabb2.left),
                TSMath.Max(aabb1.right, aabb2.right)));
 }
Beispiel #3
0
        /// <summary>
        /// Builds the AABB by combining all the shape AABBs.
        /// </summary>
        private void UpdateAABB()
        {
            FP top    = FP.NegativeInfinity;
            FP right  = FP.NegativeInfinity;
            FP bottom = FP.PositiveInfinity;
            FP left   = FP.PositiveInfinity;

            for (int i = 0; i < this.shapeCount; i++)
            {
                VoltAABB aabb = this.shapes[i].AABB;
                top    = TSMath.Max(top, aabb.Top);
                right  = TSMath.Max(right, aabb.Right);
                bottom = TSMath.Min(bottom, aabb.Bottom);
                left   = TSMath.Min(left, aabb.Left);
            }

            this.AABB = new VoltAABB(top, bottom, left, right);
        }
        private static VoltAABB ComputeBounds(
            TSVector2[] vertices,
            int count)
        {
            FP top    = vertices[0].y;
            FP bottom = vertices[0].y;
            FP left   = vertices[0].x;
            FP right  = vertices[0].x;

            for (int i = 1; i < count; i++)
            {
                top    = TSMath.Max(top, vertices[i].y);
                bottom = TSMath.Min(bottom, vertices[i].y);
                left   = TSMath.Min(left, vertices[i].x);
                right  = TSMath.Max(right, vertices[i].x);
            }

            return(new VoltAABB(top, bottom, left, right));
        }
Beispiel #5
0
 public static void Min(ref TSVector2 value1, ref TSVector2 value2, out TSVector2 result)
 {
     result.x = TSMath.Min(value1.x, value2.x);
     result.y = TSMath.Min(value1.y, value2.y);
 }
Beispiel #6
0
 public static TSVector2 Min(TSVector2 value1, TSVector2 value2)
 {
     return(new TSVector2(
                TSMath.Min(value1.x, value2.x),
                TSMath.Min(value1.y, value2.y)));
 }
Beispiel #7
0
 private static FP BiasDist(FP dist)
 {
     return(VoltConfig.ResolveRate * TSMath.Min(0, dist + VoltConfig.ResolveSlop));
 }