Fix for proper collision distance based on

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

@ -851,8 +851,12 @@ public class BoundingSphere extends BoundingVolume {
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());
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