Exemple #1
0
        public Projection(float2 v, CircleCollider c)
        {
            var d = math.dot(c.Center, v);

            Min = d - c.Radius;
            Max = d + c.Radius;
        }
Exemple #2
0
        public static bool IsColliding(CircleCollider c0, CircleCollider c1)
        {
            var n  = math.normalizesafe(c0.Center - c1.Center);
            var p0 = new Projection(n, c0);
            var p1 = new Projection(n, c1);

            return(Projection.DoesOverlap(p0, p1));
        }
Exemple #3
0
        public static bool IsColliding(CircleCollider c0, CircleCollider c1, out MTV mtv)
        {
            mtv = new MTV();
            var n  = math.normalizesafe(c0.Center - c1.Center);
            var p0 = new Projection(n, c0);
            var p1 = new Projection(n, c1);

            if (Projection.DoesOverlap(p0, p1))
            {
                mtv.Calculate(n, p0, p1, c0.Center, c1.Center);
                return(true);
            }
            return(false);
        }
Exemple #4
0
        public static bool IsColliding(
            CircleCollider circle,
            NativeArray <ColliderVertex> vertices,
            NativeArray <EdgeNormal> normals,
            float2 center,
            out MTV mtv)
        {
            mtv = MTV.Max;
            var shouldCheckCorner = true;

            for (int i = 0; i < normals.Length; i++)
            {
                var n  = normals[i].Value;
                var p0 = new Projection(n, circle);
                var p1 = new Projection(n, vertices);
                var d  = math.dot(circle.Center, n);
                shouldCheckCorner = shouldCheckCorner && !Projection.DoesOverlap(p1, d);

                if (!Projection.DoesOverlap(p0, p1))
                {
                    return(false);
                }

                mtv.Calculate(n, p0, p1, circle.Center, center);
            }

            if (shouldCheckCorner)
            {
                var closest = ClosestPoint(circle.Center, vertices);
                var n       = math.normalizesafe(closest - circle.Center);
                var p0      = new Projection(n, circle);
                var p1      = new Projection(n, vertices);

                if (!Projection.DoesOverlap(p0, p1))
                {
                    return(false);
                }

                mtv.Calculate(n, p0, p1, circle.Center, center);
            }

            return(true);
        }
Exemple #5
0
        public static bool IsPointInsideCircle(float2 point, CircleCollider collider)
        {
            var distSq = math.lengthsq(collider.Center - point);

            return(distSq <= collider.RadiusSq);
        }
Exemple #6
0
 public Bounds2D(CircleCollider c)
 {
     Min = new float2(c.Center.x - c.Radius, c.Center.y - c.Radius);
     Max = new float2(c.Center.x + c.Radius, c.Center.y + c.Radius);
 }