One of the most frequently requested features for Cesium is the ability to easily set the heading, pitch, and roll for the camera and primitives. Starting with version 1.6, a couple of functions have been added to make it easier.
For anyone who is unfamiliar with heading, pitch and roll angles:
-
Heading is the rotation from the local north direction where a positive angle is increasing eastward.
-
Pitch is the rotation from the local east-north plane. Positive pitch angles are above the plane. Negative pitch angles are below the plane.
-
Roll is the first rotation applied about the local east axis.
The camera position, heading, pitch and roll can be set with Camera.setView. The position can be either an instance of Cartesian3 or Cartographic. This can be used in all three scene modes, however, in 2D the pitch and roll are ignored because the camera must be looking straight down at the map though it can still be rotated about the view direction by setting the heading. For example, setting the view with a cartesian position looks like:
camera.setView({
position : new Cesium.Cartesian3(x, y, z),
heading : headingAngle,
pitch : pitchAngle,
roll : rollAngle
});
An example setting the position using a cartographic:
camera.setView({
positionCartographic : new Cesium.Cartographic(longitude, latitude, height),
heading : headingAngle,
pitch : pitchAngle,
roll : rollAngle
});
I think the most common use case would be to set the camera position looking straight down at the Earth with the heading oriented to north:
camera.setView({
position : Cesium.Cartesian3.fromDegrees(longitude, latitude, height),
heading : 0.0,
pitch : -Cesium.Math.PI_OVER_TWO,
roll : 0.0
});
If both position and positionCartographic are provided, then position will be used. All of the parameters are optional. The default values for any undefined
parameters are the current camera position, heading, pitch, and roll. For example, if you wish to just change the heading while the pitch, roll and position remain the same:
camera.setView({
heading : 0.0
});
We also added Transforms.headingPitchRollToFixedFrame. This creates a model matrix from a position, heading, pitch and roll. An example:
var origin = Cesium.Cartesian3.fromDegrees(longitude, latitude, height);
var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(origin, heading, pitch, roll);
var model = scene.primitives.add(Cesium.Model.fromGltf({
url : ‘path/to/model’,
modelMatrix : modelMatrix
}));
The heading, pitch and roll angles are all computed in the local east-north-up frame at the position. If heading, pitch, and roll are all zero, this is equivalent to Transforms.eastNorthUpToFixedFrame.
Dan