Exemple #1
0
    public bool Intersect(Sphere2D other)
    {
        if (m_width == 0 && m_height == 0 || other.radius == 0)
        {
            return(false);
        }

        return(other.Intersect(this));
    }
    public static bool Cross(Sphere2D sphere, Sphere2D other, Vector2_ tp, ref Vector2_ hit)
    {
        if (sphere.Intersect(other))
        {
            return(true);
        }

        var o = other.center_;

        tp -= o;
        sphere.SetCenter(sphere.center_ - o);
        other.SetCenter(Vector2_.zero);

        other.radius += sphere.radius;

        var dir = tp - sphere.center_;
        var rr  = other.radius * other.radius * dir.sqrMagnitude;
        var t   = sphere.center_ + dir;
        var d   = sphere.x * t.y - t.x * sphere.y;
        var dd  = d * d;

        if (rr - dd > 0)
        {
            var proj = Vector2_.Project(-sphere.center_, dir.normalized);
            if (proj.magnitude <= dir.magnitude && Vector2_.Dot(proj, dir) > 0)
            {
                hit = proj + sphere.center_ + o;
                return(true);
            }
        }

        sphere.SetCenter(tp);

        if (sphere.Intersect(other))
        {
            hit = tp + o;
            return(true);
        }

        return(false);
    }
 public override bool CollisionTest(ref Box2D other)
 {
     return(m_sphere.Intersect(other));
 }