summaryrefslogtreecommitdiff
path: root/src/tesseract/forces/Gravity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/tesseract/forces/Gravity.java')
-rw-r--r--src/tesseract/forces/Gravity.java49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/tesseract/forces/Gravity.java b/src/tesseract/forces/Gravity.java
new file mode 100644
index 0000000..79e7f6a
--- /dev/null
+++ b/src/tesseract/forces/Gravity.java
@@ -0,0 +1,49 @@
+package tesseract.forces;
+
+import javax.vecmath.Vector3f;
+
+import tesseract.objects.Forceable;
+
+/**
+ * Generic downward force class (aka Gravity).
+ *
+ * @author Jesse Morgan
+ */
+public class Gravity extends Force {
+ /**
+ * Default gravity force.
+ */
+ private static final float DEFAULT_GRAVITY = 1f;
+
+ /**
+ * The force used here.
+ */
+ private float myGravity;
+
+ /**
+ * Create a default gravity.
+ */
+ public Gravity() {
+ myGravity = DEFAULT_GRAVITY;
+ }
+
+ /**
+ * Create gravity with a custom strength.
+ *
+ * @param gravity The strength of gravity.
+ */
+ public Gravity(final float gravity) {
+ myGravity = gravity;
+ }
+
+ /**
+ * Calculate the force of gravity...
+ *
+ * @param obj The object the force is calculated for.
+ * @return A vector describing the force
+ */
+ protected Vector3f calculateForce(final Forceable obj) {
+ return new Vector3f(0, -myGravity, 0);
+ }
+
+}