diff options
author | Jesse Morgan <jesse@jesterpm.net> | 2011-03-09 02:48:37 +0000 |
---|---|---|
committer | Jesse Morgan <jesse@jesterpm.net> | 2011-03-09 02:48:37 +0000 |
commit | 5d414f403fa98094c6c571ad7c91342bfcc69883 (patch) | |
tree | 72437c1f60df43ee465a7ce212111cfba9a08376 /src/common/Sphere.java | |
parent | b48fff6b59100439ab3992208800ff0932f85b02 (diff) |
Adding more stuff to common.
Diffstat (limited to 'src/common/Sphere.java')
-rw-r--r-- | src/common/Sphere.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/common/Sphere.java b/src/common/Sphere.java new file mode 100644 index 0000000..af755d9 --- /dev/null +++ b/src/common/Sphere.java @@ -0,0 +1,35 @@ +package common;
+
+import javax.media.j3d.*;
+import javax.vecmath.*;
+
+@SuppressWarnings("restriction")
+public class Sphere extends CollidableObject {
+ protected float radius;
+
+ public Sphere(float radius, Vector3f position) {
+ this(1, radius, position);
+ }
+
+ public Sphere(float mass, float radius, Vector3f position) {
+ super(mass);
+ setShape(createShape(radius, 22));
+ this.radius = radius;
+ this.position.set(position);
+ if (inverseMass != 0) {
+ inverseInertiaTensor.m00 = 2f / 5 / inverseMass * radius * radius;
+ inverseInertiaTensor.m11 = inverseInertiaTensor.m00;
+ inverseInertiaTensor.m22 = inverseInertiaTensor.m00;
+ inverseInertiaTensor.invert();
+ }
+ updateTransformGroup();
+ }
+
+ protected Node createShape(float radius, int divisions) {
+ Appearance appearance = new Appearance();
+ Material material = new Material();
+ material.setDiffuseColor(0.7f, 0.7f, 1);
+ appearance.setMaterial(material);
+ return new com.sun.j3d.utils.geometry.Sphere(radius, com.sun.j3d.utils.geometry.Sphere.GENERATE_NORMALS, divisions, appearance);
+ }
+}
|