Orientation of the model changing at last position.
Can anyone please explain why the orientation changing suddenly when model out of points?
copy and paste the following code in sandcastle to test it out.
var viewer = new Cesium.Viewer("cesiumContainer");
Cesium.Math.setRandomNumberSeed(3);
//Set bounds of our simulation time
var start = Cesium.JulianDate.fromDate(new Date(new Date().getTime() - 60000));
var stop = Cesium.JulianDate.addSeconds(
start,
3600,
new Cesium.JulianDate()
);
let currentTimestamp = new Date().getTime() - 6000;
//Make sure viewer is at the desired time.
viewer.clock.startTime = start.clone();
// .clock.stopTime = stop.clone();
viewer.clock.currentTime = Cesium.JulianDate.fromDate(new Date(currentTimestamp));
viewer.clock.clockRange = Cesium.ClockRange.UNBOUNDED; //Loop at the end
viewer.clock.multiplier = 1;
viewer.clock.shouldAnimate = true;
//Set timeline to simulation bounds
viewer.timeline.zoomTo(start, stop);
var position = new Cesium.SampledPositionProperty();
position.forwardExtrapolationType = Cesium.ExtrapolationType.HOLD;
var entity = viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(55.06773, 24.99495, 50),
model: {
uri: "../SampleData/models/CesiumMilkTruck/CesiumMilkTruck.glb",
minimumPixelSize: 32,
scale: 0.5,
},
viewFrom: new Cesium.Cartesian3(-100.0, 0.0, 100.0),
//position: position,
//orientation: new Cesium.VelocityOrientationProperty(position),
});
viewer.trackedEntity = entity;
var liveLocations = [
[55.0673734458, 24.9945164584],
//[55.0685952005, 24.9955737298],
[55.0687067851, 24.9956577933],
[55.0693178548, 24.9950571553],
//[55.0692440368, 24.9949780376],
[55.0683879693, 24.9942512493]
];
var pointer = 0;
var clock = viewer.clock;
setTimeout(function(){
entity.position = position;
entity.orientation = new Cesium.VelocityOrientationProperty(position);
var lastUpdated = clock.currentTime;
clock.onTick.addEventListener(function () {
var dt = Cesium.JulianDate.secondsDifference(clock.currentTime, lastUpdated);
if (dt >= 5 && pointer < liveLocations.length) {
console.log(pointer);
var location = liveLocations[pointer];
position.addSample(Cesium.JulianDate.fromDate(new Date()), Cesium.Cartesian3.fromDegrees(location[0], location[1]));
if(pointer < liveLocations.length) {
viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(location[0], location[1], 10),
point: {
pixelSize: 5,
color: Cesium.Color.RED
},
label: {
text: pointer + ''
}
});
pointer++;
}
lastUpdated = clock.currentTime;
}
});
}, 100);