Exemple #1
0
 public void DrawScreen(Box2D clipFrame, uint points)
 {
     GL.Clear(ClearBufferMask.ColorBufferBit);
     GL.LoadIdentity();
     GL.Enable(EnableCap.Blend);
     GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
     if (null != clipFrame)
     {
         foreach (IDrawable drawable in drawables)
         {
             if (clipFrame.Intersects(drawable.Rect))
             {
                 drawable.Draw();
             }
         }
     }
     else
     {
         foreach (IDrawable drawable in drawables)
         {
             drawable.Draw();
         }
     }
     Print(-0.15f, 0.0f, 0.0f, 0.04f, points.ToString());
     GL.Disable(EnableCap.Blend);
 }
        /// <summary>
        /// Calculates the AABR in the overlap
        /// Returns null if no intersection
        /// </summary>
        /// <param name="rectangleB"></param>
        /// <returns>AABR in the overlap</returns>
        public static Box2D Overlap(this Box2D rectangleA, Box2D rectangleB)
        {
            Box2D overlap = null;

            if (rectangleA.Intersects(rectangleB))
            {
                overlap = new Box2D(0.0f, 0.0f, 0.0f, 0.0f);

                overlap.X = (rectangleA.X < rectangleB.X) ? rectangleB.X : rectangleA.X;
                overlap.Y = (rectangleA.Y < rectangleB.Y) ? rectangleB.Y : rectangleA.Y;

                overlap.SizeX = (rectangleA.MaxX < rectangleB.MaxX) ? rectangleA.MaxX - overlap.X : rectangleB.MaxX - overlap.X;
                overlap.SizeY = (rectangleA.MaxY < rectangleB.MaxY) ? rectangleA.MaxY - overlap.Y : rectangleB.MaxY - overlap.Y;
            }

            return(overlap);
        }
        /// <summary>
        /// If an intersection with the frame occurs do the minimal translation to undo the overlap
        /// </summary>
        /// <param name="rectangleB">The AABR to check for intersect</param>
        public static void UndoOverlap(this Box2D rectangleA, Box2D rectangleB)
        {
            if (rectangleA.Intersects(rectangleB))
            {
                Vector2[] directions = new Vector2[]
                {
                    new Vector2(rectangleB.MaxX - rectangleA.X, 0),
                    new Vector2(rectangleB.X - rectangleA.MaxX, 0),
                    new Vector2(0, rectangleB.MaxY - rectangleA.Y),
                    new Vector2(0, rectangleB.Y - rectangleA.MaxY)
                };

                Vector2 minimum = directions.Aggregate((curMin, x) => (curMin == null || (x.Length) < curMin.Length) ? x : curMin);

                rectangleA.X += minimum.X;
                rectangleA.Y += minimum.Y;
            }
        }