summaryrefslogtreecommitdiff
path: root/src/tesseract/objects/Particle.java
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2011-01-28 18:52:51 +0000
committerJesse Morgan <jesse@jesterpm.net>2011-01-28 18:52:51 +0000
commitfc40e7f6e3165a002326c92401c17951b7048a32 (patch)
treeccbb0fa261c51de242cf32a3aa622c78103b352f /src/tesseract/objects/Particle.java
parent380952816905723a8f3a18104e18e92ba85b2b88 (diff)
And we now have a basic 3d world :D
Diffstat (limited to 'src/tesseract/objects/Particle.java')
-rw-r--r--src/tesseract/objects/Particle.java80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/tesseract/objects/Particle.java b/src/tesseract/objects/Particle.java
new file mode 100644
index 0000000..8307c55
--- /dev/null
+++ b/src/tesseract/objects/Particle.java
@@ -0,0 +1,80 @@
+package tesseract.objects;
+
+import java.awt.Color;
+
+import javax.media.j3d.Appearance;
+import javax.media.j3d.ColoringAttributes;
+import javax.media.j3d.Node;
+import javax.vecmath.Color3f;
+import javax.vecmath.Vector3f;
+
+import com.sun.j3d.utils.geometry.Sphere;
+
+/**
+ * A particle object.
+ *
+ * @author Jesse Morgan
+ */
+public class Particle extends ForceableObject {
+ /**
+ * Rendered radius of particle.
+ */
+ private static final float RADIUS = .004f;
+
+ /**
+ * Default mass.
+ */
+ private static final float DEFAULT_MASS = 1;
+
+ /**
+ * Number of divisions in the sphere.
+ */
+ private static final int DIVISIONS = 8;
+
+ /**
+ * Create a new Particle.
+ *
+ * @param position Initial position.
+ * @param mass Initial mass.
+ * @param color Initial color. Null for random.
+ */
+ public Particle(final Vector3f position, final float mass,
+ final Color3f color) {
+ super(position, mass);
+
+ getTransformGroup().addChild(createShape(color));
+ }
+
+ /**
+ * Create a new Particle.
+ *
+ * @param position Initial position.
+ * @param color Initial color. Null for random.
+ */
+ public Particle(final Vector3f position, final Color3f color) {
+ this(position, DEFAULT_MASS, color);
+ }
+
+ /**
+ * Create a new particle of the give color.
+ *
+ * @param theColor The particle color or null for random.
+ * @return A sphere to visually represent the particle.
+ */
+ private Node createShape(final Color3f theColor) {
+ Color3f color = theColor;
+
+ ColoringAttributes cAttr;
+
+ if (color == null) {
+ Color randomColor = Color.getHSBColor((float) Math.random(), 1, 1);
+ color = new Color3f(randomColor);
+ }
+
+ cAttr = new ColoringAttributes(color, ColoringAttributes.FASTEST);
+ Appearance appearance = new Appearance();
+ appearance.setColoringAttributes(cAttr);
+ return new Sphere(RADIUS, 0, DIVISIONS, appearance);
+ }
+
+}