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:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -11,4 +11,6 @@ public interface KeyframeValue {
|
||||
|
||||
KeyframeValue newInstance();
|
||||
|
||||
Interpolation getLinearInterpolator();
|
||||
Interpolation getCubicInterpolator();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user