summaryrefslogtreecommitdiff
path: root/src/tesseract
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2011-01-28 20:55:28 +0000
committerJesse Morgan <jesse@jesterpm.net>2011-01-28 20:55:28 +0000
commitf93d4988249f3166329e84699cbaeccd65d16ba8 (patch)
tree888e9d11b04e061a7cb5f23241c7a0b14921bf56 /src/tesseract
parent93bce11072ffec1166606ce981ac508bc7fadce6 (diff)
Added a shiny new particle emitter.
Diffstat (limited to 'src/tesseract')
-rw-r--r--src/tesseract/TesseractUI.java4
-rw-r--r--src/tesseract/objects/emitters/ParticleEmitter.java72
2 files changed, 75 insertions, 1 deletions
diff --git a/src/tesseract/TesseractUI.java b/src/tesseract/TesseractUI.java
index 61a7e13..74d0af3 100644
--- a/src/tesseract/TesseractUI.java
+++ b/src/tesseract/TesseractUI.java
@@ -24,6 +24,7 @@ import javax.vecmath.Vector3f;
import tesseract.forces.Gravity;
import tesseract.objects.Particle;
+import tesseract.objects.emitters.ParticleEmitter;
import com.sun.j3d.utils.universe.SimpleUniverse;
@@ -47,7 +48,7 @@ public class TesseractUI extends JFrame {
/**
* Measure of 1 unite of space in the world.
*/
- private static final double UNIT = 1;
+ private static final float UNIT = 1;
/**
* Number of miliseconds in 1 second.
@@ -99,6 +100,7 @@ public class TesseractUI extends JFrame {
// TODO: REMOVE TEST CODE
myWorld.addObject(new Particle(new Vector3f(0, 0, 0), null));
myWorld.addForce(new Gravity());
+ myWorld.addObject(new ParticleEmitter(new Vector3f(0, 0.49f, 0), 0.5f, null));
}
/**
diff --git a/src/tesseract/objects/emitters/ParticleEmitter.java b/src/tesseract/objects/emitters/ParticleEmitter.java
new file mode 100644
index 0000000..de5a556
--- /dev/null
+++ b/src/tesseract/objects/emitters/ParticleEmitter.java
@@ -0,0 +1,72 @@
+package tesseract.objects.emitters;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.vecmath.Color3f;
+import javax.vecmath.Vector3f;
+
+import tesseract.objects.Particle;
+import tesseract.objects.PhysicalObject;
+
+/**
+ * ParticleEmitter Class.
+ *
+ * @author Jesse Morgan
+ */
+public class ParticleEmitter extends PhysicalObject {
+
+ /**
+ * Frequency of new objects.
+ */
+ private float myFrequency;
+
+ /**
+ * The object to create...
+ */
+ private Color3f myColor;
+
+ /**
+ * Counter to keep track of how long has passed.
+ */
+ private float myCount;
+
+ /**
+ * Construct a new Particle Emitter.
+ *
+ * @param position Where to put the emitter
+ * @param frequency How often to emit the object (seconds).
+ * @param color Color the particle be (null for random).
+ */
+ public ParticleEmitter(final Vector3f position, final float frequency,
+ final Color3f color) {
+
+ super(position);
+
+ myCount = 0;
+ myFrequency = frequency;
+ myColor = color;
+ }
+
+ /**
+ * Update State and maybe generate a new object.
+ *
+ * @param duration The length of time that has passed.
+ * @return A list of new objects to add to the world.
+ */
+ public List<PhysicalObject> updateState(final float duration) {
+ List<PhysicalObject> children = super.updateState(duration);
+
+ if (children == null) {
+ children = new LinkedList<PhysicalObject>();
+ }
+
+ myCount += duration;
+ if (myCount >= myFrequency) {
+ children.add(new Particle(getPosition(), myColor));
+ myCount = 0;
+ }
+
+ return children;
+ }
+}