Package yearreview.app.animation
Class AnimationCurve
java.lang.Object
yearreview.app.animation.AnimationCurve
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 Summary
FieldsModifier and TypeFieldDescriptionprivate static final floatPrecision of the binary search when finding a certain x-value of aBezierCurve.private final booleanWhether the animation can continue another animation.private final AnimationCurveControlPoint[]BezierControlPoints used to initially create the curve.private final TreeMap<Float,BezierCurve> Allows access to each Bezier by its starting x-value.static final AnimationCurveA Curve for ease-in animations.static final AnimationCurveA Curve for ease-in-out animations.static final AnimationCurveA Curve for ease-out animations.private final booleanWhether the AnimationCurve is normalized, meaning that it starts at (0, 0) and ends at (1, 1).static final AnimationCurveA Curve for linear animations.private final Vector2DFinal position of the Curve.private final Vector2DInitial position of the Curve. -
Constructor Summary
ConstructorsConstructorDescriptionAnimationCurve(AnimationCurveControlPoint... controlPoints) Constructs a AnimationCurve from a set of Control-Points. -
Method Summary
Modifier and TypeMethodDescriptionbooleanGets whether this AnimationCurve can continue another AnimationCurve by rotating the firstAnimationCurveControlPoint.protected AnimationCurvegetCurveWithSlope(Vector2D slope) Gets a new AnimationCurve with the start angled at a certain slope.booleanGets whether the AnimationCurve is normalized (meaning that the first Control-Point is at (0, 0) and the last Control-Point is at (1,1)).private Vector2DsampleBezierAtX(BezierCurve curve, float xVal, float min, float max) Samples the Bezier at a certain x-position by doing binary search over the interval.private Vector2DsampleBezierDeltaAtX(BezierCurve curve, float xVal, float min, float max) Samples the direction of the given Bezier at a certain x-position using binary search.floatsampleCurve(float x) Samples the AnimationCurve at a certain x-position.sampleCurveSlope(float x) Samples the slope of the Curve at a certain x-value.private static booleanvalidateControlPoints(AnimationCurveControlPoint[] controlPoints) Validates the Control-Points of an AnimationCurve.
-
Field Details
-
LINEAR
A Curve for linear animations. -
EASE_IN_OUT
A Curve for ease-in-out animations. -
EASE_IN
A Curve for ease-in animations. -
EASE_OUT
A Curve for ease-out animations. -
BINARY_SEARCH_PRECISION
private static final float BINARY_SEARCH_PRECISIONPrecision of the binary search when finding a certain x-value of aBezierCurve.- See Also:
-
curves
Allows access to each Bezier by its starting x-value. -
posStart
Initial position of the Curve. -
posEnd
Final position of the Curve. -
canContinue
private final boolean canContinueWhether the animation can continue another animation. True if the firstAnimationCurveControlPointhas a handle. -
isNormalized
private final boolean isNormalizedWhether the AnimationCurve is normalized, meaning that it starts at (0, 0) and ends at (1, 1). -
controlPoints
BezierControlPoints used to initially create the curve. Only stored if the CurvecanContinuea previous animation.
-
-
Constructor Details
-
AnimationCurve
Constructs a AnimationCurve from a set of Control-Points. ABezierCurvewill be put between each of theControl-Points.- Parameters:
controlPoints- Control-Points to construct the Curve
-
-
Method Details
-
getCurveWithSlope
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 firstAnimationCurveControlPoint.- 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
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
Samples the direction of the given Bezier at a certain x-position using binary search.- Parameters:
curve- Bezier to sample direction ofxVal- x-position to sample the direction atmin- minimum of current interval in the binary searchmax- maximum of current interval in the binary search- Returns:
- normalized Vector pointing in the direction of the Bezier at the given x-position
-
sampleBezierAtX
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 ofxVal- x-value to find using binary searchmin- left border of the intervalmax- right border of the interval- Returns:
- new Vector storing the value input into the Bezier and the y-value at that position
-
validateControlPoints
Validates the Control-Points of an AnimationCurve. The following has to be true for a valid AnimationCurve: - Atleast twoAnimationCurveControlPoint- 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 inAnimatedNumbers.- Returns:
- whether the AnimationCurve is normalized
-