Class AnimationCurve

java.lang.Object
yearreview.app.animation.AnimationCurve

public class AnimationCurve extends Object
Curve used for animating. AnimationCurves can consist of multiple BezierCurves. A Curve is normalized if it starts at (0, 0) and ends at (1, 1).
Author:
ColdStone37
  • Field Details

    • LINEAR

      public static final AnimationCurve LINEAR
      A Curve for linear animations.
    • EASE_IN_OUT

      public static final AnimationCurve EASE_IN_OUT
      A Curve for ease-in-out animations.
    • EASE_IN

      public static final AnimationCurve EASE_IN
      A Curve for ease-in animations.
    • EASE_OUT

      public static final AnimationCurve EASE_OUT
      A Curve for ease-out animations.
    • BINARY_SEARCH_PRECISION

      private static final float BINARY_SEARCH_PRECISION
      Precision of the binary search when finding a certain x-value of a BezierCurve.
      See Also:
    • curves

      private final TreeMap<Float,BezierCurve> curves
      Allows access to each Bezier by its starting x-value.
    • posStart

      private final Vector2D posStart
      Initial position of the Curve.
    • posEnd

      private final Vector2D posEnd
      Final position of the Curve.
    • canContinue

      private final boolean canContinue
      Whether the animation can continue another animation. True if the first AnimationCurveControlPoint has a handle.
    • isNormalized

      private final boolean isNormalized
      Whether the AnimationCurve is normalized, meaning that it starts at (0, 0) and ends at (1, 1).
    • controlPoints

      private final AnimationCurveControlPoint[] controlPoints
      BezierControlPoints used to initially create the curve. Only stored if the Curve canContinue a previous animation.
  • Constructor Details

    • AnimationCurve

      public AnimationCurve(AnimationCurveControlPoint... controlPoints)
      Constructs a AnimationCurve from a set of Control-Points. A BezierCurve will be put between each of the Control-Points.
      Parameters:
      controlPoints - Control-Points to construct the Curve
  • Method Details

    • getCurveWithSlope

      protected AnimationCurve getCurveWithSlope(Vector2D slope)
      Gets a new AnimationCurve with the start angled at a certain slope.
      Parameters:
      slope - slope to angle the start of the new Curve at
      Returns:
      Curve with angled start
    • canContinue

      public boolean canContinue()
      Gets whether this AnimationCurve can continue another AnimationCurve by rotating the first AnimationCurveControlPoint.
      Returns:
      true if this AnimationCurve can continue another AnimationCurve
    • sampleCurve

      public float sampleCurve(float x)
      Samples the AnimationCurve at a certain x-position.
      Parameters:
      x - position to sample the curve at
      Returns:
      AnimationCurve at that position
    • sampleCurveSlope

      public Vector2D sampleCurveSlope(float x)
      Samples the slope of the Curve at a certain x-value.
      Parameters:
      x - position to sample the slope at
      Returns:
      normalized Vector pointing in the direction of the Curve at the given x-position
    • sampleBezierDeltaAtX

      private Vector2D sampleBezierDeltaAtX(BezierCurve curve, float xVal, float min, float max)
      Samples the direction of the given Bezier at a certain x-position using binary search.
      Parameters:
      curve - Bezier to sample direction of
      xVal - x-position to sample the direction at
      min - minimum of current interval in the binary search
      max - maximum of current interval in the binary search
      Returns:
      normalized Vector pointing in the direction of the Bezier at the given x-position
    • sampleBezierAtX

      private Vector2D sampleBezierAtX(BezierCurve curve, float xVal, float min, float max)
      Samples the Bezier at a certain x-position by doing binary search over the interval. X-Value of the output vector represents the result of the binary search such that curve.samplePoint(vec.x).x == xVal.
      Parameters:
      curve - curve to sample the position of
      xVal - x-value to find using binary search
      min - left border of the interval
      max - right border of the interval
      Returns:
      new Vector storing the value input into the Bezier and the y-value at that position
    • validateControlPoints

      private static boolean validateControlPoints(AnimationCurveControlPoint[] controlPoints)
      Validates the Control-Points of an AnimationCurve. The following has to be true for a valid AnimationCurve: - Atleast two AnimationCurveControlPoint - A BezierControlPoint b2 following a BezierControlPoint b1 has to have a higher x-value than b1: b1.pos.x <= b2.pos.x - If atleast one of the BezierControlPoints has handles also b1.pos.x + b1.dir.x <= b2.pos.x - b2.dir.x has to be fulfilled
      Parameters:
      controlPoints - Control-Points to validate
      Returns:
      true if they are valid Control-Points for an AnimationCurve, false otherwise
    • isNormalized

      public boolean isNormalized()
      Gets whether the AnimationCurve is normalized (meaning that the first Control-Point is at (0, 0) and the last Control-Point is at (1,1)). Only normalized AnimationCurves can be used in AnimatedNumbers.
      Returns:
      whether the AnimationCurve is normalized