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
Modifier and TypeFieldDescriptionprivate static final float
Precision of the binary search when finding a certain x-value of aBezierCurve
.private final boolean
Whether 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 AnimationCurve
A Curve for ease-in animations.static final AnimationCurve
A Curve for ease-in-out animations.static final AnimationCurve
A Curve for ease-out animations.private final boolean
Whether the AnimationCurve is normalized, meaning that it starts at (0, 0) and ends at (1, 1).static final AnimationCurve
A Curve for linear animations.private final Vector2D
Final position of the Curve.private final Vector2D
Initial position of the Curve. -
Constructor Summary
ConstructorDescriptionAnimationCurve
(AnimationCurveControlPoint... controlPoints) Constructs a AnimationCurve from a set of Control-Points. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Gets whether this AnimationCurve can continue another AnimationCurve by rotating the firstAnimationCurveControlPoint
.protected AnimationCurve
getCurveWithSlope
(Vector2D slope) Gets a new AnimationCurve with the start angled at a certain slope.boolean
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)).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.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.float
sampleCurve
(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 boolean
validateControlPoints
(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 firstAnimationCurveControlPoint
has 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 CurvecanContinue
a previous animation.
-
-
Constructor Details
-
AnimationCurve
Constructs a AnimationCurve from a set of Control-Points. ABezierCurve
will 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
-