summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/alden/CollidableObject.java47
-rw-r--r--src/tesseract/TesseractUI.java21
-rw-r--r--src/tesseract/forces/AirDrag.java34
-rw-r--r--src/tesseract/objects/Icosahedron.java2
4 files changed, 49 insertions, 55 deletions
diff --git a/src/alden/CollidableObject.java b/src/alden/CollidableObject.java
index 7246609..1f0d285 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.3f;
+ rotationalFriction = 0.05f;
TG = new TransformGroup();
TG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
BG = new BranchGroup();
@@ -237,25 +237,6 @@ public abstract class CollidableObject {
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 * ci.contactNormal.dot(angularVelocity), angularVelocity, angularVelocity);
- other.angularVelocity.scaleAdd(-rotationalFriction * ci.contactNormal.dot(other.angularVelocity), other.angularVelocity, other.angularVelocity);
}
Vector3f thisMovementUnit = new Vector3f();
@@ -300,5 +281,31 @@ public abstract class CollidableObject {
tmp2.mul(other.orientation);
other.orientation.add(tmp2);
other.orientation.normalize();
+
+ if (rotationalFriction > 0) {
+ /* 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);
+ w.cross(previousRotationalVelocity, ci.contactNormal);
+ angularVelocity.scaleAdd(-0.5f * w.dot(angularVelocity), w, angularVelocity);
+
+ 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);
+ w.cross(other.previousRotationalVelocity, ci.contactNormal);
+ other.angularVelocity.scaleAdd(-0.5f * w.dot(other.angularVelocity), w, other.angularVelocity);
+ */
+
+ angularVelocity.scaleAdd(-rotationalFriction * ci.contactNormal.dot(angularVelocity), ci.contactNormal, angularVelocity);
+ other.angularVelocity.scaleAdd(-rotationalFriction * ci.contactNormal.dot(other.angularVelocity), ci.contactNormal, other.angularVelocity);
+
+ }
}
}
diff --git a/src/tesseract/TesseractUI.java b/src/tesseract/TesseractUI.java
index bf5bc59..652ec2b 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, 2));
+ s.setAngularVelocity(new Vector3f(0, 0, -2));
myWorld.addObject(s);
//myWorld.addObject(o);
@@ -296,6 +296,25 @@ public class TesseractUI extends JFrame {
});
forcesMenu.add(originQuadradic);
+ final JMenuItem airDrag = new JCheckBoxMenuItem("Air Drag", false);
+ originQuadradic.addActionListener(new ActionListener() {
+ private Force me;
+
+ // Constructor
+ {
+ me = new AirDrag();
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ if (((JCheckBoxMenuItem) e.getSource()).isSelected()) {
+ myWorld.addForce(me);
+ } else {
+ myWorld.removeForce(me);
+ }
+ }
+ });
+ forcesMenu.add(airDrag);
+
menuBar.add(forcesMenu);
// Add reset Simulator menu item
diff --git a/src/tesseract/forces/AirDrag.java b/src/tesseract/forces/AirDrag.java
index 43cbfe5..b6f0dbd 100644
--- a/src/tesseract/forces/AirDrag.java
+++ b/src/tesseract/forces/AirDrag.java
@@ -76,45 +76,13 @@ public class AirDrag extends Force {
float force = 0.5f * v.lengthSquared() * COEFFICIENT * surfaceArea;
- System.out.println(v.lengthSquared());
- System.out.println(force);
-
v.normalize();
v.scale(-force);
- System.out.println(v);
-
return new Vector3f();
}
- public static void main(String[] args) {
- AirDrag ad = new AirDrag();
-
- ArrayList<Vector2f> points = new ArrayList<Vector2f>();
-
- /*points.add(new Vector2f(2, 1));
- points.add(new Vector2f(2, 3));
- points.add(new Vector2f(3, 4.5f));
- points.add(new Vector2f(4, 2));
- points.add(new Vector2f(4, 7));
- points.add(new Vector2f(1, 2));
- points.add(new Vector2f(1, 5));
- points.add(new Vector2f(1.5f, 7));*/
-
- points.add(new Vector2f(0, 0));
- points.add(new Vector2f(0, 3));
- points.add(new Vector2f(3, 3));
- points.add(new Vector2f(3, 0));
- points.add(new Vector2f(1, 2));
- points.add(new Vector2f(0, 1));
-
- List<Vector2f> newPoints = ad.convexHull(points);
- System.out.println(newPoints);
-
- System.out.println(ad.areaOfHull(newPoints));
- }
-
/**
*
* @param hull vector list.
@@ -139,7 +107,7 @@ public class AirDrag extends Force {
}
/**
- *
+ * Graham's convex hull algorithm from pseudocode on wikipedia.
* @param points point list.
* @return point list.
*/
diff --git a/src/tesseract/objects/Icosahedron.java b/src/tesseract/objects/Icosahedron.java
index f58db78..67e74a3 100644
--- a/src/tesseract/objects/Icosahedron.java
+++ b/src/tesseract/objects/Icosahedron.java
@@ -34,7 +34,7 @@ public class Icosahedron extends PhysicalObject {
/**
* Default Icosohedran Scale.
*/
- public static final float DEFAULT_SCALE = 0.2f;
+ public static final float DEFAULT_SCALE = 0.1f;
/**
* Vertex count in Icosohedran.