コード例 #1
0
        public void DoHitTest(Ball ball, CollisionEvent coll, PlayerPhysics physics)
        {
            if (ball == null)
            {
                return;
            }

            if (Obj?.AbortHitTest != null && Obj.AbortHitTest())
            {
                return;
            }

            var newColl  = new CollisionEvent(ball);
            var newTime  = HitTest(ball, coll.HitTime, !physics.RecordContacts ? coll : newColl, physics);
            var validHit = newTime >= 0 && newTime <= coll.HitTime;

            if (!physics.RecordContacts)
            {
                // simply find first event
                if (validHit)
                {
                    coll.Ball    = ball;
                    coll.Obj     = this;
                    coll.HitTime = newTime;
                }
            }
            else
            {
                // find first collision, but also remember all contacts
                if (newColl.IsContact || validHit)
                {
                    newColl.Ball = ball;
                    newColl.Obj  = this;

                    if (newColl.IsContact)
                    {
                        physics.Contacts.Add(newColl);
                    }
                    else
                    {
                        // if (validhit)
                        coll.Set(newColl);
                        coll.HitTime = newTime;
                    }
                }
            }
        }