From 943d399633381d5a7138d7276eb13372288189d0 Mon Sep 17 00:00:00 2001 From: Phillip Date: Wed, 23 Feb 2011 08:01:32 +0000 Subject: Added color constructor. --- src/tesseract/objects/Sphere.java | 65 +++++++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 9 deletions(-) (limited to 'src/tesseract/objects/Sphere.java') diff --git a/src/tesseract/objects/Sphere.java b/src/tesseract/objects/Sphere.java index 4ec4aaa..cb93041 100644 --- a/src/tesseract/objects/Sphere.java +++ b/src/tesseract/objects/Sphere.java @@ -1,23 +1,63 @@ package tesseract.objects; +import java.awt.Color; + import javax.media.j3d.*; import javax.vecmath.*; import alden.CollidableObject; +/** + * Sphere. + * @author ? + * + */ public class Sphere extends PhysicalObject { + /** + * Default Object color. + */ + private static final Color3f DEFAULT_COLOR = new Color3f(0.7f, 0.7f, 1); + + /** + * Default divisions. + */ + private static final int DEFAULT_DIVISIONS = 22; + + /** + * User definable color. + */ + private final Color3f myColor; + + /** + * radius of sphere. + */ public float radius; - public Sphere(float radius, Vector3f position) { - this(1, radius, position); + /** + * Constructor. + * @param theRadius of sphere. + * @param position to start. + */ + public Sphere(final float theRadius, final Vector3f position) { + this(1, theRadius, position, DEFAULT_COLOR.get()); } - public Sphere(float mass, float radius, Vector3f position) { + /** + * constructor. + * @param mass of object. + * @param theRadius of sphere. + * @param position of sphere. + * @param theColor of sphere. + */ + public Sphere(final float mass, final float theRadius, + final Vector3f position, final Color theColor) { super(position, mass); - setShape(createShape(radius, 22)); - this.radius = radius; + myColor = new Color3f(theColor); + setShape(createShape(DEFAULT_DIVISIONS)); + radius = theRadius; if (inverseMass != 0) { - inverseInertiaTensor.m00 = 2f / 5 / inverseMass * radius * radius; + inverseInertiaTensor.m00 = 2f / 5 / inverseMass + * radius * radius; inverseInertiaTensor.m11 = inverseInertiaTensor.m00; inverseInertiaTensor.m22 = inverseInertiaTensor.m00; inverseInertiaTensor.invert(); @@ -25,11 +65,18 @@ public class Sphere extends PhysicalObject { updateTransformGroup(); } - protected Node createShape(float radius, int divisions) { + /** + * createShape. + * @param divisions + * @return node + */ + protected Node createShape(final int divisions) { Appearance appearance = new Appearance(); Material material = new Material(); - material.setDiffuseColor(0.7f, 0.7f, 1); + material.setDiffuseColor(myColor); appearance.setMaterial(material); - return new com.sun.j3d.utils.geometry.Sphere(radius, com.sun.j3d.utils.geometry.Sphere.GENERATE_NORMALS, divisions, appearance); + return new com.sun.j3d.utils.geometry.Sphere(radius, + com.sun.j3d.utils.geometry.Sphere.GENERATE_NORMALS, + divisions, appearance); } } -- cgit v1.2.3