示例#1
0
 public override bool hit(LineCollider lc, Vector2 p1, Vector2 p2)
 {
     float a = lc.secondPosition.X - lc.position.X;
     float b = lc.secondPosition.Y - lc.position.Y;
     float c = (position.X + p1.X) - (lc.position.X + p2.X);
     float d = (position.Y + p1.Y) - (lc.position.Y + p2.Y);
     float r = radius;
     if ((d * a - c * b) * (d * a - c * b) <= r * r * (a * a + b * b))
     {
         if (c * c + d * d <= r * r)
         {
             // Line segment start point is inside the circle
             return true;
         }
         if ((a - c) * (a - c) + (b - d) * (b - d) <= r * r)
         {
             // Line segment end point is inside the circle
             return true;
         }
         if (c * a + d * b >= 0 && c * a + d * b <= a * a + b * b)
         {
             // Middle section only
             return true;
         }
     }
     return false;
 }
示例#2
0
 public override bool hit(LineCollider c, Vector2 p1, Vector2 p2)
 {
     foreach (Collider colin in within)
     {
         if(colin.hit(c,p1,p2)) return true;
     }
     return false;
 }
示例#3
0
 public override bool hit(LineCollider c, Vector2 p1, Vector2 p2)
 {
     if(hit(c.position,p1,p2) || hit(c.secondPosition,p1,p2)) return true;
     foreach(LineCollider l in this.squareToLines())
     {
         if(c.hit(l,p2,p1))return true;
     }
     return false;
 }
示例#4
0
        public override bool hit(LineCollider c, Vector2 p1, Vector2 p2)
        {
            Vector2 q = position + p1;
            Vector2 p = c.position + p2;
            Vector2 r = c.secondPosition-c.position;
            Vector2 s = secondPosition-position;
            float rs = cross(r, s);
            if (rs == 0)
            {
                return (cross((q-p), r) != 0);
            }

            float t = cross((q-p),s)/rs;
            float u = cross((q-p), r) / rs;

            return (t > 0 && t < 1 && u > 0 && u < 1);
        }
示例#5
0
 public abstract Boolean hit(LineCollider c, Vector2 p1, Vector2 p2);