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,28 @@
package eu.crushedpixel.replaymod.interpolation;
import eu.crushedpixel.replaymod.holders.AdvancedPosition;
import eu.crushedpixel.replaymod.utils.InterpolationUtils;
public class AdvancedPositionLinearInterpolation extends GenericLinearInterpolation<AdvancedPosition> {
@Override
public void addPoint(AdvancedPosition point) {
double normalizedYaw = (point.getYaw() + 180) % 360;
double normalizedRoll = (point.getRoll()) % 360;
if(!points.isEmpty()) {
AdvancedPosition last = points.get(points.size()-1);
double yaw = InterpolationUtils.fixEulerRotation(last.getYaw(), point.getYaw(), 180);
double roll = InterpolationUtils.fixEulerRotation(last.getRoll(), point.getRoll(), 0);
point.setYaw(yaw);
point.setRoll(roll);
} else {
point.setYaw(normalizedYaw-180);
point.setRoll(normalizedRoll);
}
super.addPoint(point);
}
}

View File

@@ -0,0 +1,28 @@
package eu.crushedpixel.replaymod.interpolation;
import eu.crushedpixel.replaymod.holders.AdvancedPosition;
import eu.crushedpixel.replaymod.utils.InterpolationUtils;
public class AdvancedPositionSplineInterpolation extends GenericSplineInterpolation<AdvancedPosition> {
@Override
public void addPoint(AdvancedPosition point) {
double normalizedYaw = (point.getYaw() + 180) % 360;
double normalizedRoll = (point.getRoll()) % 360;
if(!points.isEmpty()) {
AdvancedPosition last = points.get(points.size()-1);
double yaw = InterpolationUtils.fixEulerRotation(last.getYaw(), point.getYaw(), 180);
double roll = InterpolationUtils.fixEulerRotation(last.getRoll(), point.getRoll(), 0);
point.setYaw(yaw);
point.setRoll(roll);
} else {
point.setYaw(normalizedYaw-180);
point.setRoll(normalizedRoll);
}
super.addPoint(point);
}
}

View File

@@ -10,15 +10,16 @@ import java.util.Vector;
public class GenericSplineInterpolation<T extends KeyframeValue> extends BasicSpline implements Interpolation<T> {
private Field[] fields;
protected Field[] fields;
private Vector<T> points;
private List<Vector<Cubic>> cubics = Collections.emptyList();
protected Vector<T> points;
protected List<Vector<Cubic>> cubics = Collections.emptyList();
public GenericSplineInterpolation() {
this.points = new Vector<T>();
}
@Override
public void addPoint(T point) {
this.points.add(point);
@@ -56,6 +57,7 @@ public class GenericSplineInterpolation<T extends KeyframeValue> extends BasicSp
}
}
@Override
public void applyPoint(float position, T toEdit) {
Vector<Cubic> first = cubics.get(0);
position = position * first.size();

View File

@@ -165,12 +165,13 @@ public class KeyframeList<K extends KeyframeValue> extends ArrayList<Keyframe<K>
* Recalculates the underlying Interpolation instances.
* @param linear Whether to prepare linear or cubic interpolation
*/
@SuppressWarnings("unchecked")
public void recalculate(boolean linear) {
previousCallLinear = linear;
if(isEmpty()) return;
if(size() < 2) return;
interpolation = linear ? new GenericLinearInterpolation<K>() : new GenericSplineInterpolation<K>();
interpolation = linear ? first().getValue().getLinearInterpolator() : first().getValue().getCubicInterpolator();
for(Keyframe<K> keyframe : this) {
interpolation.addPoint(keyframe.getValue());

View File

@@ -11,4 +11,6 @@ public interface KeyframeValue {
KeyframeValue newInstance();
Interpolation getLinearInterpolator();
Interpolation getCubicInterpolator();
}