synching camera with entity availability during timeline/animation?

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
                    }
                });
            }
        }
    }
});

Hello,

I don’t have a good answer for what you’re trying to do (sorry), but I was surprised to see “my experience is that the flyTo does not provide the same perspective as the setView, despite using the exactly identical coordinates”.

When I made changes to setView recently, the view was the same as flyTo. Could you give me an example of there the views were different so I can try to fix it?

Thanks!

-Hannah

Hannah,

I rescind my remark about differences between flyTo and setView. I’ve repeated my testing this morning and they now appear identical. (Earlier, it seemed as though the flyTo went to a higher elevation, resulting in a look angle that did not intersect my intended field of view.)

Okay! Thanks for checking. If you do see it again please let me know =)
-Hannah