summaryrefslogtreecommitdiff
path: root/src/alden/CollidableObject.java
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2011-02-20 09:12:14 +0000
committerJesse Morgan <jesse@jesterpm.net>2011-02-20 09:12:14 +0000
commitd6e8cbe83fc8011b59189a5c62ec21ab7e5e6e98 (patch)
tree018b2be177e01301ceaedca57274537a6a26e04f /src/alden/CollidableObject.java
parentd28b3635746c1328ad95c0e30c43447fe6b11c3e (diff)
Slight improvement.
Diffstat (limited to 'src/alden/CollidableObject.java')
-rw-r--r--src/alden/CollidableObject.java41
1 files changed, 18 insertions, 23 deletions
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);