示例#1
0
        /// <summary>
        /// Zwraca ujemną głębokość kolizji w pionie między dwoma prostokątami
        /// </summary>
        /// <param name="rectA">Prostokąt A</param>
        /// <param name="rectB">Prostokąt B</param>
        /// <returns>-1 * Głębokość kolizji w pikselach</returns>
        public static float GetVerticalIntersectionDepth(this BoundingRect rectA, BoundingRect rectB)
        {
            // Calculate half sizes.
            float halfHeightA = rectA.Height/2.0f;
            float halfHeightB = rectB.Height/2.0f;

            // Calculate centers.
            float centerA = rectA.Top + halfHeightA;
            float centerB = rectB.Top + halfHeightB;

            // Calculate current and minimum-non-intersecting distances between centers.
            float distanceY = centerA - centerB;
            float minDistanceY = halfHeightA + halfHeightB;

            // If we are not intersecting at all, return (0, 0).
            if (Math.Abs(distanceY) >= minDistanceY)
                return 0f;

            // Calculate and return intersection depths.
            return distanceY > 0 ? minDistanceY - distanceY : -minDistanceY - distanceY;
        }
示例#2
0
        /// <summary>
        /// Zwraca ujemną głębokość kolizji w poziomie między dwoma prostokątami
        /// </summary>
        /// <param name="rectA">Prostokąt A</param>
        /// <param name="rectB">Prostokąt B</param>
        /// <returns>-1 * Głębokość kolizji w pikselach</returns>
        public static float GetHorizontalIntersectionDepth(this BoundingRect rectA, BoundingRect rectB)
        {
            // Calculate half sizes.
            float halfWidthA = rectA.Width/2.0f;
            float halfWidthB = rectB.Width/2.0f;

            // Calculate centers.
            float centerA = rectA.Left + halfWidthA;
            float centerB = rectB.Left + halfWidthB;

            // Calculate current and minimum-non-intersecting distances between centers.
            float distanceX = centerA - centerB;
            float minDistanceX = halfWidthA + halfWidthB;

            // If we are not intersecting at all, return (0, 0).
            if (Math.Abs(distanceX) >= minDistanceX)
                return 0f;

            // Calculate and return intersection depths.
            return distanceX > 0 ? minDistanceX - distanceX : -minDistanceX - distanceX;
        }
示例#3
0
 public bool Equals(BoundingRect other)
 {
     return
         (this.Min.X == other.Min.X) &&
         (this.Min.Y == other.Min.Y) &&
         (this.Max.X == other.Max.X) &&
         (this.Max.Y == other.Max.Y);
 }
示例#4
0
 public void Contains(ref BoundingRect rect, out bool result)
 {
     result =
         (this.Min.X <= rect.Min.X) &&
         (this.Min.Y <= rect.Min.Y) &&
         (this.Max.X >= rect.Max.X) &&
         (this.Max.Y >= rect.Max.Y);
 }
示例#5
0
 static BoundingRect()
 {
     BoundingRect.mEmpty = new BoundingRect();
     BoundingRect.mMinMax = new BoundingRect(Vector2.One*float.MinValue, Vector2.One*float.MaxValue);
 }
示例#6
0
 public bool Contains(BoundingRect rect)
 {
     return
         (this.Min.X <= rect.Min.X) &&
         (this.Min.Y <= rect.Min.Y) &&
         (this.Max.X >= rect.Max.X) &&
         (this.Max.Y >= rect.Max.Y);
 }
示例#7
0
        public static void Union(ref BoundingRect rect1, ref BoundingRect rect2, out BoundingRect result)
        {
            float num6 = rect1.Max.X;
            float num5 = rect2.Max.X;
            float num4 = rect1.Max.Y;
            float num3 = rect2.Max.Y;
            float num2 = (rect1.Min.X < rect2.Min.X) ? rect1.Min.X : rect2.Min.X;
            float num = (rect1.Min.Y < rect2.Min.Y) ? rect1.Min.Y : rect2.Min.Y;
            float num8 = (num6 > num5) ? num6 : num5;
            float num7 = (num4 > num3) ? num4 : num3;

            result.Min.X = num2;
            result.Min.Y = num;
            result.Max.X = num8;
            result.Max.Y = num7;
        }
