I'm attempting to track an entity moving along a path. When I set the selectedEntity and use zoomTo() with a HeadingPitchRange, the camera remains fixed to the cardinal direction orientation of the globe. How would I get a camera that stays pointed behind the entity no matter which direction it moves along the path? Thanks!
Is the entity moving using interpolated samples like this http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Interpolation.html&label=Showcases
That's correct -- I'm building my code based off that interpolation example. However, as with the sample, the camera remains fixed to the global orientation, and depending on where the plane moves, sometimes the front is visible and sometimes the back is visible.
I wrote some code to do that here https://groups.google.com/forum/#!topic/cesium-dev/BqrmRaxtvro
I was going to improve on it, such as use a method that doesn’t mess with the camera’s transform. Also in hindsight this line was pointless
var x = CC3.dot(Lvelocity,Least);
x is simply Lvelocity.x !
Hyper, this works in Sandcastle but doesn't seem to work when I copy and paste it in my project. I replaced "entity" with "viewer.trackedEntity". My viewer screen turns blue instead of doing what is expected.
That’s why at the top it sets viewer.trackedEntity = undefined; This is custom per-frame code, you don’t want the built-in per-frame trackedEntity code since it lacks a relative to aircraft’s orientation option, it only provides relative to the Aircraft’s ENU frame. I suppose Cesium will eventually have that built-in as well, but until then this should work. viewer.trackedEntity is simply a variable that the built-in code uses, you can make your own entity tracking variable for your own custom per-frame code.
The button should be modified to toggle the custom per-frame code, with a remove event listener and set transform back to Cesium.Matrix4.IDENTITY then set viewer.tracketEntity.
If anyone is interested I could improve upon it, some current problems
-Sometimes it crashes if there’s no next point at the end of the path, in such cases one could use a previous point and reverse the direction.
-If you set -89 degrees pitch and the aircraft pitches down your heading can flip, I can fix that by making some more custom code rather than using .lookAt, or maybe flip roll for negative tilts after calling lookAt (not sure if that’ll work though.)
Velocity is easily determined as well by determining the distance and time deltas between the 2 sampled points.
If anyone wants to share their final solution to having the camera follow along smoothly I would think that might be a great addition to the interpolation example.
I would like to suggest this functionality be integrated into core Cesium. It could be a simple Boolean flag in addition to the trackedEntity property.