Advertisement
Geometrian

Untitled

Nov 29th, 2014
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.19 KB | None | 0 0
  1. bool _hit_two_sided_intersection(Ray const& ray_wld, ObjectIntersections* hit, ObjectBase const* object, int num_forward_roots, Float d0,Float d1) {
  2.     //There are six cases that we need to consider.  ASCII art drawn for a sphere.                   /    ___
  3.     //  Case A:                                                                                     +    /   \
  4.     //      Ray does not intersect object at all.        ray origin: +       ahead: =             //    |     |
  5.     //      Zero forward roots.                        intersection: X    backward: -            L       \___/
  6.     //                                                         both: *                                    ___
  7.     //  Case B:                                                                                          /   \
  8.     //      Ray intersects object ahead of it (once the front side, once the back side).       ----+====X=====X==>
  9.     //      Two forward roots.                                                                           \___/
  10.     //                                                                                                    ___
  11.     //  Case C:                                                                                          /   \
  12.     //      Ray is on the surface heading into the object.                                          ----*=====X==>
  13.     //      One or two forward roots (first root may not be counted).                                    \___/
  14.     //                                                                                                    ___
  15.     //  Case D:                                                                                          /   \
  16.     //      Ray starting inside the object.                                                         ----X--+==X==>
  17.     //      One forward root.                                                                            \___/
  18.     //                                                                                                    ___
  19.     //  Case E:                                                                                          /   \
  20.     //      Ray is on the surface heading away from object.                                         ----X-----*==>
  21.     //      Zero or one forward roots (second root may not be counted).                                  \___/
  22.     //                                                                                                    ___
  23.     //  Case F:                                                                                          /   \
  24.     //      Ray is outside the object heading away.  Two intersections behind.                      ----X-----X----+==>
  25.     //      Zero forward roots.                                                                          \___/
  26.  
  27.     if (num_forward_roots>0) {
  28.         //Case B, C, D, or some Es
  29.         if (ray_wld.orig.object==object) {
  30.             //Case C, D, or some Es
  31.             if (d0<static_cast<Float>(-0.000001)) { //The first root is well behind us
  32.                 //Case D or some Es
  33.                 if (d1<static_cast<Float>(0.000001)) {
  34.                     //Case some Es
  35.                     assert(num_forward_roots==0||num_forward_roots==1,"Implementation error!");
  36.                     //    Ignore "d0" far behind us and "d1" we're leaving from
  37.                 } else {
  38.                     //Case D
  39.                     assert(num_forward_roots==1,"Implementation error!");
  40.                     //    Ignore "d0" far behind us
  41.                     hit->add(object, d1, ray_wld.t);
  42.                     return true;
  43.                 }
  44.             } else {
  45.                 //Case C
  46.                 assert(num_forward_roots==1||num_forward_roots==2,"Implementation error!");
  47.                 //    Ignore front surface hit "d0".
  48.                 hit->add(object, d1, ray_wld.t);
  49.                 return true;
  50.             }
  51.         } else {
  52.             //Case B
  53.             assert(num_forward_roots==2,"Implementation error!");
  54.             hit->add(object, d0, ray_wld.t);
  55.             hit->add(object, d1, ray_wld.t);
  56.             return true;
  57.         }
  58.     } else {
  59.         //Case A, some Es, or F
  60.     }
  61.     return false;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement