view game/Interpolate.java @ 57:1435e9d7fd1a

Bugfix.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 23 Feb 2011 20:36:07 +0200
parents 59ff451750fb
children 41c6cca69d60
line wrap: on
line source

/*
 * 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
{
    float start, end, steps;

    public Interpolate(float start, float end, float steps)
    {
        this.start = start;
        this.end = end;
        this.steps = steps;
    }
    
    public float getValue(float step)
    {
        float n = step / steps;
        float v = n * n * (3.0f - 2.0f * n);
        return (start * v) + (end * (1.0f - v));
    }
}