#region CPL License /* Nuclex Framework Copyright (C) 2002-2009 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #endregion using System; using Microsoft.Xna.Framework; namespace Nuclex.Geometry.Areas.Collisions { /// Contains all Disc2-to-Disc2 interference detection code public static class Disc2Disc2Collider { /// Test whether two discs are overlapping /// Center of the first disc /// Radius of the first disc /// Center of the second disc /// Radius of the second disc /// True if the discs are intersecting each other public static bool CheckContact( Vector2 firstCenter, float firstRadius, Vector2 secondCenter, float secondRadius ) { float distanceSquared = (secondCenter - firstCenter).LengthSquared(); float combinedRadii = firstRadius + secondRadius; return (combinedRadii * combinedRadii) > distanceSquared; } /// Find the contact location between two discs /// Center of the first disc /// Radius of the first disc /// Center of the second disc /// Radius of the second disc /// A contact location if the discs touch each other public static Vector2? FindContact( Vector2 firstCenter, float firstRadius, Vector2 secondCenter, float secondRadius ) { Vector2 offset = (secondCenter - firstCenter); float distanceSquared = offset.LengthSquared(); float combinedRadii = firstRadius + secondRadius; if(distanceSquared > (combinedRadii * combinedRadii)) return null; Vector2 firstCircumferencePoint = firstCenter + offset * firstRadius; Vector2 secondCircumferencePoint = secondCenter - offset * secondRadius; return (firstCircumferencePoint + secondCircumferencePoint) / 2.0f; } /// Determines whether a disc will hit another box /// Center of the first disc /// Radius of the first disc /// Center of the second disc /// Radius of the second disc /// /// Velocity with which the second disc is moving relative to the first disc /// /// True if the second disc will hit the first disc public static bool CheckContact( Vector2 firstCenter, float firstRadius, Vector2 secondCenter, float secondRadius, float secondVelocity ) { throw new NotImplementedException("Not implemented yet"); } /// Determines the time when a disc will hit another disc /// Center of the first disc /// Radius of the first disc /// Center of the second disc /// Radius of the second disc /// /// Velocity with which the second disc is moving relative to the first disc /// /// The point of first contact, if any public static float? FindContact( Vector2 firstCenter, float firstRadius, Vector2 secondCenter, float secondRadius, float secondVelocity ) { throw new NotImplementedException("Not implemented yet"); } } } // namespace Nuclex.Geometry.Areas.Collisions