Exemplo n.º 1
0
        List <TracedRay> process_rays(Surface surface, TraceIntensityMode m, RayTraceResults result,
                                      List <TracedRay> input)
        {
            RayTraceParameters params_ = result._parameters;
            List <TracedRay>   rays    = new();

            foreach (TracedRay i in input)
            {
                TracedRay ray = i;

                Transform3 t
                    = ray.get_creator().get_transform_to(surface);
                Vector3Pair local1 = t.transform_line(ray.get_ray());

                Vector3Pair pt = surface is Stop
                    ? intersect((Stop)surface, params_, local1)
                    : intersect(surface, params_, local1);

                if (pt != null)
                {
                    result.add_intercepted(surface, ray);
                    TracedRay cray = trace_ray(surface, m, result, ray, local1, pt);
                    if (cray != null)
                    {
                        rays.Add(cray);
                    }
                }
            }

            return(rays);
        }
        static bool draw_traced_ray_recurs(Renderer renderer, TracedRay ray, double lost_len,
                                           Element ref_, bool hit_image, int D, bool draw_lost)
        {
            Transform3 t1        = ray.get_creator().get_transform_to(ref_);
            Element    i_element = null;

            Vector3 v0 = t1.transform(ray.get_ray().origin());
            Vector3 v1;

            if (ray.is_lost())
            {
                if (!draw_lost)
                {
                    return(false);
                }
                v1 = t1.transform(ray.get_ray().origin().plus(ray.get_ray().direction().times(lost_len)));
            }
            else
            {
                i_element = ray.get_intercept_element();
                Transform3 t2 = i_element.get_transform_to(ref_);
                v1 = t2.transform(ray.get_intercept_point());
            }

            Vector3Pair p    = new Vector3Pair(v0, v1);
            bool        done = false;

            for (TracedRay child_ray = ray.get_first_child(); child_ray != null; child_ray = child_ray.get_next_child())
            {
                if (draw_traced_ray_recurs(renderer, child_ray, lost_len, ref_, hit_image, 2, false))
                {
                    done = true;
                }
            }

            if (!done && hit_image && !(i_element is Image))
            {
                return(false);
            }

            switch (D)
            {
            case 2:
                // skip non tangential rays in 2d mode
                if (Math.Abs(p.x1()) > 1e-6)
                {
                    return(false);
                }

                draw_ray_line(renderer, new Vector2Pair(p.v0.project_zy(), p.v1.project_zy()), ray);
                break;

            case 3:
                draw_ray_line(renderer, p, ray);
                break;
            }

            return(true);
        }
Exemplo n.º 3
0
        List <TracedRay> process_rays(Stop surface, TraceIntensityMode m, RayTraceResults result, List <TracedRay> input)
        {
            List <TracedRay> rays = new();

            foreach (TracedRay i in input)
            {
                TracedRay ray = i;

                Transform3  t     = ray.get_creator().get_transform_to(surface);
                Vector3Pair local = t.transform_line(ray.get_ray());

                Vector3 origin = surface.get_curve().intersect(local);
                if (origin != null)
                {
                    if (origin.project_xy().len() < surface.get_external_radius())
                    {
                        Vector3 normal = surface.get_curve().normal(origin);

                        if (local.direction().z() < 0)
                        {
                            normal = normal.negate();
                        }

                        result.add_intercepted(surface, ray);

                        TracedRay cray = trace_ray(surface, m, result, ray, local, new Vector3Pair(origin, normal));
                        if (cray != null)
                        {
                            rays.Add(cray);
                        }
                    }
                }
            }

            return(rays);
        }