Exemple #1
0
        public static bool OverlapPoint <T>(ref T target, OverlapPointInput input, out OverlapPointHit closestHit) where T : struct, IQueryable
        {
            var collector = new ClosestHitCollector <OverlapPointHit>(1.0f);

            if (target.OverlapPoint(input, ref collector))
            {
                closestHit = collector.ClosestHit;
                return(true);
            }

            closestHit = new OverlapPointHit();
            return(false);
        }
Exemple #2
0
 public bool OverlapPoint(OverlapPointInput input, out OverlapPointHit hit) => QueryWrappers.OverlapPoint(ref this, input, out hit);
Exemple #3
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);
        }