How can I track an object with the camera, like Simple CZML Demo (Vehicle), without CZML? Just with tick() function?


Hi Tamy,

You can set the camera reference frame to be centered at the object each frame. For example:

var position = … // position of object to follow

camera.transform = Transforms.eastNorthUpToFixedFrame(position, ellipsoid);

A camera tutorial for the blog is in progress, but you can check out the camera-tutorial branch (https://github.com/AnalyticalGraphicsInc/cesium/tree/camera-tutorial) for a Sandcastle example that has the camera follow a moving billboard.


Thank you, Dan,

But it doesn’t work as I wanted.

Following a billboard, It doesn’t let me zoom in much.

On another test, when I zoom, I want to put the point where the mouse position is on the middle screen, like google maps.

I have this code:

var handlerZoom = new Cesium.ScreenSpaceEventHandler(scene.getCanvas());

handlerZoom.setInputAction(function(delta) {

var cartesian2 = new Cesium.Cartesian2(window.event.clientX, window.event.clientY);

var cartesian = scene.getCamera().controller.pickEllipsoid(cartesian2, ellipsoid);


camera.transform = Cesium.Transforms.eastNorthUpToFixedFrame(cartesian, ellipsoid);


}, Cesium.ScreenSpaceEventType.WHEEL);

Another thing…I want to rotate the camera around the middle screen.

If I have it:

After something like it:

var cam = scene.getCamera().controller;

cam.rotate(scene.getCamera().position, Math.PI);

I want to see it:

But with this code just the world rotates. There’s a way to do it?

Would it be possible to get a little more information on this one? I cant seem to figure out what to do for making the camera follow my moving object.

My example is identical to the http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=CZML.html&label=Showcases build in czml

You can opt-in to the automatic camera following capabilities of Entity instances (such as those that come from CZML), by calling viewer.extend(Cesium.viewerEntityMixin) and then setting the viewer.trackedEntity property. However, we are getting rid of the extend requirement in the next release, so any Entity will be able to be followed easily out of the box.

If you aren’t using Viewer, you can check out the EntityView class, which is what is being used by viewer: https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/DataSources/EntityView.js

Thanks. I found EntityView the other day and have used it with clock.onTick to get tracking started. Works out fine.

Will take a deeper look to figure out if I can position the camera closer to the object than the default.

You can use the viewFrom property in CZML to have per-entity default camera distance. It’s fairly limited, but is good enough for now until we have a better solution. Similarly, if you want to set the default for all entities, you can set the EntityViewer.defaultOffset3D property.