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 part2 = ab;
Vector3f p = center.add(a.add(part1.mult(u)).addLocal(part2.mult(v))); Vector3f p = center.add(a.add(part1.mult(u)).addLocal(part2.mult(v)));
CollisionResult r = new CollisionResult(); CollisionResult r = new CollisionResult();
r.setDistance((float)Math.sqrt(d) - radius); Vector3f normal = n.normalize();
r.setContactNormal(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); r.setContactPoint(p);
results.addCollision(r); results.addCollision(r);
return 1; return 1;
@ -920,7 +924,7 @@ public class BoundingSphere extends BoundingVolume {
Vector3f cn = nearestPt.divide(-dist); Vector3f cn = nearestPt.divide(-dist);
CollisionResult r = new CollisionResult(); CollisionResult r = new CollisionResult();
r.setDistance(dist); r.setDistance(dist - radius);
r.setContactNormal(cn); r.setContactNormal(cn);
r.setContactPoint(nearestPt.add(center)); r.setContactPoint(nearestPt.add(center));
results.addCollision(r); results.addCollision(r);
@ -960,7 +964,7 @@ public class BoundingSphere extends BoundingVolume {
Vector3f cn = nearestPt.divide(-dist); Vector3f cn = nearestPt.divide(-dist);
CollisionResult r = new CollisionResult(); CollisionResult r = new CollisionResult();
r.setDistance(dist); r.setDistance(dist - radius);
r.setContactNormal(cn); r.setContactNormal(cn);
r.setContactPoint(nearestPt.add(center)); r.setContactPoint(nearestPt.add(center));
results.addCollision(r); results.addCollision(r);

Loading…
Cancel
Save