Skip to content

Commit

Permalink
TransformTrackBuilder: initialize the curves properly
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Sep 28, 2023
1 parent d64f7b3 commit e65b1a0
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,11 @@ public void addTranslation(float time, Vector3f translation) {
*/
public TransformTrack build() {
// Convert keyframe data to curves for efficient interpolation:
VectorCurve scaleCurve = toVectorCurve(scaleMap);
RotationCurve rotationCurve = toRotationCurve(rotationMap);
VectorCurve translationCurve = toVectorCurve(translationMap);
VectorCurve scaleCurve = toVectorCurve(scaleMap, tweenScales);
RotationCurve rotationCurve
= toRotationCurve(rotationMap, tweenRotations);
VectorCurve translationCurve
= toVectorCurve(translationMap, tweenTranslations);

// Generate the merged array of keyframe times:
float[] times = toFloatArray(timeSet);
Expand Down Expand Up @@ -264,9 +266,11 @@ private static float[] toFloatArray(Set<Float> timeSet) {
* Convert the specified Map into a RotationCurve for interpolation.
*
* @param map the input map (not null, unaffected)
* @param tween the interpolation technique that will be used (not null)
* @return a new instance (not null)
*/
private RotationCurve toRotationCurve(Map<Float, Quaternion> map) {
private RotationCurve toRotationCurve(
Map<Float, Quaternion> map, TweenRotations tween) {
float[] times = toFloatArray(map.keySet());

int numFrames = times.length;
Expand All @@ -277,7 +281,7 @@ private RotationCurve toRotationCurve(Map<Float, Quaternion> map) {
Quaternion rotation = map.get(time);
array[frameIndex] = rotation.clone();
}
RotationCurve result = new RotationCurve(times, duration, array);
RotationCurve result = tween.precompute(times, duration, array);

return result;
}
Expand All @@ -286,9 +290,11 @@ private RotationCurve toRotationCurve(Map<Float, Quaternion> map) {
* Convert the specified Map into a VectorCurve for interpolation.
*
* @param map the input map (not null, unaffected)
* @param tween the interpolation technique that will be used (not null)
* @return a new instance (not null)
*/
private VectorCurve toVectorCurve(Map<Float, Vector3f> map) {
private VectorCurve toVectorCurve(
Map<Float, Vector3f> map, TweenVectors tween) {
float[] times = toFloatArray(map.keySet());

int numFrames = times.length;
Expand All @@ -299,7 +305,7 @@ private VectorCurve toVectorCurve(Map<Float, Vector3f> map) {
Vector3f vector = map.get(time);
array[frameIndex] = vector.clone();
}
VectorCurve result = new VectorCurve(times, duration, array);
VectorCurve result = tween.precompute(times, duration, array);

return result;
}
Expand Down

0 comments on commit e65b1a0

Please sign in to comment.