private static bool LoFiTest(GameLibBoundingBox boxA, GameLibBoundingBox boxB) { return (boxA.BoundingRectangle.Intersects(boxB.BoundingRectangle)); }
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; }
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); }
/// <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; }
//public virtual void OnObjectCollision(Object2D collidingObject) { collidingObjects.Add(collidingObject); } public virtual void OnObjectCollision(Object2D collidingObject, GameLibBoundingBox sourceBoundingBox, GameLibBoundingBox targetBoundingBox) { collidingObjects.Add(collidingObject); }