| 92 | // Returns true when the ray intersects the bbox, returns false otherwise |
| 93 | |
| 94 | bool |
| 95 | bbox_intersect(const boundingbox& bbox, bbox_ray_t r, float t0, float t1) |
| 96 | { |
| 97 | // This code makes handy use of IEEE floating-point behaviour, such |
| 98 | // as division by zero. See |
| 99 | // 1) Shirley et.al. Section 10.9.1 |
| 100 | // 2) Williams et.al., "An Efficient and Robust Ray-Box Intersection Algorithm" |
| 101 | |
| 102 | float tmin, tmax; |
| 103 | float tymin, tymax, tzmin, tzmax; |
| 104 | const vec3* bounds = bbox.bounds; |
| 105 | |
| 106 | tmin = (bounds[r.sign[0]].x - r.origin.x) * r.inv_direction.x; |
| 107 | tmax = (bounds[1-r.sign[0]].x - r.origin.x) * r.inv_direction.x; |
| 108 | |
| 109 | tymin = (bounds[r.sign[1]].y - r.origin.y) * r.inv_direction.y; |
| 110 | tymax = (bounds[1-r.sign[1]].y - r.origin.y) * r.inv_direction.y; |
| 111 | |
| 112 | if (tmin > tymax || tymin > tmax) |
| 113 | return false; |
| 114 | |
| 115 | if (tymin > tmin) |
| 116 | tmin = tymin; |
| 117 | if (tymax < tmax) |
| 118 | tmax = tymax; |
| 119 | |
| 120 | tzmin = (bounds[r.sign[2]].z - r.origin.z) * r.inv_direction.z; |
| 121 | tzmax = (bounds[1-r.sign[2]].z - r.origin.z) * r.inv_direction.z; |
| 122 | |
| 123 | if (tmin > tzmax || tzmin > tmax) |
| 124 | return false; |
| 125 | |
| 126 | if (tzmin > tmin) |
| 127 | tmin = tzmin; |
| 128 | if (tzmax < tmax) |
| 129 | tmax = tzmax; |
| 130 | |
| 131 | return (tmin < t1 && tmax > t0); |
| 132 | } |
| 133 | |
| 134 | } // namespace sk |
nothing calls this directly
no outgoing calls
no test coverage detected