예제 #1
0
        internal static unsafe bool OverlapPoint <T>(OverlapPointInput input, Collider *collider, ref T collector) where T : struct, ICollector <OverlapPointHit>
        {
            // Nothing to do if:
            // - MaxFraction is zero.
            // - Filtered out.
            if (math.abs(collector.MaxFraction) < 0f ||
                !CollisionFilter.IsCollisionEnabled(input.Filter, collider->Filter))
            {
                return(false);
            }

            // Ensure the query context is initialized.
            input.QueryContext.EnsureIsInitialized();

            bool hadHit;

            switch (collider->ColliderType)
            {
            case ColliderType.Box:
            {
                var box = (PhysicsBoxCollider *)collider;
                hadHit = PointConvex(input.Position, ref box->m_ConvexHull);
                break;
            }

            case ColliderType.Polygon:
            {
                var polygon = (PhysicsPolygonCollider *)collider;
                hadHit = PointConvex(input.Position, ref polygon->m_ConvexHull);
                break;
            }

            case ColliderType.Capsule:
            {
                var capsule = (PhysicsCapsuleCollider *)collider;
                hadHit = PointCapsule(input.Position, capsule->Vertex0, capsule->Vertex1, capsule->Radius);
                break;
            }

            case ColliderType.Circle:
            {
                var circle = (PhysicsCircleCollider *)collider;
                hadHit = PointCircle(input.Position, circle->Center, circle->Radius);
                break;
            }

            case ColliderType.Compound:
            {
                return(PointCompound(input, (PhysicsCompoundCollider *)collider, ref collector));
            }

            default:
                SafetyChecks.ThrowNotImplementedException();
                return(default);
            }

            if (hadHit)
            {
                var hit = new OverlapPointHit
                {
                    Fraction = 0f,
                    Position = PhysicsMath.mul(input.QueryContext.LocalToWorldTransform, input.Position),

                    PhysicsBodyIndex = input.QueryContext.PhysicsBodyIndex,
                    ColliderKey      = input.QueryContext.ColliderKey,
                    Entity           = input.QueryContext.Entity
                };

                return(collector.AddHit(hit));
            }
            return(false);
        }