diff --git a/src/com/blarg/gdx/math/SweptSphereCollisionTester.java b/src/com/blarg/gdx/math/SweptSphereCollisionTester.java index f8640f3..e6fe2f4 100644 --- a/src/com/blarg/gdx/math/SweptSphereCollisionTester.java +++ b/src/com/blarg/gdx/math/SweptSphereCollisionTester.java @@ -103,8 +103,11 @@ public final class SweptSphereCollisionTester { a = velocitySquaredLength; // P1 - b = 2.0f * velocity.dot(tmp1.set(base).sub(p1)); - c = tmp1.set(p1).sub(base).len2() - 1.0f; + b = 2.0f * velocity.dot(tmp1.set(base) + .sub(p1)); + c = tmp1.set(p1) + .sub(base) + .len2() - 1.0f; newT = MathHelpers.getLowestQuadraticRoot(a, b, c, t); if (!Float.isNaN(newT)) { t = newT; @@ -113,8 +116,11 @@ public final class SweptSphereCollisionTester { } // P2 - b = 2.0f * velocity.dot(tmp1.set(base).sub(p2)); - c = tmp1.set(p2).sub(base).len2() - 1.0f; + b = 2.0f * velocity.dot(tmp1.set(base) + .sub(p2)); + c = tmp1.set(p2) + .sub(base) + .len2() - 1.0f; newT = MathHelpers.getLowestQuadraticRoot(a, b, c, t); if (!Float.isNaN(newT)) { t = newT; @@ -123,8 +129,11 @@ public final class SweptSphereCollisionTester { } // P3 - b = 2.0f * velocity.dot(tmp1.set(base).sub(p3)); - c = tmp1.set(p3).sub(base).len2() - 1.0f; + b = 2.0f * velocity.dot(tmp1.set(base) + .sub(p3)); + c = tmp1.set(p3) + .sub(base) + .len2() - 1.0f; newT = MathHelpers.getLowestQuadraticRoot(a, b, c, t); if (!Float.isNaN(newT)) { t = newT; @@ -135,8 +144,10 @@ public final class SweptSphereCollisionTester { // Now check against the edges // P1 -> P2 - edge.set(p2).sub(p1); - baseToVertex.set(p1).sub(base); + edge.set(p2) + .sub(p1); + baseToVertex.set(p1) + .sub(base); float edgeSquaredLength = edge.len2(); float edgeDotVelocity = edge.dot(velocity); float edgeDotBaseToVertex = edge.dot(baseToVertex); @@ -153,13 +164,17 @@ public final class SweptSphereCollisionTester { // Intersection took place within the segment t = newT; foundCollision = true; - collisionPoint.set(p1).add(tmp1.set(edge).scl(f)); + collisionPoint.set(p1) + .add(tmp1.set(edge) + .scl(f)); } } // P2 -> P3 - edge.set(p3).sub(p2); - baseToVertex.set(p2).sub(base); + edge.set(p3) + .sub(p2); + baseToVertex.set(p2) + .sub(base); edgeSquaredLength = edge.len2(); edgeDotVelocity = edge.dot(velocity); edgeDotBaseToVertex = edge.dot(baseToVertex); @@ -176,13 +191,17 @@ public final class SweptSphereCollisionTester { // Intersection took place within the segment t = newT; foundCollision = true; - collisionPoint.set(p2).add(tmp1.set(edge).scl(f)); + collisionPoint.set(p2) + .add(tmp1.set(edge) + .scl(f)); } } // P3 -> P1 - edge.set(p1).sub(p3); - baseToVertex.set(p3).sub(base); + edge.set(p1) + .sub(p3); + baseToVertex.set(p3) + .sub(base); edgeSquaredLength = edge.len2(); edgeDotVelocity = edge.dot(velocity); edgeDotBaseToVertex = edge.dot(baseToVertex); @@ -199,7 +218,9 @@ public final class SweptSphereCollisionTester { // Intersection took place within the segment t = newT; foundCollision = true; - collisionPoint.set(p3).add(tmp1.set(edge).scl(f)); + collisionPoint.set(p3) + .add(tmp1.set(edge) + .scl(f)); } } } diff --git a/src/com/blarg/gdx/math/SweptSphereHandler.java b/src/com/blarg/gdx/math/SweptSphereHandler.java index 835fa48..87d4d9b 100644 --- a/src/com/blarg/gdx/math/SweptSphereHandler.java +++ b/src/com/blarg/gdx/math/SweptSphereHandler.java @@ -78,18 +78,13 @@ public class SweptSphereHandler { resultingVelocity.set(Vector3.Zero); Vector3 newEsPosition = getNewPositionForMovement(0, sphere, esPosition, esVelocity, resultingVelocity, canSlide, onlySlideIfTooSteep, tooSteepAngleY); - // resulting velocity will have been calculated in ellipsoid space + // a bunch of things need to be converted back from ellipsoid space ... sphere.fromEllipsoidSpace(resultingVelocity); - + sphere.fromEllipsoidSpace(sphere.slidingPlaneOrigin); + sphere.fromEllipsoidSpace(newEsPosition, sphere.position); if (sphere.foundCollision) sphere.fromEllipsoidSpace(sphere.esIntersectionPoint, sphere.nearestCollisionPoint); - // sliding plane origin will be in ellipsoid space still... - sphere.fromEllipsoidSpace(sphere.slidingPlaneOrigin); - - // convert the new position back to normal space and move the entity there - sphere.fromEllipsoidSpace(newEsPosition, sphere.position); - outVelocity.set(resultingVelocity); } else @@ -127,11 +122,13 @@ public class SweptSphereHandler { // if there was no collision, simply move along the velocity vector if (!sphere.foundCollision) - return resultingPosition.set(currentPosition).add(velocity); + return resultingPosition.set(currentPosition) + .add(velocity); // a collision did occur - tmpDestination.set(currentPosition).add(velocity); + tmpDestination.set(currentPosition) + .add(velocity); tmpNewPosition.set(currentPosition); if (sphere.nearestCollisionDistance >= collisionVeryCloseDistance) { @@ -152,13 +149,14 @@ public class SweptSphereHandler { moveUpLength = sphere.nearestCollisionDistance - (collisionVeryCloseDistance * 0.5f); MathHelpers.setLengthOf(tmp1.set(velocity), moveUpLength); - tmpNewPosition.set(sphere.esPosition).add(tmp1); + tmpNewPosition.set(sphere.esPosition) + .add(tmp1); // adjust the polygon intersection point, so the sliding plane will be // unaffected by the fact that we move slightly less than the collision // tells us - tmp1.nor(); - tmp1.scl(collisionVeryCloseDistance); + tmp1.nor() + .scl(collisionVeryCloseDistance); sphere.esIntersectionPoint.sub(tmp1); }