various code formatting cleanups

This commit is contained in:
Gered 2013-09-30 04:40:08 -04:00
parent f974236432
commit 308b19e815
2 changed files with 47 additions and 28 deletions

View file

@ -103,8 +103,11 @@ public final class SweptSphereCollisionTester {
a = velocitySquaredLength; a = velocitySquaredLength;
// P1 // P1
b = 2.0f * velocity.dot(tmp1.set(base).sub(p1)); b = 2.0f * velocity.dot(tmp1.set(base)
c = tmp1.set(p1).sub(base).len2() - 1.0f; .sub(p1));
c = tmp1.set(p1)
.sub(base)
.len2() - 1.0f;
newT = MathHelpers.getLowestQuadraticRoot(a, b, c, t); newT = MathHelpers.getLowestQuadraticRoot(a, b, c, t);
if (!Float.isNaN(newT)) { if (!Float.isNaN(newT)) {
t = newT; t = newT;
@ -113,8 +116,11 @@ public final class SweptSphereCollisionTester {
} }
// P2 // P2
b = 2.0f * velocity.dot(tmp1.set(base).sub(p2)); b = 2.0f * velocity.dot(tmp1.set(base)
c = tmp1.set(p2).sub(base).len2() - 1.0f; .sub(p2));
c = tmp1.set(p2)
.sub(base)
.len2() - 1.0f;
newT = MathHelpers.getLowestQuadraticRoot(a, b, c, t); newT = MathHelpers.getLowestQuadraticRoot(a, b, c, t);
if (!Float.isNaN(newT)) { if (!Float.isNaN(newT)) {
t = newT; t = newT;
@ -123,8 +129,11 @@ public final class SweptSphereCollisionTester {
} }
// P3 // P3
b = 2.0f * velocity.dot(tmp1.set(base).sub(p3)); b = 2.0f * velocity.dot(tmp1.set(base)
c = tmp1.set(p3).sub(base).len2() - 1.0f; .sub(p3));
c = tmp1.set(p3)
.sub(base)
.len2() - 1.0f;
newT = MathHelpers.getLowestQuadraticRoot(a, b, c, t); newT = MathHelpers.getLowestQuadraticRoot(a, b, c, t);
if (!Float.isNaN(newT)) { if (!Float.isNaN(newT)) {
t = newT; t = newT;
@ -135,8 +144,10 @@ public final class SweptSphereCollisionTester {
// Now check against the edges // Now check against the edges
// P1 -> P2 // P1 -> P2
edge.set(p2).sub(p1); edge.set(p2)
baseToVertex.set(p1).sub(base); .sub(p1);
baseToVertex.set(p1)
.sub(base);
float edgeSquaredLength = edge.len2(); float edgeSquaredLength = edge.len2();
float edgeDotVelocity = edge.dot(velocity); float edgeDotVelocity = edge.dot(velocity);
float edgeDotBaseToVertex = edge.dot(baseToVertex); float edgeDotBaseToVertex = edge.dot(baseToVertex);
@ -153,13 +164,17 @@ public final class SweptSphereCollisionTester {
// Intersection took place within the segment // Intersection took place within the segment
t = newT; t = newT;
foundCollision = true; foundCollision = true;
collisionPoint.set(p1).add(tmp1.set(edge).scl(f)); collisionPoint.set(p1)
.add(tmp1.set(edge)
.scl(f));
} }
} }
// P2 -> P3 // P2 -> P3
edge.set(p3).sub(p2); edge.set(p3)
baseToVertex.set(p2).sub(base); .sub(p2);
baseToVertex.set(p2)
.sub(base);
edgeSquaredLength = edge.len2(); edgeSquaredLength = edge.len2();
edgeDotVelocity = edge.dot(velocity); edgeDotVelocity = edge.dot(velocity);
edgeDotBaseToVertex = edge.dot(baseToVertex); edgeDotBaseToVertex = edge.dot(baseToVertex);
@ -176,13 +191,17 @@ public final class SweptSphereCollisionTester {
// Intersection took place within the segment // Intersection took place within the segment
t = newT; t = newT;
foundCollision = true; foundCollision = true;
collisionPoint.set(p2).add(tmp1.set(edge).scl(f)); collisionPoint.set(p2)
.add(tmp1.set(edge)
.scl(f));
} }
} }
// P3 -> P1 // P3 -> P1
edge.set(p1).sub(p3); edge.set(p1)
baseToVertex.set(p3).sub(base); .sub(p3);
baseToVertex.set(p3)
.sub(base);
edgeSquaredLength = edge.len2(); edgeSquaredLength = edge.len2();
edgeDotVelocity = edge.dot(velocity); edgeDotVelocity = edge.dot(velocity);
edgeDotBaseToVertex = edge.dot(baseToVertex); edgeDotBaseToVertex = edge.dot(baseToVertex);
@ -199,7 +218,9 @@ public final class SweptSphereCollisionTester {
// Intersection took place within the segment // Intersection took place within the segment
t = newT; t = newT;
foundCollision = true; foundCollision = true;
collisionPoint.set(p3).add(tmp1.set(edge).scl(f)); collisionPoint.set(p3)
.add(tmp1.set(edge)
.scl(f));
} }
} }
} }

View file

@ -78,18 +78,13 @@ public class SweptSphereHandler {
resultingVelocity.set(Vector3.Zero); resultingVelocity.set(Vector3.Zero);
Vector3 newEsPosition = getNewPositionForMovement(0, sphere, esPosition, esVelocity, resultingVelocity, canSlide, onlySlideIfTooSteep, tooSteepAngleY); 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(resultingVelocity);
sphere.fromEllipsoidSpace(sphere.slidingPlaneOrigin);
sphere.fromEllipsoidSpace(newEsPosition, sphere.position);
if (sphere.foundCollision) if (sphere.foundCollision)
sphere.fromEllipsoidSpace(sphere.esIntersectionPoint, sphere.nearestCollisionPoint); 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); outVelocity.set(resultingVelocity);
} }
else else
@ -127,11 +122,13 @@ public class SweptSphereHandler {
// if there was no collision, simply move along the velocity vector // if there was no collision, simply move along the velocity vector
if (!sphere.foundCollision) if (!sphere.foundCollision)
return resultingPosition.set(currentPosition).add(velocity); return resultingPosition.set(currentPosition)
.add(velocity);
// a collision did occur // a collision did occur
tmpDestination.set(currentPosition).add(velocity); tmpDestination.set(currentPosition)
.add(velocity);
tmpNewPosition.set(currentPosition); tmpNewPosition.set(currentPosition);
if (sphere.nearestCollisionDistance >= collisionVeryCloseDistance) { if (sphere.nearestCollisionDistance >= collisionVeryCloseDistance) {
@ -152,13 +149,14 @@ public class SweptSphereHandler {
moveUpLength = sphere.nearestCollisionDistance - (collisionVeryCloseDistance * 0.5f); moveUpLength = sphere.nearestCollisionDistance - (collisionVeryCloseDistance * 0.5f);
MathHelpers.setLengthOf(tmp1.set(velocity), moveUpLength); 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 // adjust the polygon intersection point, so the sliding plane will be
// unaffected by the fact that we move slightly less than the collision // unaffected by the fact that we move slightly less than the collision
// tells us // tells us
tmp1.nor(); tmp1.nor()
tmp1.scl(collisionVeryCloseDistance); .scl(collisionVeryCloseDistance);
sphere.esIntersectionPoint.sub(tmp1); sphere.esIntersectionPoint.sub(tmp1);
} }