|
@@ -593,7 +593,7 @@ int SpaceSW::test_body_ray_separation(BodySW *p_body, const Transform &p_transfo
|
|
|
|
|
|
for (int i = 0; i < p_result_max; i++) {
|
|
for (int i = 0; i < p_result_max; i++) {
|
|
//reset results
|
|
//reset results
|
|
- r_results[i].collision_depth = 0;
|
|
|
|
|
|
+ r_results[i].collision_depth = -1.0;
|
|
}
|
|
}
|
|
|
|
|
|
int rays_found = 0;
|
|
int rays_found = 0;
|
|
@@ -668,18 +668,28 @@ int SpaceSW::test_body_ray_separation(BodySW *p_body, const Transform &p_transfo
|
|
Vector3 a = sr[k * 2 + 0];
|
|
Vector3 a = sr[k * 2 + 0];
|
|
Vector3 b = sr[k * 2 + 1];
|
|
Vector3 b = sr[k * 2 + 1];
|
|
|
|
|
|
- recover_motion += (b - a) / cbk.amount;
|
|
|
|
|
|
+ // Compute plane on b towards a.
|
|
|
|
+ Vector3 n = (a - b).normalized();
|
|
|
|
+ float d = n.dot(b);
|
|
|
|
+
|
|
|
|
+ // Compute depth on recovered motion.
|
|
|
|
+ float depth = n.dot(a + recover_motion) - d;
|
|
|
|
+
|
|
|
|
+ // Apply recovery without margin.
|
|
|
|
+ float separation_depth = depth - p_margin;
|
|
|
|
+ if (separation_depth > 0.0) {
|
|
|
|
+ // Only recover if there is penetration.
|
|
|
|
+ recover_motion -= n * separation_depth;
|
|
|
|
+ }
|
|
|
|
|
|
- float depth = a.distance_to(b);
|
|
|
|
if (depth > result.collision_depth) {
|
|
if (depth > result.collision_depth) {
|
|
result.collision_depth = depth;
|
|
result.collision_depth = depth;
|
|
result.collision_point = b;
|
|
result.collision_point = b;
|
|
- result.collision_normal = (b - a).normalized();
|
|
|
|
|
|
+ result.collision_normal = -n;
|
|
result.collision_local_shape = j;
|
|
result.collision_local_shape = j;
|
|
result.collider = col_obj->get_self();
|
|
result.collider = col_obj->get_self();
|
|
result.collider_id = col_obj->get_instance_id();
|
|
result.collider_id = col_obj->get_instance_id();
|
|
result.collider_shape = shape_idx;
|
|
result.collider_shape = shape_idx;
|
|
- //result.collider_metadata = col_obj->get_shape_metadata(shape_idx);
|
|
|
|
if (col_obj->get_type() == CollisionObjectSW::TYPE_BODY) {
|
|
if (col_obj->get_type() == CollisionObjectSW::TYPE_BODY) {
|
|
BodySW *body = (BodySW *)col_obj;
|
|
BodySW *body = (BodySW *)col_obj;
|
|
|
|
|
|
@@ -704,14 +714,6 @@ int SpaceSW::test_body_ray_separation(BodySW *p_body, const Transform &p_transfo
|
|
} while (recover_attempts);
|
|
} while (recover_attempts);
|
|
}
|
|
}
|
|
|
|
|
|
- //optimize results (remove non colliding)
|
|
|
|
- for (int i = 0; i < rays_found; i++) {
|
|
|
|
- if (r_results[i].collision_depth == 0) {
|
|
|
|
- rays_found--;
|
|
|
|
- SWAP(r_results[i], r_results[rays_found]);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
r_recover_motion = body_transform.origin - p_transform.origin;
|
|
r_recover_motion = body_transform.origin - p_transform.origin;
|
|
return rays_found;
|
|
return rays_found;
|
|
}
|
|
}
|