示例#8
0
        public static BoundingRect Union(BoundingRect rect1, BoundingRect rect2)
        {
            BoundingRect result;

            float num6 = rect1.Max.X;
            float num5 = rect2.Max.X;
            float num4 = rect1.Max.Y;
            float num3 = rect2.Max.Y;
            float num2 = (rect1.Min.X < rect2.Min.X) ? rect1.Min.X : rect2.Min.X;
            float num = (rect1.Min.Y < rect2.Min.Y) ? rect1.Min.Y : rect2.Min.Y;
            float num8 = (num6 > num5) ? num6 : num5;
            float num7 = (num4 > num3) ? num4 : num3;

            result.Min.X = num2;
            result.Min.Y = num;
            result.Max.X = num8;
            result.Max.Y = num7;

            return result;
        }
示例#9
0
文件: Level.cs 项目: Bajena/Miner
        /// <summary>
        /// Zwraca kafelki otaczające dany prostokąt na planszy
        /// </summary>
        /// <param name="rectangle"></param>
        /// <returns></returns>
        public List<Tile> GetSurroundingTiles(BoundingRect rectangle)
        {
            int leftTile = (int)Math.Floor(rectangle.Left / _tileDimensions.X);
            int rightTile = (int)Math.Ceiling((rectangle.Right / _tileDimensions.X)) - 1;
            int topTile = (int)Math.Floor(rectangle.Top / _tileDimensions.Y);
            int bottomTile = (int)Math.Ceiling((rectangle.Bottom / _tileDimensions.Y)) - 1;

            leftTile = leftTile >= 0 ? leftTile : 0;
            rightTile = rightTile < Tiles.GetLength(0) ? rightTile : Tiles.GetLength(0) - 1;
            topTile = topTile >= 0 ? topTile : 0;
            bottomTile = bottomTile < Tiles.GetLength(1) ? bottomTile : Tiles.GetLength(1) - 1;

            var tileList = new List<Tile>();

            for (int y = topTile; y <= bottomTile; ++y)
            {
                for (int x = leftTile; x <= rightTile; ++x)
                {
                    tileList.Add(Tiles[x, y]);
                }
            }

            return tileList;
        }
示例#10
0
        public static BoundingRect Intersect(BoundingRect rect1, BoundingRect rect2)
        {
            BoundingRect result;

            float num8 = rect1.Max.X;
            float num7 = rect2.Max.X;
            float num6 = rect1.Max.Y;
            float num5 = rect2.Max.Y;
            float num2 = (rect1.Min.X > rect2.Min.X) ? rect1.Min.X : rect2.Min.X;
            float num = (rect1.Min.Y > rect2.Min.Y) ? rect1.Min.Y : rect2.Min.Y;
            float num4 = (num8 < num7) ? num8 : num7;
            float num3 = (num6 < num5) ? num6 : num5;

            if ((num4 > num2) && (num3 > num))
            {
                result.Min.X = num2;
                result.Min.Y = num;
                result.Max.X = num4;
                result.Max.Y = num3;

                return result;
            }

            result.Min.X = 0;
            result.Min.Y = 0;
            result.Max.X = 0;
            result.Max.Y = 0;

            return result;
        }
示例#11
0
        private void UpdateBoundingBox()
        {
            var boundingBox = ParentObject.BoundingBox;

            if (CollisionBox != Rectangle.Empty)
                boundingBox = new BoundingRect(_position.X, _position.Y, CollisionBox.Width * Scale, CollisionBox.Height * Scale);
            else
            {
                boundingBox = new BoundingRect(_position.X, _position.Y, _currentAnimation.CurrentFrame.Width * Scale, _currentAnimation.CurrentFrame.Height * Scale);
            }
            ParentObject.BoundingBox = boundingBox;
        }
