Added getLinearInterpolator() and getCubicInterpolator() methods to KeyframeValue interface to allow for specific Interpolators instead of the Generic Interpolators

Created InterpolationUtils class with a method to fix the Euler Rotation Break problem
Create AdvancedPositionSplineInterpolation and AdvancedPositionLinearInterpolation which always use the shortest possible paths between the Euler Rotation values of the Camera's Yaw and Roll
Remove Position Keyframe filtering when adding the Keyframe. This is now done by the AdvancedPositionInterpolation classes
This commit is contained in:
CrushedPixel
2015-07-21 03:49:20 +02:00
parent ff6b09dcba
commit f5a9723646
15 changed files with 177 additions and 42 deletions

View File

@@ -0,0 +1,36 @@
package eu.crushedpixel.replaymod.utils;
public class InterpolationUtils {
/**
* Note: I invented the word "Euler break". If there are any better suggestions, let me know.
* @param first The previous, fixed Rotation value
* @param second The new Rotation value
* @param eulerBreak The Euler break, e.g. 180 for Minecraft's Camera Yaw
* @return The new Rotation value, modified to make the Interpolation algorithms
* find the closest path between two Euler Rotation values
*/
public static double fixEulerRotation(double first, double second, int eulerBreak) {
if(first == second) return first;
//converting the values to values between 0 and 359,
//essentially moving the euler break to 0
double normalizedFirst = (first + eulerBreak) % 360;
double normalizedSecond = (second + eulerBreak) % 360;
//the difference between the rotation values
//if using the "conventional" path
double pathDifference = Math.abs(normalizedSecond-normalizedFirst);
int factor = normalizedSecond > normalizedFirst ? 1 : -1;
//if the "conventional" path takes more than half the rotation,
//use the path crossing the euler break
if(pathDifference > 180) {
//invert the path difference to rotate in the other direction
pathDifference = -1*(360-pathDifference);
}
return first + factor*pathDifference;
}
}