summaryrefslogtreecommitdiff
path: root/src/tesseract/objects/Box.java
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2011-02-16 08:12:56 +0000
committerJesse Morgan <jesse@jesterpm.net>2011-02-16 08:12:56 +0000
commit350a482b32512191596daad55104beec98af9981 (patch)
tree34967e2dd86b18a78a3ea0f8316a502a1e8637d3 /src/tesseract/objects/Box.java
parent5e9f617bdfea01d0bd5e66daf7a5e55f8f94dbf0 (diff)
Added alden's code, moved his objects into the object class and made them extend physical object. Fixed a node selection problem in TesseractUI.
Diffstat (limited to 'src/tesseract/objects/Box.java')
-rw-r--r--src/tesseract/objects/Box.java36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/tesseract/objects/Box.java b/src/tesseract/objects/Box.java
new file mode 100644
index 0000000..fb3dc42
--- /dev/null
+++ b/src/tesseract/objects/Box.java
@@ -0,0 +1,36 @@
+package tesseract.objects;
+import javax.media.j3d.Appearance;
+import javax.media.j3d.Geometry;
+import javax.media.j3d.Material;
+import javax.media.j3d.Node;
+import javax.vecmath.Vector3f;
+
+import com.sun.j3d.utils.geometry.Primitive;
+
+public class Box extends PhysicalObject {
+ 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(position, mass);
+ setShape(createShape(width, height, depth));
+
+ 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);
+ }
+}