change to/from ellipsoid space methods to regular instance methods so we don't have to pass an ellipsoid radius every time

This commit is contained in:
Gered 2013-09-30 04:32:08 -04:00
parent d1d4350ac1
commit f974236432
3 changed files with 25 additions and 25 deletions

View file

@ -67,27 +67,27 @@ public class SweptSphere {
esIntersectionPoint.set(Vector3.Zero); esIntersectionPoint.set(Vector3.Zero);
} }
public static void toEllipsoidSpace(Vector3 in, Vector3 ellipsoidRadius, Vector3 out) { public void toEllipsoidSpace(Vector3 in, Vector3 out) {
out.x = in.x / ellipsoidRadius.x; out.x = in.x / radius.x;
out.y = in.y / ellipsoidRadius.y; out.y = in.y / radius.y;
out.z = in.z / ellipsoidRadius.z; out.z = in.z / radius.z;
} }
public static void toEllipsoidSpace(Vector3 v, Vector3 ellipsoidRadius) { public void toEllipsoidSpace(Vector3 v) {
v.x /= ellipsoidRadius.x; v.x /= radius.x;
v.y /= ellipsoidRadius.y; v.y /= radius.y;
v.z /= ellipsoidRadius.z; v.z /= radius.z;
} }
public static void fromEllipsoidSpace(Vector3 in, Vector3 ellipsoidRadius, Vector3 out) { public void fromEllipsoidSpace(Vector3 in, Vector3 out) {
out.x = in.x * ellipsoidRadius.x; out.x = in.x * radius.x;
out.y = in.y * ellipsoidRadius.y; out.y = in.y * radius.y;
out.z = in.z * ellipsoidRadius.z; out.z = in.z * radius.z;
} }
public static void fromEllipsoidSpace(Vector3 v, Vector3 ellipsoidRadius) { public void fromEllipsoidSpace(Vector3 v) {
v.x *= ellipsoidRadius.x; v.x *= radius.x;
v.y *= ellipsoidRadius.y; v.y *= radius.y;
v.z *= ellipsoidRadius.z; v.z *= radius.z;
} }
} }

View file

@ -20,9 +20,9 @@ public final class SweptSphereCollisionTester {
public static boolean test(SweptSphere sphere, Vector3 v1, Vector3 v2, Vector3 v3) { public static boolean test(SweptSphere sphere, Vector3 v1, Vector3 v2, Vector3 v3) {
boolean foundCollision = false; boolean foundCollision = false;
SweptSphere.toEllipsoidSpace(v1, sphere.radius, p1); sphere.toEllipsoidSpace(v1, p1);
SweptSphere.toEllipsoidSpace(v2, sphere.radius, p2); sphere.toEllipsoidSpace(v2, p2);
SweptSphere.toEllipsoidSpace(v3, sphere.radius, p3); sphere.toEllipsoidSpace(v3, p3);
trianglePlane.set(p1, p2, p3); trianglePlane.set(p1, p2, p3);

View file

@ -67,8 +67,8 @@ public class SweptSphereHandler {
//calculatePossibleCollisionArea(sphere, velocity); //calculatePossibleCollisionArea(sphere, velocity);
// convert position and velocity to ellipsoid space // convert position and velocity to ellipsoid space
SweptSphere.toEllipsoidSpace(sphere.position, sphere.radius, esPosition); sphere.toEllipsoidSpace(sphere.position, esPosition);
SweptSphere.toEllipsoidSpace(velocity, sphere.radius, esVelocity); sphere.toEllipsoidSpace(velocity, esVelocity);
// check for and respond to any collisions along this velocity vector // check for and respond to any collisions along this velocity vector
sphere.nearestCollisionDistance = 0.0f; sphere.nearestCollisionDistance = 0.0f;
@ -79,16 +79,16 @@ public class SweptSphereHandler {
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 // resulting velocity will have been calculated in ellipsoid space
SweptSphere.fromEllipsoidSpace(resultingVelocity, sphere.radius); sphere.fromEllipsoidSpace(resultingVelocity);
if (sphere.foundCollision) if (sphere.foundCollision)
SweptSphere.fromEllipsoidSpace(sphere.esIntersectionPoint, sphere.radius, sphere.nearestCollisionPoint); sphere.fromEllipsoidSpace(sphere.esIntersectionPoint, sphere.nearestCollisionPoint);
// sliding plane origin will be in ellipsoid space still... // sliding plane origin will be in ellipsoid space still...
SweptSphere.fromEllipsoidSpace(sphere.slidingPlaneOrigin, sphere.radius); sphere.fromEllipsoidSpace(sphere.slidingPlaneOrigin);
// convert the new position back to normal space and move the entity there // convert the new position back to normal space and move the entity there
SweptSphere.fromEllipsoidSpace(newEsPosition, sphere.radius, sphere.position); sphere.fromEllipsoidSpace(newEsPosition, sphere.position);
outVelocity.set(resultingVelocity); outVelocity.set(resultingVelocity);
} }