diff options
author | Jesse Morgan <jesse@jesterpm.net> | 2011-02-20 09:12:14 +0000 |
---|---|---|
committer | Jesse Morgan <jesse@jesterpm.net> | 2011-02-20 09:12:14 +0000 |
commit | d6e8cbe83fc8011b59189a5c62ec21ab7e5e6e98 (patch) | |
tree | 018b2be177e01301ceaedca57274537a6a26e04f /src | |
parent | d28b3635746c1328ad95c0e30c43447fe6b11c3e (diff) |
Slight improvement.
Diffstat (limited to 'src')
-rw-r--r-- | src/alden/CollidableObject.java | 41 | ||||
-rw-r--r-- | src/tesseract/TesseractUI.java | 2 |
2 files changed, 19 insertions, 24 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);
diff --git a/src/tesseract/TesseractUI.java b/src/tesseract/TesseractUI.java index 4922e52..9a046f1 100644 --- a/src/tesseract/TesseractUI.java +++ b/src/tesseract/TesseractUI.java @@ -160,7 +160,7 @@ public class TesseractUI extends JFrame { //World.addObject(new Box(0.18f, 0.1f, 0.25f, new Vector3f(0.1f, -0.10f, 0))); //myWorld.addObject(new Box(0.18f, 0.25f, 0.1f, new Vector3f(-0.1f, 0, 0))); PhysicalObject s = new Sphere(.05f, new Vector3f()); - s.setAngularVelocity(new Vector3f(0, 0, -1)); + s.setAngularVelocity(new Vector3f(0, 0, 2)); myWorld.addObject(s); //myWorld.addObject(o); |