Attaching camera orientation to entity moving along path

1,165 views
Skip to first unread message

gad...@gmail.com

unread,
May 7, 2015, 1:06:53 PM5/7/15
to cesiu...@googlegroups.com
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!

Hyper Sonic

unread,
May 7, 2015, 9:45:02 PM5/7/15
to cesiu...@googlegroups.com, gad...@gmail.com

gad...@gmail.com

unread,
May 7, 2015, 9:48:04 PM5/7/15
to cesiu...@googlegroups.com, gad...@gmail.com
On Thursday, May 7, 2015 at 9:45:02 PM UTC-4, Hyper Sonic wrote:
> 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.

Hyper Sonic

unread,
May 7, 2015, 9:55:38 PM5/7/15
to cesiu...@googlegroups.com, gad...@gmail.com
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 !

D2P

unread,
May 10, 2015, 1:16:30 PM5/10/15
to cesiu...@googlegroups.com, gad...@gmail.com
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.

Hyper Sonic

unread,
May 10, 2015, 2:42:56 PM5/10/15
to cesiu...@googlegroups.com, gad...@gmail.com, stephe...@gmail.com
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.

Mike LP

unread,
May 11, 2015, 12:05:02 PM5/11/15
to cesiu...@googlegroups.com, gman...@gmail.com, gad...@gmail.com, stephe...@gmail.com
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.

D2P

unread,
May 11, 2015, 6:31:38 PM5/11/15
to cesiu...@googlegroups.com, gman...@gmail.com, stephe...@gmail.com, gad...@gmail.com
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.
Reply all
Reply to author
Forward
0 new messages