diff game/Interpolate.java @ 1:44f1e7b47fcf

Preliminary work ... puuh.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 28 Jan 2011 16:34:53 +0200
parents
children 70714c229e23
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/game/Interpolate.java	Fri Jan 28 16:34:53 2011 +0200
@@ -0,0 +1,26 @@
+/*
+ * Class for smooth non-linear interpolation between two given values in N steps
+ * (C) Copyright 2011 Matti 'ccr' Hämäläinen <ccr@tnsp.org>
+ */
+package game;
+
+import java.util.*;
+
+public class Interpolate
+{
+    double start, end, steps;
+
+    public Interpolate(double start, double end, double steps)
+    {
+      this.start = start;
+      this.end = end;
+      this.steps = steps;
+    }
+    
+    public double getValue(double step)
+    {
+      double n = step / steps;
+      double v = n * n * (3.0f - 2.0f * n);
+      return (start * v) + (end * (1.0f - v));
+    }
+}