summaryrefslogtreecommitdiff
path: root/src/common/Box.java
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2011-03-09 02:48:37 +0000
committerJesse Morgan <jesse@jesterpm.net>2011-03-09 02:48:37 +0000
commit5d414f403fa98094c6c571ad7c91342bfcc69883 (patch)
tree72437c1f60df43ee465a7ce212111cfba9a08376 /src/common/Box.java
parentb48fff6b59100439ab3992208800ff0932f85b02 (diff)
Adding more stuff to common.
Diffstat (limited to 'src/common/Box.java')
-rw-r--r--src/common/Box.java33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/common/Box.java b/src/common/Box.java
new file mode 100644
index 0000000..5864606
--- /dev/null
+++ b/src/common/Box.java
@@ -0,0 +1,33 @@
+package common;
+
+import javax.media.j3d.*;
+import javax.vecmath.*;
+
+@SuppressWarnings("restriction")
+public class Box extends CollidableObject {
+ public Box(float width, float height, float depth, Vector3f position) {
+ this(1, width, height, depth, position);
+ }
+
+ public Box(float mass, float width, float height, float depth, Vector3f position) {
+ super(mass);
+ setShape(createShape(width, height, depth));
+ this.position.set(position);
+ previousPosition.set(position);
+ if (inverseMass != 0) {
+ inverseInertiaTensor.m00 = 1f / 12 / inverseMass * (height * height + depth * depth);
+ inverseInertiaTensor.m11 = 1f / 12 / inverseMass * (width * width + depth * depth);
+ inverseInertiaTensor.m22 = 1f / 12 / inverseMass * (width * width + height * height);
+ inverseInertiaTensor.invert();
+ }
+ updateTransformGroup();
+ }
+
+ protected Node createShape(float width, float height, float depth) {
+ Appearance appearance = new Appearance();
+ Material material = new Material();
+ material.setDiffuseColor(0.7f, 1, 0.7f);
+ appearance.setMaterial(material);
+ return new com.sun.j3d.utils.geometry.Box(width / 2, height / 2, depth / 2, appearance);
+ }
+}