Ejemplo n.º 1
0
        private void Recompute()
        {
            if (!initialized)
            {
                return;
            }

            sphere.Center = GetVectorFromControls(sphereCenterXNumeric, sphereCenterYNumeric, sphereCenterZNumeric);
            incomingRay.Origin = GetVectorFromControls(rayOriginXNumeric, rayOriginYNumeric, rayOriginZNumeric);
            double directionPhi = (double)rayDirectionPhiNumeric.Value;
            incomingRay.Direction = new Vector3d(Math.Sin(directionPhi), 0, Math.Cos(directionPhi));

            intersection = sphere.Intersect(incomingRay);
            refractedRay = null;
            normal = Vector3d.Zero;
            if (intersection != null)
            {
                normal = sphere.GetNormal(intersection.Position);
                double n1, n2;
                double dot = Vector3d.Dot(normal, incomingRay.Direction);
                if (dot < 0)
                {
                    n1 = Materials.Fixed.AIR;
                    n2 = Materials.Fixed.GLASS_CROWN_BK7;
                }
                else
                {
                    n1 = Materials.Fixed.GLASS_CROWN_BK7;
                    n2 = Materials.Fixed.AIR;
                    normal = -normal;
                }
                refractedRay = new Ray(intersection.Position,
                    Ray.Refract(incomingRay.Direction, normal, n1, n2, false));
            }

            drawingPanel.Invalidate();
        }
Ejemplo n.º 2
0
        private void ComputeIntersection(bool withDebugInfo)
        {
            rayStartPoint = new Point((int)rayStart.X, (int)rayStart.Y);
            rayEndPoint = new Point((int)rayEnd.X, (int)rayEnd.Y);
            if (withDebugInfo)
            {
                footprintDebugInfo = new FootprintDebugInfo();
            }
            else
            {
                footprintDebugInfo = null;
            }
            intersection = selectedIntersector.Intersect(rayStart, rayEnd, ref footprintDebugInfo);
            intersectionLabel.Text = (intersection != null) ? intersection.Position.ToString() : "none";
            isecLayerLabel.Text = (footprintDebugInfo != null) && (intersection != null) ? footprintDebugInfo.LayerOfIntersection.ToString() : "";

            heightFieldPanel.Invalidate();
            footprintTraversalPanel.Invalidate();
        }