Пример #1
0
        public ISkyBoxAble SkyBox;        // = DefaultSkyBox.Default; // todo: 删除默认值

        public RayCastResult Intersection(Ray ray)
        {
            RayCastResult result = null;

            foreach (RenderObject o in r_Objects)
            {
                RayCastResult re = o.Intersection(ray, float.MaxValue);
                result = RayCastResult.BetterOne(result, re);
            }
            return(result);
        }
Пример #2
0
 /// <summary>
 /// 返回两个结果中更好的一个
 /// </summary>
 /// <param name="res1"></param>
 /// <param name="res2"></param>
 /// <returns></returns>
 public static RayCastResult BetterOne(RayCastResult res1, RayCastResult res2)
 {
     if (res1 == null)
     {
         return(res2);
     }
     if (res2 == null)
     {
         return(res1);
     }
     if (res1.distance < res2.distance)
     {
         return(res1);
     }
     else
     {
         return(res2);
     }
 }
Пример #3
0
        public RayCastResult Intersection(Ray ray, float nowbest)
        {
            (bool cast, float mint) = BoundBox.Intersection(ray);
            if (!cast || mint > nowbest)               // 未相交 或 当前最小解已不是最优
            {
                return(null);
            }
            RayCastResult result = null;             // RayCastResult.BetterOne(lres, rres);

            if (Childs != null)
            {
                foreach (IRayCastAble obj in Childs)
                {
                    RayCastResult restmp = obj.Intersection(ray, nowbest);
                    result = RayCastResult.BetterOne(result, restmp);
                    if (result != null)
                    {
                        nowbest = Math.Min(nowbest, result.distance);
                    }
                }
            }

            return(result);
        }