summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/alden/CollidableObject.java65
-rw-r--r--src/tesseract/TesseractUI.java10
-rw-r--r--src/tesseract/forces/AirDrag.java6
-rw-r--r--src/tesseract/objects/PhysicalObject.java4
4 files changed, 62 insertions, 23 deletions
diff --git a/src/alden/CollidableObject.java b/src/alden/CollidableObject.java
index a2738fa..a8c4975 100644
--- a/src/alden/CollidableObject.java
+++ b/src/alden/CollidableObject.java
@@ -13,11 +13,13 @@ public abstract class CollidableObject {
protected Vector3f forceAccumulator;
protected Quat4f orientation;
protected Vector3f angularVelocity;
+ protected Vector3f previousRotationalVelocity;
protected Vector3f torqueAccumulator;
protected Matrix3f inverseInertiaTensor;
protected float coefficientOfRestitution;
protected float penetrationCorrection;
protected float dynamicFriction;
+ protected float rotationalFriction;
protected BranchGroup BG;
protected TransformGroup TG;
protected Node node;
@@ -43,11 +45,13 @@ public abstract class CollidableObject {
forceAccumulator = new Vector3f();
orientation = new Quat4f(0, 0, 0, 1);
angularVelocity = new Vector3f();
+ previousRotationalVelocity = new Vector3f();
torqueAccumulator = new Vector3f();
inverseInertiaTensor = new Matrix3f();
coefficientOfRestitution = 0.75f;
penetrationCorrection = 1.05f;
dynamicFriction = 0.02f;
+ rotationalFriction = 0.017f;
TG = new TransformGroup();
TG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
BG = new BranchGroup();
@@ -194,44 +198,71 @@ public abstract class CollidableObject {
Vector3f thisRelativeContactPosition = new Vector3f();
thisRelativeContactPosition.scaleAdd(-1, position, ci.contactPoint);
thisRelativeContactPosition.scaleAdd(-1, centerOfMass, thisRelativeContactPosition);
- Vector3f thisContactVelocity = new Vector3f();
- thisContactVelocity.cross(angularVelocity, thisRelativeContactPosition);
- thisContactVelocity.add(previousVelocity);
Vector3f otherRelativeContactPosition = new Vector3f();
otherRelativeContactPosition.scaleAdd(-1, other.position, ci.contactPoint);
otherRelativeContactPosition.scaleAdd(-1, other.centerOfMass, otherRelativeContactPosition);
- 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();
Vector3f perpVelocity = new Vector3f();
- perpVelocity.scaleAdd(initialClosingSpeed, ci.contactNormal, previousVelocity);
+ float contactSpeed = ci.contactNormal.dot(velocity) - ci.contactNormal.dot(other.velocity);
+
+ perpVelocity.scaleAdd(-contactSpeed, 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);
+ perpVelocity.scaleAdd(contactSpeed, 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);
}
+
+ /* Rotational Friction */
+ Vector3f w = new Vector3f();
+
+ float radius = thisRelativeContactPosition.length();
+ w.cross(angularVelocity, ci.contactNormal);
+ velocity.scaleAdd(-1, previousRotationalVelocity, velocity);
+ previousRotationalVelocity.scale(radius, w);
+ velocity.scaleAdd(radius, w, velocity);
+
+ radius = otherRelativeContactPosition.length();
+ w.cross(other.angularVelocity, ci.contactNormal);
+ other.velocity.scaleAdd(-1, other.previousRotationalVelocity, other.velocity);
+ other.previousRotationalVelocity.scale(radius, w);
+ other.velocity.scaleAdd(radius, w, other.velocity);
+
+
+ angularVelocity.scaleAdd(-rotationalFriction, angularVelocity);
+ other.angularVelocity.scaleAdd(-rotationalFriction, 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 fed3939..4922e52 100644
--- a/src/tesseract/TesseractUI.java
+++ b/src/tesseract/TesseractUI.java
@@ -45,6 +45,7 @@ import tesseract.menuitems.SurfBoardMenuItem;
import tesseract.objects.Box;
import tesseract.objects.ChainLink2;
import tesseract.objects.PhysicalObject;
+import tesseract.objects.Sphere;
import com.sun.j3d.utils.picking.PickCanvas;
import com.sun.j3d.utils.picking.PickResult;
@@ -154,10 +155,13 @@ public class TesseractUI extends JFrame {
ChainLink2 o = new ChainLink2(new Vector3f(), 1);
o.setRotation();
- myWorld.addForce(new AirDrag());
+ //myWorld.addForce(new AirDrag());
- myWorld.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)));
+ //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));
+ myWorld.addObject(s);
//myWorld.addObject(o);
}
diff --git a/src/tesseract/forces/AirDrag.java b/src/tesseract/forces/AirDrag.java
index c27ec7e..356de7a 100644
--- a/src/tesseract/forces/AirDrag.java
+++ b/src/tesseract/forces/AirDrag.java
@@ -74,9 +74,9 @@ public class AirDrag extends Force {
float surfaceArea = areaOfHull(hull);
- float force = 0.5f * v.length() * COEFFICIENT * surfaceArea;
+ float force = 0.5f * v.lengthSquared() * COEFFICIENT * surfaceArea;
- System.out.println(v.length());
+ System.out.println(v.lengthSquared());
System.out.println(force);
v.normalize();
@@ -84,7 +84,7 @@ public class AirDrag extends Force {
System.out.println(v);
- return v;
+ return new Vector3f();
}
diff --git a/src/tesseract/objects/PhysicalObject.java b/src/tesseract/objects/PhysicalObject.java
index e2f31c8..c743e8e 100644
--- a/src/tesseract/objects/PhysicalObject.java
+++ b/src/tesseract/objects/PhysicalObject.java
@@ -142,5 +142,9 @@ public class PhysicalObject extends CollidableObject {
public float getInverseMass() {
return this.inverseMass;
+ }
+
+ public void setAngularVelocity(final Vector3f velocity) {
+ this.angularVelocity = velocity;
}
} \ No newline at end of file