Esempio n. 1
0
        public void Update()
        {
            IntersectionResults.Clear();

            IntersectionResult previousResult = new IntersectionResult()
            {
                OutgoingRay = new Ray(IncidentRay)
            };

            double lastRefractiveIndex       = RefractiveIndices.AIR;
            Vector translationFromLensCenter = new Vector(0.0, 0.0);

            int maxIntersections = Elements.Count;

            for (int i = 0; i < maxIntersections; i++)
            {
                IntersectionResult result  = new IntersectionResult();
                OpticalElement     element = Elements[i];

                result.IncidentRay = new Ray(previousResult.OutgoingRay);

                Vector toLocal = element.TranslationToLocal();

                // compute intersection

                Point intersection         = null;
                Ray   rayIncidentToElement = result.IncidentRay.Translate(translationFromLensCenter + toLocal);
                result.Intersected = element.IntersectRay(rayIncidentToElement, out intersection);
                result.Normal      = Vector.FromPoint(intersection);
                intersection       = intersection - (translationFromLensCenter + toLocal);
                if (!result.Intersected)
                {
                    break;
                }
                result.Intersection = intersection;

                // compute refracted ray

                Vector outgoingDirection;
                if (Math.Abs(lastRefractiveIndex - element.NextRefractiveIndex) > double.Epsilon)
                {
                    outgoingDirection = result.IncidentRay.Direction.Length * Vector.refract(result.IncidentRay.Direction, result.Normal, lastRefractiveIndex, element.NextRefractiveIndex);
                }
                else
                {
                    // there's no border between different media and thus no refraction
                    outgoingDirection = result.IncidentRay.Direction;
                }
                result.OutgoingRay = new Ray(result.Intersection, outgoingDirection);
                result.Refracted   = true; // TODO: differ refraction and TIR
                IntersectionResults.Add(result);
                previousResult               = result;
                lastRefractiveIndex          = element.NextRefractiveIndex;
                translationFromLensCenter.X += element.DistanceToNext;
            }
        }
Esempio n. 2
0
 private void ComputeRefractedRay()
 {
     RefractedDirection  = Vector.refract(Direction, Normal, RefractiveIndexAir, RefractiveIndexGlass);
     RefractedDirection *= Direction.Length;
 }