public bool Intersects(AABB2D b) { if (Math.Abs(this.Pos.X - b.Pos.X) > (this.HalfExtents.X + b.HalfExtents.X)) return false; if (Math.Abs(this.Pos.Y - b.Pos.Y) > (this.HalfExtents.Y + b.HalfExtents.Y)) return false; return true; }
public static AABB2D CreateMerged(AABB2D a, AABB2D b) { Vector2 min = Vector2.Min(a.Pos - a.HalfExtents, b.Pos - b.HalfExtents); Vector2 max = Vector2.Max(a.Pos + a.HalfExtents, b.Pos + b.HalfExtents); return CreateFromMinMax(min, max); }
public LineBody(Vector2 normal, Vector2 p) : base(p, Vector2.Zero, 0f, 0, 0f) { this.normal = Vector2.Normalize(normal); this.p = p; //A line extends infinitely, so make our AABB as big as possible motionBounds = new AABB2D(Vector2.Zero, new Vector2(float.MaxValue, float.MaxValue)); }
public override void GenerateMotionAABB(float dt) { Vector2 predictedPos = Pos + (Vel * dt); Vector2 center = (Pos + predictedPos) / 2f; Vector2 halfExtents = new Vector2((Math.Abs(predictedPos.X-Pos.X) * 0.5f) + radius, (Math.Abs(predictedPos.Y-Pos.Y) * 0.5f) + radius); motionBounds = new AABB2D(center, halfExtents); }