예제 #1
0
        public override void RecalculateBounds()
        {
            Matrix transform = TranslateFrom;

            bool firstIteration = true;

            OuterRadiusVector = VectorUtility.Zero;
            float   outerRadius = 0;
            Vector2 tempOuterRadius;

            ActualCenter = Vector2.Transform(ReferenceRegion.Center, transform);

            for (int i = 0; i < NumSides; i++)
            {
                _actualVertices[i] = Vector2.Transform(ReferenceRegion.Vertices[i], transform);
                if (firstIteration)
                {
                    LowestX        = _actualVertices[i].X;
                    LowestY        = _actualVertices[i].Y;
                    HighestX       = _actualVertices[i].X;
                    HighestY       = _actualVertices[i].Y;
                    firstIteration = false;
                }
                else
                {
                    LowestX  = MathHelper.Min(LowestX, _actualVertices[i].X);
                    LowestY  = MathHelper.Min(LowestY, _actualVertices[i].Y);
                    HighestX = MathHelper.Max(HighestX, _actualVertices[i].X);
                    HighestY = MathHelper.Max(HighestY, _actualVertices[i].Y);
                }

                tempOuterRadius = (_actualVertices[i] - ActualCenter);
                if (tempOuterRadius.Length() > outerRadius)
                {
                    outerRadius       = tempOuterRadius.Length();
                    OuterRadiusVector = tempOuterRadius;
                }
            }

            InnerRadiusVector = ShapeUtility.FindClosestPointOnPolygon(ActualCenter, _actualVertices, NumSides) - ActualCenter;
        }
예제 #2
0
 public Vector2 FindClosestPoint(Vector2 point)
 {
     return(ShapeUtility.FindClosestPointOnPolygon(point, this));
 }