| 92 | /////////////////////////////////////////// |
| 93 | |
| 94 | bool32_t bounds_line_contains(bounds_t bounds, vec3 pt1, vec3 pt2) { |
| 95 | vec3 delta = pt2 - pt1; |
| 96 | if (vec3_dot(delta, delta) <= 0.0001f) |
| 97 | return bounds_point_contains(bounds, pt1); |
| 98 | |
| 99 | // If any of these is 0, then m becomes inf, and that axis is then |
| 100 | // ignored from the calculation. This is a bit of a hack, and I should |
| 101 | // probably find a better way to fix this? But it shouldn't be too |
| 102 | // terrible |
| 103 | if (delta.x == 0) delta.x = 0.000000000001f; |
| 104 | if (delta.y == 0) delta.y = 0.000000000001f; |
| 105 | if (delta.z == 0) delta.z = 0.000000000001f; |
| 106 | |
| 107 | vec3 ray_origin = pt1 - bounds.center; |
| 108 | vec3 m = { 1.f / delta.x, 1.f / delta.y, 1.f / delta.z }; |
| 109 | vec3 n = m * ray_origin; |
| 110 | vec3 k = vec3_abs(m) * (bounds.dimensions / 2); |
| 111 | vec3 t1 = -n - k; |
| 112 | vec3 t2 = -n + k; |
| 113 | float tN = fmaxf(fmaxf(t1.x, t1.y), t1.z); |
| 114 | float tF = fminf(fminf(t2.x, t2.y), t2.z); |
| 115 | return tF >= 0 && tN < tF && (tF <= 1 || tN <= 1); |
| 116 | } |
| 117 | |
| 118 | /////////////////////////////////////////// |
| 119 |
no test coverage detected