@@ -272,7 +272,7 @@ class Geometry3D {
272272 return true ;
273273 }
274274
275- static bool segment_intersects_convex (const Vector3 &p_from, const Vector3 &p_to, const Plane *p_planes, int p_plane_count, Vector3 *p_res , Vector3 *p_norm ) {
275+ static bool segment_intersects_convex (const Vector3 &p_from, const Vector3 &p_to, const Plane *p_planes, int p_plane_count, Vector3 *r_res , Vector3 *r_norm ) {
276276 real_t min = -1e20 , max = 1e20 ;
277277
278278 Vector3 rel = p_to - p_from;
@@ -315,46 +315,58 @@ class Geometry3D {
315315 return false ; // No intersection.
316316 }
317317
318- if (p_res ) {
319- *p_res = p_from + dir * min;
318+ if (r_res ) {
319+ *r_res = p_from + dir * min;
320320 }
321- if (p_norm ) {
322- *p_norm = p_planes[min_index].normal ;
321+ if (r_norm ) {
322+ *r_norm = p_planes[min_index].normal ;
323323 }
324324
325325 return true ;
326326 }
327327
328+ #ifndef DISABLE_DEPRECATED
328329 static Vector3 get_closest_point_to_segment (const Vector3 &p_point, const Vector3 *p_segment) {
329- Vector3 p = p_point - p_segment[0 ];
330- Vector3 n = p_segment[1 ] - p_segment[0 ];
330+ return get_closest_point_to_segment (p_point, p_segment[0 ], p_segment[1 ]);
331+ }
332+ #endif // DISABLE_DEPRECATED
333+
334+ static Vector3 get_closest_point_to_segment (const Vector3 &p_point, const Vector3 &p_segment_a, const Vector3 &p_segment_b) {
335+ Vector3 p = p_point - p_segment_a;
336+ Vector3 n = p_segment_b - p_segment_a;
331337 real_t l2 = n.length_squared ();
332338 if (l2 < 1e-20f ) {
333- return p_segment[ 0 ] ; // Both points are the same, just give any.
339+ return p_segment_a ; // Both points are the same, just give any.
334340 }
335341
336342 real_t d = n.dot (p) / l2;
337343
338344 if (d <= 0 .0f ) {
339- return p_segment[ 0 ] ; // Before first point.
345+ return p_segment_a ; // Before first point.
340346 } else if (d >= 1 .0f ) {
341- return p_segment[ 1 ] ; // After first point.
347+ return p_segment_b ; // After first point.
342348 } else {
343- return p_segment[ 0 ] + n * d; // Inside.
349+ return p_segment_a + n * d; // Inside.
344350 }
345351 }
346352
353+ #ifndef DISABLE_DEPRECATED
347354 static Vector3 get_closest_point_to_segment_uncapped (const Vector3 &p_point, const Vector3 *p_segment) {
348- Vector3 p = p_point - p_segment[0 ];
349- Vector3 n = p_segment[1 ] - p_segment[0 ];
355+ return get_closest_point_to_segment_uncapped (p_point, p_segment[0 ], p_segment[1 ]);
356+ }
357+ #endif // DISABLE_DEPRECATED
358+
359+ static Vector3 get_closest_point_to_segment_uncapped (const Vector3 &p_point, const Vector3 &p_segment_a, const Vector3 &p_segment_b) {
360+ Vector3 p = p_point - p_segment_a;
361+ Vector3 n = p_segment_b - p_segment_a;
350362 real_t l2 = n.length_squared ();
351363 if (l2 < 1e-20f ) {
352- return p_segment[ 0 ] ; // Both points are the same, just give any.
364+ return p_segment_a ; // Both points are the same, just give any.
353365 }
354366
355367 real_t d = n.dot (p) / l2;
356368
357- return p_segment[ 0 ] + n * d; // Inside.
369+ return p_segment_a + n * d; // Inside.
358370 }
359371
360372 static inline bool point_in_projected_triangle (const Vector3 &p_point, const Vector3 &p_v1, const Vector3 &p_v2, const Vector3 &p_v3) {
@@ -381,8 +393,14 @@ class Geometry3D {
381393 return true ;
382394 }
383395
396+ #ifndef DISABLE_DEPRECATED
384397 static inline bool triangle_sphere_intersection_test (const Vector3 *p_triangle, const Vector3 &p_normal, const Vector3 &p_sphere_pos, real_t p_sphere_radius, Vector3 &r_triangle_contact, Vector3 &r_sphere_contact) {
385- real_t d = p_normal.dot (p_sphere_pos) - p_normal.dot (p_triangle[0 ]);
398+ return triangle_sphere_intersection_test (p_triangle[0 ], p_triangle[1 ], p_triangle[2 ], p_normal, p_sphere_pos, p_sphere_radius, r_triangle_contact, r_sphere_contact);
399+ }
400+ #endif // DISABLE_DEPRECATED
401+
402+ static inline bool triangle_sphere_intersection_test (const Vector3 &p_triangle_a, const Vector3 &p_triangle_b, const Vector3 &p_triangle_c, const Vector3 &p_normal, const Vector3 &p_sphere_pos, real_t p_sphere_radius, Vector3 &r_triangle_contact, Vector3 &r_sphere_contact) {
403+ real_t d = p_normal.dot (p_sphere_pos) - p_normal.dot (p_triangle_a);
386404
387405 if (d > p_sphere_radius || d < -p_sphere_radius) {
388406 // Not touching the plane of the face, return.
@@ -393,7 +411,7 @@ class Geometry3D {
393411
394412 /* * 2nd) TEST INSIDE TRIANGLE **/
395413
396- if (Geometry3D::point_in_projected_triangle (contact, p_triangle[ 0 ], p_triangle[ 1 ], p_triangle[ 2 ] )) {
414+ if (Geometry3D::point_in_projected_triangle (contact, p_triangle_a, p_triangle_b, p_triangle_c )) {
397415 r_triangle_contact = contact;
398416 r_sphere_contact = p_sphere_pos - p_normal * p_sphere_radius;
399417 // printf("solved inside triangle\n");
@@ -402,7 +420,7 @@ class Geometry3D {
402420
403421 /* * 3rd TEST INSIDE EDGE CYLINDERS **/
404422
405- const Vector3 verts[4 ] = { p_triangle[ 0 ], p_triangle[ 1 ], p_triangle[ 2 ], p_triangle[ 0 ] }; // for() friendly
423+ const Vector3 verts[4 ] = { p_triangle_a, p_triangle_b, p_triangle_c, p_triangle_a }; // for() friendly
406424
407425 for (int i = 0 ; i < 3 ; i++) {
408426 // Check edge cylinder.
0 commit comments