From 5d414f403fa98094c6c571ad7c91342bfcc69883 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Wed, 9 Mar 2011 02:48:37 +0000 Subject: Adding more stuff to common. --- src/common/Box.java | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/common/Box.java (limited to 'src/common/Box.java') 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); + } +} -- cgit v1.2.3