예제 #1
0
 private static bool LoFiTest(GameLibBoundingBox boxA, GameLibBoundingBox boxB)
 {
     return (boxA.BoundingRectangle.Intersects(boxB.BoundingRectangle));
 }
예제 #2
0
        public static bool TestWithInfo(Object2D objA, Object2D objB, out GameLibBoundingBox sourceBoundingBox, out GameLibBoundingBox targetBoundingBox)
        {
            bool useSat = (objA.CollisionMode == CollisionModes.SatBox && objB.CollisionMode == CollisionModes.SatBox);

            foreach (var boxA in objA.BoundingBoxes)
            {
                foreach (var boxB in objB.BoundingBoxes)
                {
                    if (Test(boxA, boxB, !useSat))
                    {
                        sourceBoundingBox = boxA;
                        targetBoundingBox = boxB;
                        return true;
                    }
                }
            }

            sourceBoundingBox = null;
            targetBoundingBox = null;

            return false;
        }
예제 #3
0
        public void SetupDefaultBoundingBox()
        {
            if (Texture == null)
            {
                throw new Exception("Texture has to be set to create a boundingbox");
            }

            BoundingBoxes.Clear();

            var box = new GameLibBoundingBox(new Rectangle(0, 0, Width, Height), Origin, 0, Angle);
            BoundingBoxes.Add(box);
        }
예제 #4
0
        /// <summary>
        /// Determines if two GameLibBoundingBox-object are intersecting.
        /// </summary>
        /// <param name="boxA"></param>
        /// <param name="boxB"></param>
        /// <returns></returns>
        public static bool Test(GameLibBoundingBox boxA, GameLibBoundingBox boxB, bool onlyLoFiTest)
        {
            // Test "lo-fi" by bounding sphere
            var lofiCheck = LoFiTest(boxA, boxB);

            if (!lofiCheck)
                return false;

            // We only want to test the bounding boxes and not the rotated ones.
            if (onlyLoFiTest)
                return true;

            // Test "hi-fi" by SAT
            boxA.CalculatedAxis();  // Update the axis
            boxB.CalculatedAxis();

            if (!TestAxis(boxA.AxisA, boxA.Vertices, boxB.Vertices))
                return false;

            if (!TestAxis(boxA.AxisB, boxA.Vertices, boxB.Vertices))
                return false;

            if (!TestAxis(boxB.AxisA, boxA.Vertices, boxB.Vertices))
                return false;

            if (!TestAxis(boxB.AxisB, boxA.Vertices, boxB.Vertices))
                return false;

            return true;
        }
예제 #5
0
 //public virtual void OnObjectCollision(Object2D collidingObject) { collidingObjects.Add(collidingObject); }
 public virtual void OnObjectCollision(Object2D collidingObject, GameLibBoundingBox sourceBoundingBox, GameLibBoundingBox targetBoundingBox)
 {
     collidingObjects.Add(collidingObject);
 }