From 354041e8d61571b25c6eeb672537a013d3e0fa60 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Fri, 11 Feb 2011 18:53:32 +0000 Subject: Broke the grabbing code but added Alden's collision code. Not sure if its working yet since my Mac doesn't like it. --- src/alden/Sphere.java | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/alden/Sphere.java (limited to 'src/alden/Sphere.java') diff --git a/src/alden/Sphere.java b/src/alden/Sphere.java new file mode 100644 index 0000000..df063a3 --- /dev/null +++ b/src/alden/Sphere.java @@ -0,0 +1,34 @@ +package alden; +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); + } +} -- cgit v1.2.3