Fix for proper collision distance based on

precedent.  "I had one job..."
experimental
pspeed42 10 years ago
parent 0633c0c5bc
commit 1b0f6d0f59
  1. 14
      jme3-core/src/main/java/com/jme3/bounding/BoundingSphere.java

@ -850,9 +850,13 @@ public class BoundingSphere extends BoundingVolume {
Vector3f part2 = ab;
Vector3f p = center.add(a.add(part1.mult(u)).addLocal(part2.mult(v)));
CollisionResult r = new CollisionResult();
r.setDistance((float)Math.sqrt(d) - radius);
r.setContactNormal(n.normalize());
CollisionResult r = new CollisionResult();
Vector3f normal = n.normalize();
float dist = -normal.dot(a); // a is center relative, so -a points to center
dist = dist - radius;
r.setDistance(dist);
r.setContactNormal(normal);
r.setContactPoint(p);
results.addCollision(r);
return 1;
@ -920,7 +924,7 @@ public class BoundingSphere extends BoundingVolume {
Vector3f cn = nearestPt.divide(-dist);
CollisionResult r = new CollisionResult();
r.setDistance(dist);
r.setDistance(dist - radius);
r.setContactNormal(cn);
r.setContactPoint(nearestPt.add(center));
results.addCollision(r);
@ -960,7 +964,7 @@ public class BoundingSphere extends BoundingVolume {
Vector3f cn = nearestPt.divide(-dist);
CollisionResult r = new CollisionResult();
r.setDistance(dist);
r.setDistance(dist - radius);
r.setContactNormal(cn);
r.setContactPoint(nearestPt.add(center));
results.addCollision(r);

Loading…
Cancel
Save