Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool _hit_two_sided_intersection(Ray const& ray_wld, ObjectIntersections* hit, ObjectBase const* object, int num_forward_roots, Float d0,Float d1) {
- //There are six cases that we need to consider. ASCII art drawn for a sphere. / ___
- // Case A: + / \
- // Ray does not intersect object at all. ray origin: + ahead: = // | |
- // Zero forward roots. intersection: X backward: - L \___/
- // both: * ___
- // Case B: / \
- // Ray intersects object ahead of it (once the front side, once the back side). ----+====X=====X==>
- // Two forward roots. \___/
- // ___
- // Case C: / \
- // Ray is on the surface heading into the object. ----*=====X==>
- // One or two forward roots (first root may not be counted). \___/
- // ___
- // Case D: / \
- // Ray starting inside the object. ----X--+==X==>
- // One forward root. \___/
- // ___
- // Case E: / \
- // Ray is on the surface heading away from object. ----X-----*==>
- // Zero or one forward roots (second root may not be counted). \___/
- // ___
- // Case F: / \
- // Ray is outside the object heading away. Two intersections behind. ----X-----X----+==>
- // Zero forward roots. \___/
- if (num_forward_roots>0) {
- //Case B, C, D, or some Es
- if (ray_wld.orig.object==object) {
- //Case C, D, or some Es
- if (d0<static_cast<Float>(-0.000001)) { //The first root is well behind us
- //Case D or some Es
- if (d1<static_cast<Float>(0.000001)) {
- //Case some Es
- assert(num_forward_roots==0||num_forward_roots==1,"Implementation error!");
- // Ignore "d0" far behind us and "d1" we're leaving from
- } else {
- //Case D
- assert(num_forward_roots==1,"Implementation error!");
- // Ignore "d0" far behind us
- hit->add(object, d1, ray_wld.t);
- return true;
- }
- } else {
- //Case C
- assert(num_forward_roots==1||num_forward_roots==2,"Implementation error!");
- // Ignore front surface hit "d0".
- hit->add(object, d1, ray_wld.t);
- return true;
- }
- } else {
- //Case B
- assert(num_forward_roots==2,"Implementation error!");
- hit->add(object, d0, ray_wld.t);
- hit->add(object, d1, ray_wld.t);
- return true;
- }
- } else {
- //Case A, some Es, or F
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement