From d6e8cbe83fc8011b59189a5c62ec21ab7e5e6e98 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Sun, 20 Feb 2011 09:12:14 +0000 Subject: Slight improvement. --- src/alden/CollidableObject.java | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) (limited to 'src/alden/CollidableObject.java') diff --git a/src/alden/CollidableObject.java b/src/alden/CollidableObject.java index a8c4975..7246609 100644 --- a/src/alden/CollidableObject.java +++ b/src/alden/CollidableObject.java @@ -51,7 +51,7 @@ public abstract class CollidableObject { coefficientOfRestitution = 0.75f; penetrationCorrection = 1.05f; dynamicFriction = 0.02f; - rotationalFriction = 0.017f; + rotationalFriction = 0.3f; TG = new TransformGroup(); TG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); BG = new BranchGroup(); @@ -203,6 +203,21 @@ public abstract class CollidableObject { otherRelativeContactPosition.scaleAdd(-1, other.position, ci.contactPoint); otherRelativeContactPosition.scaleAdd(-1, other.centerOfMass, otherRelativeContactPosition); + Vector3f thisContactVelocity = new Vector3f(); + thisContactVelocity.cross(angularVelocity, thisRelativeContactPosition); + thisContactVelocity.add(previousVelocity); + + Vector3f otherContactVelocity = new Vector3f(); + otherContactVelocity.cross(other.angularVelocity, otherRelativeContactPosition); + otherContactVelocity.add(other.previousVelocity); + + float initialClosingSpeed = ci.contactNormal.dot(thisContactVelocity) - ci.contactNormal.dot(otherContactVelocity); + float finalClosingSpeed = -initialClosingSpeed * coefficientOfRestitution; + float deltaClosingSpeed = finalClosingSpeed - initialClosingSpeed; + float totalInverseMass = inverseMass + other.inverseMass; + if (totalInverseMass == 0) + return; + /* Dynamic Friction */ if (dynamicFriction > 0) { Vector3f acceleration = new Vector3f(); @@ -239,30 +254,10 @@ public abstract class CollidableObject { other.velocity.scaleAdd(radius, w, other.velocity); - angularVelocity.scaleAdd(-rotationalFriction, angularVelocity); - other.angularVelocity.scaleAdd(-rotationalFriction, other.angularVelocity); - - + angularVelocity.scaleAdd(-rotationalFriction * ci.contactNormal.dot(angularVelocity), angularVelocity, angularVelocity); + other.angularVelocity.scaleAdd(-rotationalFriction * ci.contactNormal.dot(other.angularVelocity), other.angularVelocity, other.angularVelocity); } - - Vector3f thisContactVelocity = new Vector3f(); - thisContactVelocity.cross(angularVelocity, thisRelativeContactPosition); - thisContactVelocity.add(previousVelocity); - - Vector3f otherContactVelocity = new Vector3f(); - otherContactVelocity.cross(other.angularVelocity, otherRelativeContactPosition); - otherContactVelocity.add(other.previousVelocity); - - float initialClosingSpeed = ci.contactNormal.dot(thisContactVelocity) - ci.contactNormal.dot(otherContactVelocity); - float finalClosingSpeed = -initialClosingSpeed * coefficientOfRestitution; - float deltaClosingSpeed = finalClosingSpeed - initialClosingSpeed; - float totalInverseMass = inverseMass + other.inverseMass; - if (totalInverseMass == 0) - return; - - - Vector3f thisMovementUnit = new Vector3f(); thisMovementUnit.cross(thisRelativeContactPosition, ci.contactNormal); getInverseInertiaTensor().transform(thisMovementUnit); -- cgit v1.2.3