From 350a482b32512191596daad55104beec98af9981 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Wed, 16 Feb 2011 08:12:56 +0000 Subject: Added alden's code, moved his objects into the object class and made them extend physical object. Fixed a node selection problem in TesseractUI. --- src/tesseract/objects/Sphere.java | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/tesseract/objects/Sphere.java (limited to 'src/tesseract/objects/Sphere.java') diff --git a/src/tesseract/objects/Sphere.java b/src/tesseract/objects/Sphere.java new file mode 100644 index 0000000..4ec4aaa --- /dev/null +++ b/src/tesseract/objects/Sphere.java @@ -0,0 +1,35 @@ +package tesseract.objects; +import javax.media.j3d.*; +import javax.vecmath.*; + +import alden.CollidableObject; + +public class Sphere extends PhysicalObject { + public float radius; + + public Sphere(float radius, Vector3f position) { + this(1, radius, position); + } + + public Sphere(float mass, float radius, Vector3f position) { + super(position, mass); + setShape(createShape(radius, 22)); + this.radius = radius; + + 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