Camera.lookAt() broken? (Or confusing documentation.)

If I want the camera to center on e.g. Mexico City, the documentation suggests that I should be able to do this:

var viewer = new Cesium.Viewer(‘cesiumContainer’);

var mexico = Cesium.Cartesian3.fromDegrees(-99.1013, 19.2465); // 19.2465° N, 99.1013

var noOffsetSinceIWantToStareRightAtIt = new Cesium.Cartesian3(0, 0, 0);

viewer.camera.lookAt(mexico, noOffsetSinceIWantToStareRightAtIt);

But that errors out with:

// RangeError: Invalid array length

So, how do I get the Camera to do a simple pan to a given lat/long?

I'm using this to set camera position (x,y.z)

viewer.camera.setView({
      position : Cesium.Cartesian3.fromDegrees(-99.1013, 19.2465, 750.0 )
      });

To be clear, I’m not trying to set the position of the camera (i.e. where it is) I’m trying to set the gaze of the camera (i.e. what it is looking at).

Assume the position of the camera is on the equator, at some longitude, and I just want it to pan over to look at some other lat / long.

How is that achieved in Cesium?

Hello,

Camera.lookAt is indeed intended to set both the position and orientation of the camera. The target is the position at which the camera should be pointing. The offset lets the camera know how far away from the target it’s new position should be. For example, Cartesian(0, 0, 10) tells the camera to move 10m above the target and look straight down.

Passing in (0,0,0) causes an error because it puts the camera in an invalid state. There are infinitely many orientations the camera could be in that satisfy an offset of 0.

If you simply want to turn the camera, you can use the setView function. If you only pass an orientation, it’ll turn the camera without moving it.

Best,

Hannah

Hannah,

Guess “lookAt” is just a bad name. That being said, can you point me to a simple example of how to use setView to set the orientation of the camera to point at a given lat/long?

In particular, it’s not obvious how to calculate the “up” vector. (I’d love to leave it unchanged, if that makes sense. Simply move the orientation without changing that “up” is.)

Thanks,

Dave