Beispiel #1
0
        public bool IsHitBy(Ray r, float tMin, float tMax, out HitRecord record)
        {
            if (_boundingBox.IsHitBy(r, tMin, tMax, out record))
            {
                bool hitLeft  = Left.IsHitBy(r, tMin, tMax, out HitRecord leftRecord);
                bool hitRight = Right.IsHitBy(r, tMin, tMax, out HitRecord rightRecord);

                if (hitLeft || hitRight)
                {
                    if (hitLeft && hitRight)
                    {
                        record = leftRecord.t < rightRecord.t ? leftRecord : rightRecord;
                    }
                    else if (hitLeft)
                    {
                        record = leftRecord;
                    }
                    else if (hitRight)
                    {
                        record = rightRecord;
                    }
                    return(true);
                }
            }
            return(false);
        }