Exemplo n.º 1
0
    /// <summary>
    /// Checks whether the given circle intersects with this circle, calculating the
    /// collision data in that case.
    /// </summary>
    /// <param name="other">the circle to check</param>
    /// <param name="intersection">the collision data, <code>null</code> if no collision has been detected.</param>
    /// <returns>true if the colliders intersect, false otherwise.</returns>
    public override bool Intersects(DCircleCollider other, out Manifold intersection)
    {
        intersection = null;
        Fix32    rDistance         = this.radius + other.radius;
        Fix32    sqrRadiusDistance = rDistance * rDistance;
        Vector2F centerDistance    = other.center - this.center;

        if (centerDistance.SqrtMagnitude > sqrRadiusDistance)
        {
            return(false);
        }

        //check if one of them is a trigger
        if (this.IsTrigger || other.IsTrigger)
        {
            intersection = new Manifold(this.Body, other.Body);
            return(true);
        }

        Fix32    distance = centerDistance.Magnitude;
        Vector2F normal;
        Fix32    penetration;

        if (distance > Fix32.Zero)
        {
            penetration = rDistance - distance;
            normal      = centerDistance / distance;
        }
        else
        {
            penetration = this.radius;
            normal      = new Vector2F((Fix32)1, (Fix32)0);
        }
        intersection = new Manifold(this.Body, other.Body, normal, penetration);
        return(true);
    }
Exemplo n.º 2
0
 public override bool Intersects(DCircleCollider other, out Manifold intersection)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 3
0
 /// <summary>
 /// Checks whether the given colliders intersect, generating an Intersection instance
 /// with the collision data in that case.
 /// Since this function represents a "box vs circle" collision, the symmetric function is called
 /// instead. See DCircleCollider for more info.
 /// </summary>
 /// <param name="other">the second collider</param>
 /// <param name="intersection">the collision data, <code>null</code> if no collision has been detected.</param>
 /// <returns></returns>
 public override bool Intersects(DCircleCollider other, out Manifold intersection)
 {
     return(other.Intersects(this, out intersection));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Abstract function for intersections with circles.
 /// </summary>
 /// <param name="other">circle collider</param>
 /// <param name="intersection">collision data</param>
 /// <returns></returns>
 public abstract bool Intersects(DCircleCollider other, out Manifold intersection);