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

            Min = d - c.Radius;
            Max = d + c.Radius;
        }
Beispiel #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));
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #5
0
        public static bool IsPointInsideCircle(float2 point, CircleCollider collider)
        {
            var distSq = math.lengthsq(collider.Center - point);

            return(distSq <= collider.RadiusSq);
        }
Beispiel #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);
 }