TracedRay trace_ray_simple(Stop surface, RayTraceResults result, TracedRay incident, Vector3Pair local, Vector3Pair intersect) { Vector2 v = intersect.origin().project_xy(); bool ir = true; // FIXME _intercept_reemit || result.get_params ().is_sequential (); if (ir && surface.get_shape().inside(v)) { // re-emit incident ray TracedRay r = result.newRay(intersect.origin(), incident.get_ray().direction()); r.set_wavelen(incident.get_wavelen()); r.set_intensity(incident.get_intensity()); r.set_material(incident.get_material()); r.set_creator(surface); incident.add_generated(r); return(r); } return(null); }
private TracedRay trace_ray_simple(OpticalSurface surface, RayTraceResults result, TracedRay incident, Vector3Pair local, Vector3Pair intersect) { bool right_to_left = intersect.normal().z() > 0; Medium prev_mat = surface.get_material(right_to_left ? 1 : 0); Medium next_mat = surface.get_material(!right_to_left ? 1 : 0); // check ray didn't "escaped" from its material // std::cout << prev_mat->name << " " << next_mat->name << // " " << incident.get_material()->name << std::endl; if (prev_mat != incident.get_material()) { return(null); } double wl = incident.get_wavelen(); double index = prev_mat.get_refractive_index(wl) / next_mat.get_refractive_index(wl); // refracted ray direction Vector3 direction = refract(surface, local, intersect.normal(), index); if (direction == null) { // total internal reflection Vector3 o = intersect.origin(); Vector3 dir = reflect(surface, local, intersect.normal()); TracedRay r = result.newRay(o, dir); r.set_wavelen(wl); r.set_intensity(incident.get_intensity()); r.set_material(prev_mat); r.set_creator(surface); incident.add_generated(r); return(r); } // transmit if (!next_mat.is_opaque()) { Vector3 o = intersect.origin(); TracedRay r = result.newRay(o, direction); r.set_wavelen(wl); r.set_intensity(incident.get_intensity()); r.set_material(next_mat); r.set_creator(surface); incident.add_generated(r); return(r); } // reflect if (next_mat.is_reflecting()) { Vector3 o = intersect.origin(); Vector3 dir = reflect(surface, local, intersect.normal()); TracedRay r = result.newRay(o, dir); r.set_wavelen(wl); r.set_intensity(incident.get_intensity()); r.set_material(prev_mat); r.set_creator(surface); incident.add_generated(r); return(r); } return(null); }