Пример #1
0
        private ClosestSphere GetClosestSphereIntersectionInList(Ray ray, List <PotatoSphere> spheres)
        {
            PotatoSphere intersectedSphere = null;
            Vector3      hitPosition       = new Vector3();
            Vector3      hitNormal         = new Vector3();

            Vector3 localHitPosition = new Vector3();
            Vector3 localHitNormal   = new Vector3();
            double  distance         = double.PositiveInfinity;
            double  t = 0.0;

            //LoopSphereListToGetTheClosets(ray, spheres, ref intersectedSphere, ref hitPosition, ref hitNormal, ref localHitPosition, ref localHitNormal, ref distance, ref t);

            for (int i = 0; i < spheres.Count; i++)
            {
                if (SphereIntersection.Intersect(ray, spheres[i], ref localHitPosition, ref localHitNormal, ref t))
                {
                    if (t < distance)
                    {
                        distance          = t;
                        intersectedSphere = spheres[i];

                        hitPosition = localHitPosition;
                        hitNormal   = localHitNormal;
                    }
                }
            }

            return(new ClosestSphere(intersectedSphere, hitPosition, hitNormal, distance));
        }
Пример #2
0
        private void LoopSphereListToGetTheClosets(Ray ray, List <PotatoSphere> spheres, ref PotatoSphere intersectedSphere, ref Vector3 hitPosition, ref Vector3 hitNormal, ref Vector3 localHitPosition, ref Vector3 localHitNormal, ref double distance, ref double t)
        {
            for (int i = 0; i < spheres.Count; i++)
            {
                if (SphereIntersection.Intersect(ray, spheres[i], ref localHitPosition, ref localHitNormal, ref t))
                {
                    if (t < distance)
                    {
                        distance          = t;
                        intersectedSphere = spheres[i];

                        hitPosition = localHitPosition;
                        hitNormal   = localHitNormal;
                    }
                }
            }
        }