Class TimeShiftedComposer

  • All Implemented Interfaces:
    FrameComposer

    public class TimeShiftedComposer
    extends AbstractFilteredComposer
    A filter for composers that adjusts the timing of the filtered composer according to a function. Given an unshifted position value, the function must return the position value after shifting. The shifted values are not clamped to to range 0..1 as this simplifies the writing of some animations. Likewise, it is allowed to repeat the same value at different times in the shifted animation. When the shift function exhibits either behaviour, it is up to the user to ensure that the underlying composer handles them correctly.
    Since:
    3.0
    Author:
    Chris Jennings
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void composeFrame​(float position)
      This method is called with a value between 0 (start) and 1 (end).
      Fn getShiftFunction()
      Returns the time shifting function to be applied to the animation.
      void setShiftFunction​(float[] inputTimes, float[] outputTimes)
      Creates a time shift function that uses cubic spline interpolation to create an interpolator that maps the unshifted times in inputTimes to the elements with the same index in outputTimes.
      void setShiftFunction​(Fn f)
      Sets the time shifting function to be applied to the animation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TimeShiftedComposer

        public TimeShiftedComposer​(Animation animation)
        Creates a new time shifted composer that wraps the specified animation. A default timing function that applies an ease-in/ease-out to the animation will be used.
        Parameters:
        animation - the animation to modify the timing of
      • TimeShiftedComposer

        public TimeShiftedComposer​(FrameComposer composer)
        Creates a new time shifted composer that wraps the specified animation. A default timing function that applies an ease-in/ease-out to the animation will be used.
        Parameters:
        composer - the composer to modify the timing of
      • TimeShiftedComposer

        public TimeShiftedComposer​(Fn timeFunction,
                                   Animation animation)
        Creates a new time shifted composer that wraps the specified animation.
        Parameters:
        timeFunction - the function used to modify the timing of the animation
        animation - the animation to modify the timing of
      • TimeShiftedComposer

        public TimeShiftedComposer​(Fn timeFunction,
                                   FrameComposer composer)
        Creates a new time shifted composer that wraps the specified animation.
        Parameters:
        timeFunction - the function used to modify the timing of the animation
        composer - the composer to modify the timing of
    • Method Detail

      • getShiftFunction

        public final Fn getShiftFunction()
        Returns the time shifting function to be applied to the animation.
        Returns:
        the time shift function
        See Also:
        setShiftFunction(ca.cgjennings.math.Fn)
      • setShiftFunction

        public final void setShiftFunction​(Fn f)
        Sets the time shifting function to be applied to the animation. This function will be passed the original timing position as a value between 0 and 1. It should return a new value, also between 0 and 1, that the original value maps to. For example, the function f(x) = 1-x would play the original animation in reverse.
        See Also:
        getShiftFunction()
      • setShiftFunction

        public void setShiftFunction​(float[] inputTimes,
                                     float[] outputTimes)
        Creates a time shift function that uses cubic spline interpolation to create an interpolator that maps the unshifted times in inputTimes to the elements with the same index in outputTimes. The elements of inputTimes must be monotone increasing values (sorted into increasing order and with no repeats).
        Parameters:
        inputTimes - positions of key frames in unshifted time
        outputTimes - the positions to map those key frames to
      • composeFrame

        public void composeFrame​(float position)
        Description copied from interface: FrameComposer
        This method is called with a value between 0 (start) and 1 (end). It should set up the animation state proportionally between these two conditions.
        Parameters:
        position - the interpolated position at which to compose the frame between the start and end key frames