コード例 #1
0
ファイル: HitElement.cs プロジェクト: VilRan/Legatus
        public override Vector2?FindIntersection(HitRay other)
        {
            float denominator = Length.X * other.Length.Y - other.Length.X * Length.Y;

            if (denominator == 0)
            {
                return(null);
            }

            float dx = Start.X - other.Start.X;
            float dy = Start.Y - other.Start.Y;
            float s  = (Length.X * dy - Length.Y * dx) / denominator;
            float t  = (other.Length.X * dy - other.Length.Y * dx) / denominator;

            if (s >= 0 && s <= 1 && t >= 0 && t <= 1)
            {
                return(Start + t * Length);
            }

            return(null);
        }
コード例 #2
0
ファイル: HitElement.cs プロジェクト: VilRan/Legatus
        public override Vector2?FindIntersection(HitRay ray)
        {
            List <Vector2> intersections = new List <Vector2>(Sides.Length);

            foreach (HitRay side in Sides)
            {
                Vector2?intersection = side.FindIntersection(ray);
                if (intersection != null)
                {
                    intersections.Add(intersection.Value);
                }
            }

            switch (intersections.Count)
            {
            case 0: return(null);

            case 1: return(intersections[0]);

            default:
                intersections.OrderBy(e => (e - ray.Start).LengthSquared());
                return(intersections[0]);
            }
        }
コード例 #3
0
ファイル: HitElement.cs プロジェクト: VilRan/Legatus
 /// <summary>
 /// Returns null if no intersection.
 /// </summary>
 /// <param name="ray"></param>
 /// <returns></returns>
 public abstract Vector2?FindIntersection(HitRay ray);