Пример #1
0
        public virtual CircleCastHit CircleCastHandle(CircleCast cast)
        {
            // Already collided at origin position
            if (pos.distTo(cast.origin) < cast.r)
            {
                return(new CircleCastHit
                       (
                           isHit: true, isOriginHit: true,
                           originCirclePos: cast.origin, hitCirclePos: cast.origin, contactPos: pos
                       ));
            }
            // Detect
            var castLine = cast.GetLineBase();

            if (castLine.FootOnThis(pos))
            {
                var dist = castLine.DistToPoint(pos);
                if (dist <= cast.r)
                {
                    var distContactFoot   = Math.Sqrt(cast.r * cast.r - dist * dist);
                    var foot1             = castLine.FootPoint(pos);
                    var distOriginFoot    = (foot1 - cast.origin) * cast.dir;
                    var distOriginContact = distOriginFoot - distContactFoot;
                    var hit = cast.origin + cast.dir * distOriginContact;
                    return(new CircleCastHit
                           (
                               isHit: true, isOriginHit: false, originCirclePos: cast.origin,
                               hitCirclePos: hit, contactPos: pos
                           ));
                }
            }

            // No Collision
            return(CircleCastHit.NotHit(cast.origin));
        }
Пример #2
0
 public bool EarlierThan(CircleCastHit hit)
 {
     if (!isHit)
     {
         return(false);
     }
     if (!hit.isHit)
     {
         return(true);
     }
     return(dist < hit.dist);
 }
Пример #3
0
        protected CircleCastHit CircleCastHandle_ExceptEnds(CircleCast cast)
        {
            if (this.DistToPoint(cast.origin) < cast.r)
            {
                // Already collided at origin position
                if (this.FootOnThis(cast.origin))
                {
                    return(new CircleCastHit
                           (
                               isHit: true, isOriginHit: true, originCirclePos: cast.origin,
                               hitCirclePos: cast.origin, contactPos: FootPoint(cast.origin)
                           ));
                }
                // Except Collide Inside out
                else
                {
                    return(CircleCastHit.NotHit(cast.origin));
                }
            }

            // Detect collision between ends
            var marginLine = this.MovedAlongNormToPointSide(cast.origin, cast.r);
            var castLine   = cast.GetLineBase();
            var sec        = castLine.Intersect(marginLine);

            if (!sec.isNull)
            {
                return(new CircleCastHit
                       (
                           isHit: true, isOriginHit: false, originCirclePos: cast.origin,
                           hitCirclePos: sec, contactPos: FootPoint(sec)
                       ));
            }
            // No Collision
            return(CircleCastHit.NotHit(cast.origin));
        }