@@ -122,15 +122,15 @@ AABB AABB::intersection(const AABB &p_aabb) const {
122
122
// The caller can therefore decide when INSIDE whether to use the
123
123
// backtracked intersection, or use p_from as the intersection, and
124
124
// carry on progressing without e.g. reflecting against the normal.
125
- bool AABB::find_intersects_ray (const Vector3 &p_from, const Vector3 &p_dir, bool &r_inside, Vector3 *r_intersection_point, Vector3 *r_normal) const {
125
+ bool AABB::find_intersects_ray (const Vector3 &p_from, const Vector3 &p_dir, bool &r_inside, Vector3 *r_intersection_point, Vector3 *r_normal, real_t p_max_distance ) const {
126
126
#ifdef MATH_CHECKS
127
127
if (unlikely (size.x < 0 || size.y < 0 || size.z < 0 )) {
128
128
ERR_PRINT (" AABB size is negative, this is not supported. Use AABB.abs() to get an AABB with a positive size." );
129
129
}
130
130
#endif
131
131
Vector3 end = position + size;
132
- real_t tmin = -1e20 ;
133
- real_t tmax = 1e20 ;
132
+ real_t tmin = -INFINITY ;
133
+ real_t tmax = INFINITY ;
134
134
int axis = 0 ;
135
135
136
136
// Make sure r_inside is always initialized,
@@ -159,7 +159,7 @@ bool AABB::find_intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, bool
159
159
}
160
160
tmax = t2;
161
161
}
162
- if (tmin > tmax) {
162
+ if (tmin > tmax || (p_max_distance > 0 && tmin > p_max_distance) ) {
163
163
return false ;
164
164
}
165
165
}
@@ -185,71 +185,6 @@ bool AABB::find_intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, bool
185
185
return true ;
186
186
}
187
187
188
- bool AABB::intersects_segment (const Vector3 &p_from, const Vector3 &p_to, Vector3 *r_intersection_point, Vector3 *r_normal) const {
189
- #ifdef MATH_CHECKS
190
- if (unlikely (size.x < 0 || size.y < 0 || size.z < 0 )) {
191
- ERR_PRINT (" AABB size is negative, this is not supported. Use AABB.abs() to get an AABB with a positive size." );
192
- }
193
- #endif
194
- real_t min = 0 , max = 1 ;
195
- int axis = 0 ;
196
- real_t sign = 0 ;
197
-
198
- for (int i = 0 ; i < 3 ; i++) {
199
- real_t seg_from = p_from[i];
200
- real_t seg_to = p_to[i];
201
- real_t box_begin = position[i];
202
- real_t box_end = box_begin + size[i];
203
- real_t cmin, cmax;
204
- real_t csign;
205
-
206
- if (seg_from < seg_to) {
207
- if (seg_from > box_end || seg_to < box_begin) {
208
- return false ;
209
- }
210
- real_t length = seg_to - seg_from;
211
- cmin = (seg_from < box_begin) ? ((box_begin - seg_from) / length) : 0 ;
212
- cmax = (seg_to > box_end) ? ((box_end - seg_from) / length) : 1 ;
213
- csign = -1.0 ;
214
-
215
- } else {
216
- if (seg_to > box_end || seg_from < box_begin) {
217
- return false ;
218
- }
219
- real_t length = seg_to - seg_from;
220
- cmin = (seg_from > box_end) ? (box_end - seg_from) / length : 0 ;
221
- cmax = (seg_to < box_begin) ? (box_begin - seg_from) / length : 1 ;
222
- csign = 1.0 ;
223
- }
224
-
225
- if (cmin > min) {
226
- min = cmin;
227
- axis = i;
228
- sign = csign;
229
- }
230
- if (cmax < max) {
231
- max = cmax;
232
- }
233
- if (max < min) {
234
- return false ;
235
- }
236
- }
237
-
238
- Vector3 rel = p_to - p_from;
239
-
240
- if (r_normal) {
241
- Vector3 normal ;
242
- normal [axis] = sign;
243
- *r_normal = normal ;
244
- }
245
-
246
- if (r_intersection_point) {
247
- *r_intersection_point = p_from + rel * min;
248
- }
249
-
250
- return true ;
251
- }
252
-
253
188
bool AABB::intersects_plane (const Plane &p_plane) const {
254
189
Vector3 points[8 ] = {
255
190
Vector3 (position.x , position.y , position.z ),
0 commit comments