| 145 | #pragma float_control(precise, on) |
| 146 | #endif |
| 147 | bool BBox::IntersectP(const Ray &ray, |
| 148 | const Point &pMin, const Point &pMax, |
| 149 | float *hitt0, float *hitt1) { |
| 150 | float t0 = ray.mint, t1 = ray.maxt; |
| 151 | for (int i = 0; i < 3; ++i) { |
| 152 | // Update interval for _i_th bounding box slab |
| 153 | const float invRayDir = 1.f / ray.d[i]; |
| 154 | float tNear = (pMin[i] - ray.o[i]) * invRayDir; |
| 155 | float tFar = (pMax[i] - ray.o[i]) * invRayDir; |
| 156 | // Update parametric interval from slab intersection $t$s |
| 157 | if (tNear > tFar) Swap(tNear, tFar); |
| 158 | t0 = tNear > t0 ? tNear : t0; |
| 159 | t1 = tFar < t1 ? tFar : t1; |
| 160 | if (t0 > t1) return false; |
| 161 | } |
| 162 | if (hitt0) *hitt0 = t0; |
| 163 | if (hitt1) *hitt1 = t1; |
| 164 | return true; |
| 165 | } |
| 166 | |
| 167 | bool BBox::IntersectP(const Ray &ray, float *hitt0, float *hitt1) const { |
| 168 | return IntersectP(ray, pMin, pMax, hitt0, hitt1); |