From 2d6b06a6e4169c301527efe4635f58a390cf79a7 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Sat, 19 Feb 2011 20:04:05 +0000 Subject: Added dynamic friction. --- src/alden/CollidableObject.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/alden/CollidableObject.java b/src/alden/CollidableObject.java index 236b731..a2738fa 100644 --- a/src/alden/CollidableObject.java +++ b/src/alden/CollidableObject.java @@ -212,6 +212,26 @@ public abstract class CollidableObject { if (totalInverseMass == 0) return; + /* Dynamic Friction */ + if (dynamicFriction > 0) { + Vector3f perpVelocity = new Vector3f(); + perpVelocity.scaleAdd(initialClosingSpeed, ci.contactNormal, previousVelocity); + if (perpVelocity.length() > 0) { + perpVelocity.normalize(); + Vector3f acceleration = new Vector3f(); + acceleration.scaleAdd(-1, previousVelocity, velocity); + velocity.scaleAdd(dynamicFriction * acceleration.dot(ci.contactNormal), perpVelocity, velocity); + } + + perpVelocity.scaleAdd(initialClosingSpeed, ci.contactNormal, other.previousVelocity); + if (perpVelocity.length() > 0) { + perpVelocity.normalize(); + Vector3f acceleration = new Vector3f(); + acceleration.scaleAdd(-1, other.previousVelocity, other.velocity); + other.velocity.scaleAdd(dynamicFriction * acceleration.dot(ci.contactNormal), perpVelocity, other.velocity); + } + } + Vector3f thisMovementUnit = new Vector3f(); thisMovementUnit.cross(thisRelativeContactPosition, ci.contactNormal); getInverseInertiaTensor().transform(thisMovementUnit); -- cgit v1.2.3