예제 #1
0
        /// <summary>
        /// Get intersection
        /// </summary>
        /// <param name="ray">Ray that is intersecting</param>
        /// <returns>Intersection</returns>
        public override Intersection GetIntersection(Ray ray)
        {
            Intersection p1 = a.GetIntersection(ray);
            Intersection p2 = b.GetIntersection(ray);

            if (p1 != null && p2 != null)
            {
                if (p1.t < p2.t && p1.t2 < p2.t2) // Objects overlap
                {
                    p1.t2 = p2.t;
                    return(p1);
                }
                else if (p2.t2 > p1.t2 && p2.t2 > p1.t && p2.t < p1.t && p2.t < p1.t2)
                {
                    return(null);                                                      //Object inside
                }
                else if (p1.t < p2.t2 && p1.t > p2.t && p1.t2 > p2.t && p1.t2 > p2.t2) // Objects overpal
                {
                    return(null);
                }
                else if (p1.t < p2.t && p1.t2 < p2.t)
                {
                    if (p2.t2 > 0.001)
                    {
                        return(p1);               // Objects outside
                    }
                    else
                    {
                        return(null);
                    }
                }
                else if (p1.t > p2.t2 && p1.t2 > p2.t2)
                {
                    return(p1); // Objects outside
                }
                else
                {
                    return(null);
                }
            }
            else if (p2 == null)
            {
                return(p1);
            }
            else
            {
                return(null);
            }
        }
예제 #2
0
        /// <summary>
        /// Get intersection
        /// </summary>
        /// <param name="ray">Ray</param>
        /// <returns>Intersection if found, null otherwise</returns>
        public override Intersection GetIntersection(Ray ray)
        {
            Intersection p1 = a.GetIntersection(ray);
            Intersection p2 = b.GetIntersection(ray);

            if (p1 != null && p2 != null)
            {
                if (p1.t > 0.001 && p2.t > 0.001 && p1.t2 > 0.001 && p2.t2 > 0.001)
                {
                    if (p1.t < p2.t && p1.t2 > p2.t2)
                    {
                        return(p1);                             // p2 in
                    }
                    else if (p2.t < p1.t && p2.t2 > p1.t2)
                    {
                        return(p2);                                        // p1 in
                    }
                    else if (p1.t < p2.t && p1.t2 < p2.t2 && p1.t < p2.t2) // overlay p1 sooner
                    {
                        p1.t2                   = p2.t2;
                        p1.normalEnd            = p2.normalEnd;
                        p1.pointOfIntersection2 = p2.pointOfIntersection2;
                        return(p1);
                    }
                    else if (p2.t < p1.t && p2.t2 < p1.t2 && p2.t < p1.t2)           // overlay p2 sooner
                    {
                        p2.t2                   = p1.t2;
                        p2.normalEnd            = p1.normalEnd;
                        p2.pointOfIntersection2 = p1.pointOfIntersection2;
                        return(p2);
                    }
                    else if (p1.t < p2.t && p1.t2 < p2.t)
                    {
                        return(p1);                                  //p1 sooner
                    }
                    else if (p2.t < p1.t && p2.t2 < p1.t)
                    {
                        return(p2);                                  //p2 sooner
                    }
                }
                else
                {
                    if (p2.t2 < 0.001)
                    {
                        if (p2.t < p1.t && p2.t < p1.t2)
                        {
                            p2.isIn = true;
                            return(p2);
                        }
                        else if (p2.t > p1.t && p2.t < p1.t2)
                        {
                            p2.t      = p1.t2;
                            p2.normal = p1.normalEnd;
                            p2.pointOfIntersection = p1.pointOfIntersection2;
                            p2.isIn = true;
                            return(p2);
                        }
                        else if (p2.t > p1.t && p2.t > p1.t2)
                        {
                            p2.isIn = true;
                            return(p2);
                        }
                        else if (p1.t2 < 0.001 && p2.t < p1.t)
                        {
                            p2.t      = p1.t;
                            p2.normal = p1.normal;
                            p2.pointOfIntersection = p1.pointOfIntersection;
                            p2.isIn = true;
                            return(p2);
                        }
                        p2.isIn = true;
                        return(p2);
                    }
                    if (p1.t2 < 0.001)
                    {
                        if (p1.t < p2.t && p1.t < p2.t2)
                        {
                            p1.isIn = true;
                            return(p1);
                        }
                        else if (p1.t > p2.t && p1.t < p2.t2)
                        {
                            p1.t      = p2.t2;
                            p1.normal = p2.normalEnd;
                            p1.pointOfIntersection = p2.pointOfIntersection2;
                            p1.isIn = true;
                            return(p1);
                        }
                        else if (p1.t > p2.t && p1.t > p2.t2)
                        {
                            p1.isIn = true;
                            return(p1);
                        }
                        else if (p2.t2 < 0.001 && p1.t < p2.t)
                        {
                            p1.t      = p2.t;
                            p1.normal = p2.normal;
                            p1.pointOfIntersection = p2.pointOfIntersection;
                            p1.isIn = true;
                            return(p1);
                        }
                        p1.isIn = true;

                        return(p1);
                    }
                }
            }
            else if (p1 == null && p2 != null)
            {
                if (p2.t2 < 0.001)
                {
                    p2.isIn = true;
                    return(p2);
                }
                else
                {
                    return(p2);
                }
            }
            else if (p2 == null && p1 != null)
            {
                if (p1.t2 < 0.001)
                {
                    p1.isIn = true;
                    return(p1);
                }
                else
                {
                    return(p1);
                }
            }
            else
            {
                return(null);
            }
            return(null);
        }