Absolutely. SampledProperty works with any value that implements the Packable interface and there is also an additional PackableForInterpolation interface when further control is needed (for example, Quaternion can’t be directly interpolated so it uses PackableForInterpolation in order to interpolate using axis and angle. I believe what you want to do is actually kind of tricky if you wanted it to work across all interpolation types. However, if all you care about is linear interpolation (which is the default) that should be easy enough. Basically, create a new object, called Angle and have it implement Packable and PackableForInterpolation. Then you can detect the result in unpackInterpolationResult and use the ratio to have the rotation go in the opposite direction. Here’s some shell code for you and an example for using it. Just replace the TODO with the code to computes the alternate result from start and end values.
//A value that always interpolates the shortest distances between 2 angles.
var Angle = {
packedLength : 1,
packedInterpolationLength : 1,
pack : function(value, array, startingIndex) {
startingIndex = Cesium.defaultValue(startingIndex, 0);
array[startingIndex] = value;
},
unpack : function(array, startingIndex, result) {
startingIndex = Cesium.defaultValue(startingIndex, 0);
return array[startingIndex];
},
convertPackedArrayForInterpolation : function(packedArray, startingIndex, lastIndex, result) {
for (var i = 0, len = lastIndex - startingIndex + 1; i < len; i++) {
result[i] = packedArray[startingIndex + i];
}
},
unpackInterpolationResult : function(value, sourceArray, firstIndex, lastIndex, result) {
var start = sourceArray[firstIndex];
var end = sourceArray[lastIndex];
var difference = Math.abs(end - start);
if(difference > Math.PI / 2) {
//TODO convert value to rotation in opposite direction.
return value;
}
return value;
}
};
//Example
var property = new Cesium.SampledProperty(Angle);
var now = Cesium.JulianDate.now();
var nowPlus1 = Cesium.JulianDate.addSeconds(now, 1, new Cesium.JulianDate());
var nowPlus2 = Cesium.JulianDate.addSeconds(now, 2, new Cesium.JulianDate());
property.addSample(now, Cesium.Math.toRadians(45));
property.addSample(nowPlus1, Cesium.Math.toRadians(320));
console.log(property.getValue(nowPlus1));
Another solution that just occurred to me as I was about to send this would be to change the implementation of convertPackedArrayForInterpolation to store the shortest difference between values to fill the result array, and then you would simply add the result value toe the start value in unpackInterpolationResult. The benefit of the second solution is that it would work with all interpolation types. It would actually be easy to implement. If you go this second route, let us know and we’d be happy to take a pull request into Cesium for it.