diff options
author | Phillip <pacardon@u.washington.edu> | 2011-02-23 08:01:32 +0000 |
---|---|---|
committer | Phillip <pacardon@u.washington.edu> | 2011-02-23 08:01:32 +0000 |
commit | 943d399633381d5a7138d7276eb13372288189d0 (patch) | |
tree | 72853d9350e869038f72c4cdfd96259dbf235c39 | |
parent | c730b47ab60148b4dc5c23317121619c4e63224c (diff) |
Added color constructor.
-rw-r--r-- | src/tesseract/objects/Box.java | 27 | ||||
-rw-r--r-- | src/tesseract/objects/ChainLink2.java | 39 | ||||
-rw-r--r-- | src/tesseract/objects/Ellipsoid.java | 62 | ||||
-rw-r--r-- | src/tesseract/objects/Icosahedron.java | 34 | ||||
-rw-r--r-- | src/tesseract/objects/Sphere.java | 65 | ||||
-rw-r--r-- | src/tesseract/objects/Toroid.java | 34 |
6 files changed, 230 insertions, 31 deletions
diff --git a/src/tesseract/objects/Box.java b/src/tesseract/objects/Box.java index fb3dc42..ca20a68 100644 --- a/src/tesseract/objects/Box.java +++ b/src/tesseract/objects/Box.java @@ -1,19 +1,40 @@ package tesseract.objects;
+import java.awt.Color;
+
import javax.media.j3d.Appearance;
import javax.media.j3d.Geometry;
import javax.media.j3d.Material;
import javax.media.j3d.Node;
+import javax.vecmath.Color3f;
import javax.vecmath.Vector3f;
import com.sun.j3d.utils.geometry.Primitive;
public class Box extends PhysicalObject {
+ /**
+ * default color.
+ */
+ public static final Color3f DEFAULT_COLOR = new Color3f(0.7f, 1, 0.7f);
+
+ /**
+ * Object color.
+ */
+ private final Color3f myColor;
+
+ /**
+ *
+ * @param width
+ * @param height
+ * @param depth
+ * @param position
+ */
public Box(float width, float height, float depth, Vector3f position) {
- this(1, width, height, depth, position);
+ this(1, width, height, depth, position, DEFAULT_COLOR.get());
}
- public Box(float mass, float width, float height, float depth, Vector3f position) {
+ public Box(float mass, float width, float height, float depth, Vector3f position, Color theColor) {
super(position, mass);
+ myColor = new Color3f(theColor);
setShape(createShape(width, height, depth));
previousPosition.set(position);
@@ -29,7 +50,7 @@ public class Box extends PhysicalObject { protected Node createShape(float width, float height, float depth) {
Appearance appearance = new Appearance();
Material material = new Material();
- material.setDiffuseColor(0.7f, 1, 0.7f);
+ material.setDiffuseColor(myColor);
appearance.setMaterial(material);
return new com.sun.j3d.utils.geometry.Box(width / 2, height / 2, depth / 2, appearance);
}
diff --git a/src/tesseract/objects/ChainLink2.java b/src/tesseract/objects/ChainLink2.java index 23a8097..90ded50 100644 --- a/src/tesseract/objects/ChainLink2.java +++ b/src/tesseract/objects/ChainLink2.java @@ -1,11 +1,14 @@ package tesseract.objects; +import java.awt.Color; + import javax.media.j3d.Appearance; import javax.media.j3d.IndexedQuadArray; import javax.media.j3d.Material; import javax.media.j3d.PointArray; import javax.media.j3d.Shape3D; import javax.media.j3d.Transform3D; +import javax.vecmath.Color3f; import javax.vecmath.Point3f; import javax.vecmath.Vector3f; @@ -44,6 +47,16 @@ public class ChainLink2 extends PhysicalObject { protected static final int SLICE_DIVISIONS = 16; /** + * default color. + */ + public static final Color3f DEFAULT_COLOR = new Color3f(1, 0, 0); + + /** + * Object color. + */ + private final Color3f myColor; + + /** * Construct a chain link. * * @param thePosition Position. @@ -51,7 +64,8 @@ public class ChainLink2 extends PhysicalObject { */ public ChainLink2(final Vector3f thePosition, final float mass) { this(thePosition, mass, DEFAULT_LENGTH * DEFAULT_DIAMETER_RATIO, - DEFAULT_LENGTH, DEFAULT_LENGTH * DEFAULT_WIDTH_RATIO); + DEFAULT_LENGTH, DEFAULT_LENGTH * DEFAULT_WIDTH_RATIO, + DEFAULT_COLOR.get()); } /** @@ -65,7 +79,7 @@ public class ChainLink2 extends PhysicalObject { public ChainLink2(final Vector3f thePosition, final float mass, final float length) { this(thePosition, mass, length * DEFAULT_DIAMETER_RATIO, - length, length * DEFAULT_WIDTH_RATIO); + length, length * DEFAULT_WIDTH_RATIO, DEFAULT_COLOR.get()); } /** @@ -76,11 +90,28 @@ public class ChainLink2 extends PhysicalObject { * @param diameter Diameter of link. * @param length Length of link. * @param width Width of link. + * @param theColor color of link. */ public ChainLink2(final Vector3f thePosition, final float mass, final float diameter, final float length, final float width) { + this(thePosition, mass, diameter, length, width, DEFAULT_COLOR.get()); + } + + /** + * Construct a Chain Link. + * + * @param thePosition Position. + * @param mass Mass. + * @param diameter Diameter of link. + * @param length Length of link. + * @param width Width of link. + * @param theColor color of link. + */ + public ChainLink2(final Vector3f thePosition, final float mass, + final float diameter, final float length, final float width, + final Color theColor) { super(thePosition, mass); - + myColor = new Color3f(theColor); setShape(createShape(SLICE_COUNT, SLICE_DIVISIONS, diameter, length, width)); @@ -205,7 +236,7 @@ public class ChainLink2 extends PhysicalObject { Shape3D shape = new Shape3D(gInfo.getGeometryArray()); Appearance app = new Appearance(); Material mat = new Material(); - mat.setDiffuseColor(1, 0, 0); + mat.setDiffuseColor(myColor); app.setMaterial(mat); shape.setAppearance(app); diff --git a/src/tesseract/objects/Ellipsoid.java b/src/tesseract/objects/Ellipsoid.java index 52948e9..d2a752f 100644 --- a/src/tesseract/objects/Ellipsoid.java +++ b/src/tesseract/objects/Ellipsoid.java @@ -6,9 +6,14 @@ package tesseract.objects;
+import java.awt.Color;
+
import javax.media.j3d.Appearance;
+import javax.media.j3d.ColoringAttributes;
+import javax.media.j3d.Material;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
+import javax.vecmath.Color3f;
import javax.vecmath.Matrix3f;
import javax.vecmath.Vector3f;
@@ -33,11 +38,21 @@ public class Ellipsoid extends PhysicalObject { private static final float DEFAULT_MASS = 10;
/**
+ * Default Object color.
+ */
+ private static final Color3f DEFAULT_COLOR = new Color3f(.9f, .05f, .05f);
+
+ /**
+ * User definable color.
+ */
+ private final Color3f myColor;
+
+ /**
* Number of divisions in the sphere.
*/
private static final int DEFAULT_DIVISIONS = 50;
-
+
/**
* Create a new Ellipsoid.
*
@@ -49,12 +64,14 @@ public class Ellipsoid extends PhysicalObject { * @param appearance an Appearance object.
* @param b a float for the b portion of the ellipsoid formula.
* @param c a float for the c portion of the ellipsoid formula.
+ * @param theColor of the object.
*/
public Ellipsoid(final Vector3f position, final float mass,
final float radius, final int primflags, final int divisions,
final Appearance appearance, final float b, final float c) {
super(position, mass);
-
+ myColor = new Color3f();
+ appearance.getMaterial().getDiffuseColor(myColor);
setShape(createShape(radius, primflags, appearance, divisions, b, c));
final float rSq = radius * radius;
@@ -68,18 +85,32 @@ public class Ellipsoid extends PhysicalObject { }
updateTransformGroup();
}
-
+
/**
* Create a new Ellipsoid.
* @author Phillip Cardon
* @param position Initial position.
* @param mass mass of ellipsoid
* @param radius a float for the size of the base sphere.
+ * @param theColor of the object.
*/
public Ellipsoid(final Vector3f position, final float mass,
final float radius) {
+ this(position, mass, radius, DEFAULT_COLOR.get());
+ }
+
+ /**
+ * Create a new Ellipsoid.
+ * @author Phillip Cardon
+ * @param position Initial position.
+ * @param mass mass of ellipsoid
+ * @param radius a float for the size of the base sphere.
+ * @param theColor of the object.
+ */
+ public Ellipsoid(final Vector3f position, final float mass,
+ final float radius, Color theColor) {
super(position, mass);
-
+ myColor = new Color3f(theColor);
final float rSq = radius * radius;
final float a = 1.0f;
final float b = 1.0f;
@@ -104,8 +135,20 @@ public class Ellipsoid extends PhysicalObject { * @param radius a float for the size of the base sphere.
*/
public Ellipsoid(final Vector3f position, final float radius) {
+ this(position, radius, DEFAULT_COLOR.get());
+ }
+
+ /**
+ * Create a new Ellipsoid.
+ *
+ * @param position Initial position.
+ * @param radius a float for the size of the base sphere.
+ * @param theColor of object.
+ */
+ public Ellipsoid(final Vector3f position, final float radius,
+ final Color theColor) {
super(position, DEFAULT_MASS);
-
+ myColor = new Color3f(theColor);
final float rSq = radius * radius;
final float a = 1.0f;
final float b = 1.0f;
@@ -133,9 +176,14 @@ public class Ellipsoid extends PhysicalObject { */
private TransformGroup createDefaultEllipsoid(final float radius, final float a,
final float b, final float c) {
-
+ Appearance meshApp = new Appearance();
+ Material surface = new Material();
+ surface.setDiffuseColor(myColor);
+ meshApp.setMaterial(surface);
+ meshApp.setColoringAttributes(new ColoringAttributes(myColor,
+ ColoringAttributes.NICEST));
Sphere sphere = new Sphere(radius, new Sphere().getPrimitiveFlags() | Sphere.ENABLE_GEOMETRY_PICKING,
- DEFAULT_DIVISIONS);
+ DEFAULT_DIVISIONS, meshApp);
Transform3D tmp = new Transform3D();
tmp.set(new Matrix3f(a, 0.0f, 0.0f, 0.0f, b, 0.0f, 0.0f, 0.0f, c));
TransformGroup tg = new TransformGroup(tmp);
diff --git a/src/tesseract/objects/Icosahedron.java b/src/tesseract/objects/Icosahedron.java index 67e74a3..39852df 100644 --- a/src/tesseract/objects/Icosahedron.java +++ b/src/tesseract/objects/Icosahedron.java @@ -5,6 +5,8 @@ */
package tesseract.objects;
+import java.awt.Color;
+
import javax.media.j3d.Appearance;
import javax.media.j3d.ColoringAttributes;
import javax.media.j3d.GeometryArray;
@@ -12,6 +14,7 @@ import javax.media.j3d.Material; import javax.media.j3d.Shape3D;
import javax.media.j3d.TransformGroup;
import javax.media.j3d.TriangleArray;
+import javax.vecmath.Color3f;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;
@@ -46,7 +49,15 @@ public class Icosahedron extends PhysicalObject { */
private static final float GOLDEN_RATIO = (float) ((1.0 + Math.sqrt(5.0))
/ 2.0);
+ /**
+ * Default Object color.
+ */
+ private static final Color3f DEFAULT_COLOR = new Color3f(.9f, .05f, .05f);
+ /**
+ * User definable color.
+ */
+ private final Color3f myColor;
//CONSTRUCTORS
/**
@@ -54,12 +65,12 @@ public class Icosahedron extends PhysicalObject { * @param position start position.
* @param mass start mass.
* @param scale of object.
+ * @param theColor of object.
*/
public Icosahedron(final Vector3f position, final float mass,
- final float scale) {
-
+ final float scale, final Color theColor) {
super(position, mass);
-
+ myColor = new Color3f(theColor);
setShape(buildIcosahedron(scale));
if (inverseMass != 0) {
@@ -73,6 +84,17 @@ public class Icosahedron extends PhysicalObject { /**
* Create new Icosahedron.
+ * @param position start position.
+ * @param mass start mass.
+ * @param scale of object.
+ */
+ public Icosahedron(final Vector3f position, final float mass,
+ final float scale) {
+ this(position, mass, scale, DEFAULT_COLOR.get());
+ }
+
+ /**
+ * Create new Icosahedron.
* @param position Initial Position.
* @param mass object mass.
*/
@@ -206,10 +228,10 @@ public class Icosahedron extends PhysicalObject { Shape3D shape = new Shape3D(geo.getGeometryArray());
Appearance meshApp = new Appearance();
Material surface = new Material();
- surface.setDiffuseColor(.9f, .05f, .05f);
+ surface.setDiffuseColor(myColor);
meshApp.setMaterial(surface);
- meshApp.setColoringAttributes(new ColoringAttributes(.9f,
- .05f, .05f, ColoringAttributes.NICEST));
+ meshApp.setColoringAttributes(new ColoringAttributes(myColor,
+ ColoringAttributes.NICEST));
shape.setAppearance(meshApp);
return shape;
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);
}
}
diff --git a/src/tesseract/objects/Toroid.java b/src/tesseract/objects/Toroid.java index 7528129..75ead89 100644 --- a/src/tesseract/objects/Toroid.java +++ b/src/tesseract/objects/Toroid.java @@ -5,12 +5,15 @@ */
package tesseract.objects;
+import java.awt.Color;
+
import javax.media.j3d.Appearance;
import javax.media.j3d.IndexedQuadArray;
import javax.media.j3d.Material;
import javax.media.j3d.PointArray;
import javax.media.j3d.Shape3D;
import javax.media.j3d.Transform3D;
+import javax.vecmath.Color3f;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;
@@ -35,6 +38,16 @@ public class Toroid extends PhysicalObject { private static final float INEERTIA_TENSOR_CONSTANT5 = 5f;
/**
+ * Default color.
+ */
+ private static final Color3f DEFAULT_COLOR = new Color3f(1, 0, 0);
+
+ /**
+ * Object color.
+ */
+ private final Color3f myColor;
+
+ /**
* @param position starting position.
* @param mass of object.
* @param scale mesh scale.
@@ -46,8 +59,25 @@ public class Toroid extends PhysicalObject { public Toroid(final Vector3f position, final float mass, final float scale,
final float sliceRadius, final int sliceDivisions,
final float arcRadius, final int arcDivisions) {
+ this(position, mass, scale, sliceRadius, sliceDivisions,
+ arcRadius, arcDivisions, DEFAULT_COLOR.get());
+ }
+
+ /**
+ * @param position starting position.
+ * @param mass of object.
+ * @param scale mesh scale.
+ * @param sliceRadius radius of slice "flesh."
+ * @param sliceDivisions resolution of slice "flesh" circles.
+ * @param arcRadius Radius of donut circle
+ * @param arcDivisions resolution of slices on donut.
+ * @param theColor of toroid.
+ */
+ public Toroid(final Vector3f position, final float mass, final float scale,
+ final float sliceRadius, final int sliceDivisions,
+ final float arcRadius, final int arcDivisions, Color theColor) {
super(position, mass);
-
+ myColor = new Color3f(theColor);
setShape(buildToroid(scale, sliceRadius, sliceDivisions,
arcRadius, arcDivisions));
if (inverseMass != 0) {
@@ -154,7 +184,7 @@ public class Toroid extends PhysicalObject { Appearance app = new Appearance();
Material mat = new Material();
- mat.setDiffuseColor(1, 0, 0);
+ mat.setDiffuseColor(myColor);
app.setMaterial(mat);
shape.setAppearance(app);
|