1
|
1 /*
|
|
2 * Class for smooth non-linear interpolation between two given values in N steps
|
|
3 * (C) Copyright 2011 Matti 'ccr' Hämäläinen <ccr@tnsp.org>
|
|
4 */
|
|
5 package game;
|
|
6
|
|
7 import java.util.*;
|
|
8
|
|
9 public class Interpolate
|
|
10 {
|
|
11 double start, end, steps;
|
|
12
|
|
13 public Interpolate(double start, double end, double steps)
|
|
14 {
|
|
15 this.start = start;
|
|
16 this.end = end;
|
|
17 this.steps = steps;
|
|
18 }
|
|
19
|
|
20 public double getValue(double step)
|
|
21 {
|
|
22 double n = step / steps;
|
|
23 double v = n * n * (3.0f - 2.0f * n);
|
|
24 return (start * v) + (end * (1.0f - v));
|
|
25 }
|
|
26 }
|