What is the best way to synchronize the camera view with entities that are animated via availability (and the timeline)? That is, I have a set of entities, of which only one is visible at any instant; the visibility is dictated by the entity’s availability and the system time (timeline). I would like to synchronize the camera with this animated set of entities.
Presently, I have the following hack for a 1Hz frame rate. But rather than using a difference method, I would like to directly relate the camera to the currently available path entity. Each frame has a start and end time. (Additionally, my experience is that the flyTo does not provide the same perspective as the setview, despite using the exactly identical coordinates.)
// camera follows sensor perspective
viewer.clock.onTick.addEventListener(function(clock) {
if (viewer.clock.currentTime >= jStart && viewer.clock.currentTime <= jEnd) {
var frame = Math.floor(viewer.clock.currentTime.secondsOfDay - jStart.secondsOfDay); // approximation related to 30fps rate
frame = Math.min(frame, jLength-1);
if (frame != lastFrame) {
lastFrame = frame;
if (false) {
viewer.camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(frames[frame].document.uso, frames[frame].document.usa, frames[frame].document.usef),
orientation: {
heading: Cesium.Math.toRadians(frames[frame].bearingH),
pitch: Cesium.Math.toRadians(frames[frame].bearingV),
roll: 0
},
duration: 0.9,
complete: function() {
console.log("cesiumModule/flyToVideoMetadata: frame["+frame+"], lon = " + JSON.stringify(frames[frame].document.uso) + "°, lat = " + JSON.stringify(frames[frame].document.usa) + "°, elevation = " + JSON.stringify(frames[frame].document.use * 0.3048) + "', heading = " + JSON.stringify(frames[frame].bearingH) + "°" + "', look = " + JSON.stringify(frames[frame].bearingV) + "°");
}
});
}
if (true) {
viewer.camera.setView({
destination: Cesium.Cartesian3.fromDegrees(frames[frame].document.uso, frames[frame].document.usa, frames[frame].document.usef),
orientation: {
heading: Cesium.Math.toRadians(frames[frame].bearingH),
pitch: Cesium.Math.toRadians(frames[frame].bearingV),
roll: 0
}
});
}
}
}
});