示例#12
0
        public override void Draw(SpriteBatch spriteBatch)
        {
            _position = ParentObject.Position;
            _velocity = ParentObject.Velocity;

            var boundingBox = new BoundingRect(_position.X-CollisionBox.X, _position.Y-CollisionBox.Y, _currentAnimation.CurrentFrame.Width * Scale, _currentAnimation.CurrentFrame.Height * Scale);

            spriteBatch.Draw(_currentAnimation.SpriteSheet, new Vector2(boundingBox.Left + boundingBox.Width / 2, boundingBox.Top + boundingBox.Height / 2),
                    _currentAnimation.CurrentFrame, Color.White, _rotation, new Vector2(boundingBox.Width / 2, boundingBox.Height / 2), Scale, _spriteEffect, 0);
        }
示例#13
0
 /// <summary>
 /// Sprawdza głębokość kolizji między dwoma prostokątami
 /// </summary>
 /// <param name="rectA">Prostokąt A</param>
 /// <param name="rectB">Prostokąt B</param>
 /// <param name="direction">Testowany kierunek</param>
 /// <param name="depth">Zwracana głębokość kolizji</param>
 /// <returns>Zwraca true, jeśli jest kolizja między prostokątami</returns>
 public static bool Intersects(this BoundingRect rectA, BoundingRect rectB, EDirection direction, out Vector2 depth)
 {
     depth = direction == EDirection.Vertical
         ? new Vector2(0, rectA.GetVerticalIntersectionDepth(rectB))
         : new Vector2(rectA.GetHorizontalIntersectionDepth(rectB), 0);
     return depth.Y != 0 || depth.X != 0;
 }
示例#14
0
 public bool Intersects(BoundingRect rect)
 {
     return
         (this.Min.X < rect.Max.X) &&
         (this.Min.Y < rect.Max.Y) &&
         (this.Max.X > rect.Min.X) &&
         (this.Max.Y > rect.Min.Y);
 }
示例#15
0
        public static void Intersect(ref BoundingRect rect1, ref BoundingRect rect2, out BoundingRect result)
        {
            float num8 = rect1.Max.X;
            float num7 = rect2.Max.X;
            float num6 = rect1.Max.Y;
            float num5 = rect2.Max.Y;
            float num2 = (rect1.Min.X > rect2.Min.X) ? rect1.Min.X : rect2.Min.X;
            float num = (rect1.Min.Y > rect2.Min.Y) ? rect1.Min.Y : rect2.Min.Y;
            float num4 = (num8 < num7) ? num8 : num7;
            float num3 = (num6 < num5) ? num6 : num5;

            if ((num4 > num2) && (num3 > num))
            {
                result.Min.X = num2;
                result.Min.Y = num;
                result.Max.X = num4;
                result.Max.Y = num3;
            }

            result.Min.X = 0;
            result.Min.Y = 0;
            result.Max.X = 0;
            result.Max.Y = 0;
        }
示例#16
0
 public void Intersects(ref BoundingRect rect, out bool result)
 {
     result =
         (this.Min.X < rect.Max.X) &&
         (this.Min.Y < rect.Max.Y) &&
         (this.Max.X > rect.Min.X) &&
         (this.Max.Y > rect.Min.Y);
 }
示例#17
0
文件: Camera.cs 项目: Bajena/Miner
 /// <summary>
 /// Sprawdza, czy obiekt jest widziany przez kamerę
 /// </summary>
 /// <param name="boundingRectangle">Prostokąt reprezentujący dany obiekt</param>
 /// <returns></returns>
 public bool IsRectangleVisible(BoundingRect boundingRectangle)
 {
     return boundingRectangle.Intersects(BoundingRectangle);
 }