Ejemplo n.º 1
0
        private static bool FindMinSepAxis(
            VoltPolygon poly1,
            VoltPolygon poly2,
            out Axis axis)
        {
            axis = new Axis(VoltVector2.zero, Fix64.MinValue);

            for (int i = 0; i < poly1.countWorld; i++)
            {
                Axis  a   = poly1.worldAxes[i];
                Fix64 min = Fix64.MaxValue;
                for (int j = 0; j < poly2.countWorld; j++)
                {
                    VoltVector2 v = poly2.worldVertices[j];
                    min = VoltMath.Min(min, VoltVector2.Dot(a.Normal, v));
                }
                min -= a.Width;

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

            return(true);
        }
Ejemplo n.º 2
0
 public static VoltAABB CreateMerged(VoltAABB aabb1, VoltAABB aabb2)
 {
     return(new VoltAABB(
                VoltMath.Max(aabb1.top, aabb2.top),
                VoltMath.Min(aabb1.bottom, aabb2.bottom),
                VoltMath.Min(aabb1.left, aabb2.left),
                VoltMath.Max(aabb1.right, aabb2.right)));
 }
Ejemplo n.º 3
0
        private static VoltAABB ComputeBounds(
            VoltVector2[] vertices,
            int count)
        {
            Fix64 top    = vertices[0].y;
            Fix64 bottom = vertices[0].y;
            Fix64 left   = vertices[0].x;
            Fix64 right  = vertices[0].x;

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

            return(new VoltAABB(top, bottom, left, right));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Builds the AABB by combining all the shape AABBs.
        /// </summary>
        private void UpdateAABB()
        {
            Fix64 top    = Fix64.MinValue;
            Fix64 right  = Fix64.MaxValue;
            Fix64 bottom = Fix64.MaxValue;
            Fix64 left   = Fix64.MinValue;

            for (int i = 0; i < this.shapeCount; i++)
            {
                VoltAABB aabb = this.shapes[i].AABB;

                top    = VoltMath.Max(top, aabb.Top);
                right  = VoltMath.Max(right, aabb.Right);
                bottom = VoltMath.Min(bottom, aabb.Bottom);
                left   = VoltMath.Min(left, aabb.Left);
            }

            this.AABB = new VoltAABB(top, bottom, left, right);
        }
Ejemplo n.º 5
0
 private static Fix64 BiasDist(Fix64 dist)
 {
     return(VoltConfig.ResolveRate * VoltMath.Min(Fix64.Zero, dist + VoltConfig.ResolveSlop));
 }