summaryrefslogtreecommitdiff
path: root/src/tesseract/objects/Sphere.java
diff options
context:
space:
mode:
authorPhillip <pacardon@u.washington.edu>2011-02-23 08:01:32 +0000
committerPhillip <pacardon@u.washington.edu>2011-02-23 08:01:32 +0000
commit943d399633381d5a7138d7276eb13372288189d0 (patch)
tree72853d9350e869038f72c4cdfd96259dbf235c39 /src/tesseract/objects/Sphere.java
parentc730b47ab60148b4dc5c23317121619c4e63224c (diff)
Added color constructor.
Diffstat (limited to 'src/tesseract/objects/Sphere.java')
-rw-r--r--src/tesseract/objects/Sphere.java65
1 files changed, 56 insertions, 9 deletions
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);
}
}