public class Interpolator
extends java.lang.Object
Vona's utils: a time-based interpolator.
Interpolates a currentValue()
from start
to end
over the time period duration
according to clock
.
Default impl is simple linear interpolation.
Copyright (C) 2004 Marsette A. Vona, III
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Modifier and Type | Field and Description |
---|---|
Clock |
clock
The time base to use for this interpolation.
|
(package private) static java.lang.String |
cvsid
CVS id.
|
double |
distance
|
double |
duration
The duration of this interpolation.
|
double |
end
The ending value for this interpolation.
|
double |
start
The starting value for this interpolation.
|
protected double |
startTime
The start time of the current interpolation, or NaN if no current
interpolation.
|
static Clock |
wallClock
A default time base.
|
Constructor and Description |
---|
Interpolator(Clock clock,
double start,
double end,
double duration)
Create a new Interpolator.
|
Interpolator(double start,
double end,
double duration)
Covers
Interpolator(Clock, double, double, double) but always
uses wallClock . |
Modifier and Type | Method and Description |
---|---|
double |
currentValue()
Get the current value of the interpolation.
|
protected double |
currentValue(double when)
Hook for subclasses to implement different interpolation schemes.
|
void |
reset()
Reset this Interpolator.
|
static final java.lang.String cvsid
CVS id.
public final Clock clock
The time base to use for this interpolation.
public final double start
The starting value for this interpolation.
public final double end
The ending value for this interpolation.
public final double distance
public final double duration
The duration of this interpolation.
protected double startTime
The start time of the current interpolation, or NaN if no current interpolation.
public static final Clock wallClock
A default time base.
public Interpolator(Clock clock, double start, double end, double duration)
Create a new Interpolator.
clock
- the time base, if null then use wallClock
start
- the initial valueend
- the final falueduration
- the duration in seconds according to clock
public Interpolator(double start, double end, double duration)
Covers Interpolator(Clock, double, double, double)
but always
uses wallClock
.
public double currentValue()
Get the current value of the interpolation.
The first call to this method after construction or a reset()
returns start
and initiates the interpolation. Subsequent calls
will return the interpolated value at the time of call until duration
has expired according to clock
, after which time all
calls will return end
until the next reset()
.
protected double currentValue(double when)
Hook for subclasses to implement different interpolation schemes.
currentValue()
calls this to compute intermediate values
between start
and end
.
when
- the time in seconds according to clock
since the
start of the interpolationwhen
public void reset()
Reset this Interpolator.
May be called at any time.