| 85 | } |
| 86 | |
| 87 | AABB AABB::intersection(const AABB &p_aabb) const { |
| 88 | #ifdef MATH_CHECKS |
| 89 | if (unlikely(size.x < 0 || size.y < 0 || size.z < 0 || p_aabb.size.x < 0 || p_aabb.size.y < 0 || p_aabb.size.z < 0)) { |
| 90 | ERR_PRINT("AABB size is negative, this is not supported. Use AABB.abs() to get an AABB with a positive size."); |
| 91 | } |
| 92 | #endif |
| 93 | Vector3 src_min = position; |
| 94 | Vector3 src_max = position + size; |
| 95 | Vector3 dst_min = p_aabb.position; |
| 96 | Vector3 dst_max = p_aabb.position + p_aabb.size; |
| 97 | |
| 98 | Vector3 min, max; |
| 99 | |
| 100 | if (src_min.x > dst_max.x || src_max.x < dst_min.x) { |
| 101 | return AABB(); |
| 102 | } else { |
| 103 | min.x = (src_min.x > dst_min.x) ? src_min.x : dst_min.x; |
| 104 | max.x = (src_max.x < dst_max.x) ? src_max.x : dst_max.x; |
| 105 | } |
| 106 | |
| 107 | if (src_min.y > dst_max.y || src_max.y < dst_min.y) { |
| 108 | return AABB(); |
| 109 | } else { |
| 110 | min.y = (src_min.y > dst_min.y) ? src_min.y : dst_min.y; |
| 111 | max.y = (src_max.y < dst_max.y) ? src_max.y : dst_max.y; |
| 112 | } |
| 113 | |
| 114 | if (src_min.z > dst_max.z || src_max.z < dst_min.z) { |
| 115 | return AABB(); |
| 116 | } else { |
| 117 | min.z = (src_min.z > dst_min.z) ? src_min.z : dst_min.z; |
| 118 | max.z = (src_max.z < dst_max.z) ? src_max.z : dst_max.z; |
| 119 | } |
| 120 | |
| 121 | return AABB(min, max - min); |
| 122 | } |
| 123 | |
| 124 | // Note that this routine returns the BACKTRACKED (i.e. behind the ray origin) |
| 125 | // intersection point + normal if INSIDE the AABB. |
no test coverage detected