Camera

new Camera()

The camera is defined by a position, orientation, and view frustum.

The orientation forms an orthonormal basis with a view, up and right = view x up unit vectors.

The viewing frustum is defined by 6 planes. Each plane is represented by a Cartesian4 object, where the x, y, and z components define the unit vector normal to the plane, and the w component is the distance of the plane from the origin/camera position.
Example:
// Create a camera looking down the negative z-axis, positioned at the origin,
// with a field of view of 60 degrees, and 1:1 aspect ratio.
var camera = new Cesium.Camera(scene);
camera.position = new Cesium.Cartesian3();
camera.direction = Cesium.Cartesian3.negate(Cesium.Cartesian3.UNIT_Z, new Cesium.Cartesian3());
camera.up = Cesium.Cartesian3.clone(Cesium.Cartesian3.UNIT_Y);
camera.frustum.fov = Cesium.Math.PI_OVER_THREE;
camera.frustum.near = 1.0;
camera.frustum.far = 2.0;
Demo:

Members

staticCamera.DEFAULT_VIEW_FACTOR :Number

A scalar to multiply to the camera position and add it back after setting the camera to view the rectangle. A value of zero means the camera will view the entire Camera#DEFAULT_VIEW_RECTANGLE, a value greater than zero will move it further away from the extent, and a value less than zero will move it close to the extent.

staticCamera.DEFAULT_VIEW_RECTANGLE :Rectangle

The default extent the camera will view on creation.

constrainedAxis :Cartesian3

If set, the camera will not be able to rotate past this axis in either direction.
Default Value: undefined

defaultLookAmount :Number

The default amount to rotate the camera when an argument is not provided to the look methods.
Default Value: Math.PI / 60.0

defaultMoveAmount :Number

The default amount to move the camera when an argument is not provided to the move methods.
Default Value: 100000.0;

defaultRotateAmount :Number

The default amount to rotate the camera when an argument is not provided to the rotate methods.
Default Value: Math.PI / 3600.0

defaultZoomAmount :Number

The default amount to move the camera when an argument is not provided to the zoom methods.
Default Value: 100000.0;

direction :Cartesian3

The view direction of the camera.

readonlydirectionWC :Cartesian3

Gets the view direction of the camera in world coordinates.

frustum :Frustum

The region of space in view.
Default Value: PerspectiveFrustum()
See:

heading :Number

Gets or sets the camera heading in radians.

readonlyinverseTransform :Matrix4

Gets the inverse camera transform.
Default Value: Matrix4.IDENTITY

readonlyinverseViewMatrix :Matrix4

Gets the inverse view matrix.
See:

maximumTranslateFactor :Number

The factor multiplied by the the map size used to determine where to clamp the camera position when translating across the surface. The default is 1.5. Only valid for 2D and Columbus view.
Default Value: 1.5

maximumZoomFactor :Number

The factor multiplied by the the map size used to determine where to clamp the camera position when zooming out from the surface. The default is 2.5. Only valid for 2D.
Default Value: 2.5

position :Cartesian3

The position of the camera.

positionCartographic :Cartographic

Gets the Cartographic position of the camera, with longitude and latitude expressed in radians and height in meters. In 2D and Columbus View, it is possible for the returned longitude and latitude to be outside the range of valid longitudes and latitudes when the camera is outside the map.

readonlypositionWC :Cartesian3

Gets the position of the camera in world coordinates.
The right direction of the camera.

readonlyrightWC :Cartesian3

Gets the right direction of the camera in world coordinates.

tilt :Number

Gets or sets the camera tilt in radians

transform :Matrix4

Modifies the camera's reference frame. The inverse of this transformation is appended to the view matrix.
Default Value: Matrix4.IDENTITY
See:
The up direction of the camera.

readonlyupWC :Cartesian3

Gets the up direction of the camera in world coordinates.

readonlyviewMatrix :Matrix4

Gets the view matrix.
See:

Methods

cameraToWorldCoordinates(cartesian, result)Cartesian4

Transform a vector or point from the camera's reference frame to world coordinates.
Name Type Description
cartesian Cartesian4 The vector or point to transform.
result Cartesian4 optional The object onto which to store the result.
Returns:
The transformed vector or point.

cameraToWorldCoordinatesPoint(cartesian, result)Cartesian3

Transform a point from the camera's reference frame to world coordinates.
Name Type Description
cartesian Cartesian3 The point to transform.
result Cartesian3 optional The object onto which to store the result.
Returns:
The transformed point.

cameraToWorldCoordinatesVector(cartesian, result)Cartesian3

Transform a vector from the camera's reference frame to world coordinates.
Name Type Description
cartesian Cartesian3 The vector to transform.
result Cartesian3 optional The object onto which to store the result.
Returns:
The transformed vector.

clone()Camera

Returns a duplicate of a Camera instance.
Returns:
A new copy of the Camera instance.

flyTo(options)

Flies the camera from its current position to a new position.
Name Type Description
options Object Object with the following properties:
Name Type Default Description
destination Cartesian3 The final position of the camera in WGS84 (world) coordinates.
direction Cartesian3 optional The final direction of the camera in WGS84 (world) coordinates. By default, the direction will point towards the center of the frame in 3D and in the negative z direction in Columbus view or 2D.
up Cartesian3 optional The final up direction in WGS84 (world) coordinates. By default, the up direction will point towards local north in 3D and in the positive y direction in Columbus view or 2D.
duration Number 3.0 optional The duration of the flight in seconds.
complete Camera~FlightCompleteCallback optional The function to execute when the flight is complete.
cancel Camera~FlightCancelledCallback optional The function to execute if the flight is cancelled.
endTransform Matrix4 optional Transform matrix representing the reference frame the camera will be in when the flight is completed.
convert Boolean true optional When true, the destination is converted to the correct coordinate system for each scene mode. When false, the destination is expected to be in the correct coordinate system.
Throws:
  • DeveloperError : If either direction or up is given, then both are required.

flyToRectangle(options, endTransform)

Flies the camera from its current position to a position where the entire rectangle is visible.
Name Type Description
options Object Object with the following properties:
Name Type Default Description
destination Rectangle The rectangle to view, in WGS84 (world) coordinates, which determines the final position of the camera.
duration Number 3.0 optional The duration of the flight in seconds.
complete Camera~FlightCompleteCallback optional The function to execute when the flight is complete.
cancel Camera~FlightCancelledCallback optional The function to execute if the flight is cancelled.
endTransform Matrix4 optional Transform matrix representing the reference frame the camera will be in when the flight is completed.

getMagnitude()Number

Gets the magnitude of the camera position. In 3D, this is the vector magnitude. In 2D and Columbus view, this is the distance to the map.
Returns:
The magnitude of the position.

getPickRay(windowPosition, result)Object

Create a ray from the camera position through the pixel at windowPosition in world coordinates.
Name Type Description
windowPosition Cartesian2 The x and y coordinates of a pixel.
result Ray optional The object onto which to store the result.
Returns:
Returns the Cartesian3 position and direction of the ray.

getRectangleCameraCoordinates(rectangle, result)Cartesian3

Get the camera position needed to view an rectangle on an ellipsoid or map
Name Type Description
rectangle Rectangle The rectangle to view.
result Cartesian3 optional The camera position needed to view the rectangle
Returns:
The camera position needed to view the rectangle

look(axis, angle)

Rotate each of the camera's orientation vectors around axis by angle
Name Type Description
axis Cartesian3 The axis to rotate around.
angle Number optional The angle, in radians, to rotate by. Defaults to defaultLookAmount.
See:

lookAt(eye, target, up)

Sets the camera position and orientation with an eye position, target, and up vector. This method is not supported in 2D mode because there is only one direction to look.
Name Type Description
eye Cartesian3 The position of the camera.
target Cartesian3 The position to look at.
up Cartesian3 The up vector.
Throws:

lookDown(amount)

Rotates the camera around its right vector by amount, in radians, in the opposite direction of its up vector.
Name Type Description
amount Number optional The amount, in radians, to rotate by. Defaults to defaultLookAmount.
See:

lookLeft(amount)

Rotates the camera around its up vector by amount, in radians, in the opposite direction of its right vector.
Name Type Description
amount Number optional The amount, in radians, to rotate by. Defaults to defaultLookAmount.
See:

lookRight(amount)

Rotates the camera around its up vector by amount, in radians, in the direction of its right vector.
Name Type Description
amount Number optional The amount, in radians, to rotate by. Defaults to defaultLookAmount.
See:

lookUp(amount)

Rotates the camera around its right vector by amount, in radians, in the direction of its up vector.
Name Type Description
amount Number optional The amount, in radians, to rotate by. Defaults to defaultLookAmount.
See:

move(direction, amount)

Translates the camera's position by amount along direction.
Name Type Description
direction Cartesian3 The direction to move.
amount Number optional The amount, in meters, to move. Defaults to defaultMoveAmount.
See:

moveBackward(amount)

Translates the camera's position by amount along the opposite direction of the camera's view vector.
Name Type Description
amount Number optional The amount, in meters, to move. Defaults to defaultMoveAmount.
See:

moveDown(amount)

Translates the camera's position by amount along the opposite direction of the camera's up vector.
Name Type Description
amount Number optional The amount, in meters, to move. Defaults to defaultMoveAmount.
See:

moveForward(amount)

Translates the camera's position by amount along the camera's view vector.
Name Type Description
amount Number optional The amount, in meters, to move. Defaults to defaultMoveAmount.
See:

moveLeft(amount)

Translates the camera's position by amount along the opposite direction of the camera's right vector.
Name Type Description
amount Number optional The amount, in meters, to move. Defaults to defaultMoveAmount.
See:

moveRight(amount)

Translates the camera's position by amount along the camera's right vector.
Name Type Description
amount Number optional The amount, in meters, to move. Defaults to defaultMoveAmount.
See:

moveUp(amount)

Translates the camera's position by amount along the camera's up vector.
Name Type Description
amount Number optional The amount, in meters, to move. Defaults to defaultMoveAmount.
See:

pickEllipsoid(windowPosition, ellipsoid, result)Cartesian3

Pick an ellipsoid or map.
Name Type Default Description
windowPosition Cartesian2 The x and y coordinates of a pixel.
ellipsoid Ellipsoid Ellipsoid.WGS84 optional The ellipsoid to pick.
result Cartesian3 optional The object onto which to store the result.
Returns:
If the ellipsoid or map was picked, returns the point on the surface of the ellipsoid or map in world coordinates. If the ellipsoid or map was not picked, returns undefined.

rotate(axis, angle)

Rotates the camera around axis by angle. The distance of the camera's position to the center of the camera's reference frame remains the same.
Name Type Description
axis Cartesian3 The axis to rotate around given in world coordinates.
angle Number optional The angle, in radians, to rotate by. Defaults to defaultRotateAmount.
See:

rotateDown(angle)

Rotates the camera around the center of the camera's reference frame by angle downwards.
Name Type Description
angle Number optional The angle, in radians, to rotate by. Defaults to defaultRotateAmount.
See:

rotateLeft(angle)

Rotates the camera around the center of the camera's reference frame by angle to the left.
Name Type Description
angle Number optional The angle, in radians, to rotate by. Defaults to defaultRotateAmount.
See:

rotateRight(angle)

Rotates the camera around the center of the camera's reference frame by angle to the right.
Name Type Description
angle Number optional The angle, in radians, to rotate by. Defaults to defaultRotateAmount.
See:

rotateUp(angle)

Rotates the camera around the center of the camera's reference frame by angle upwards.
Name Type Description
angle Number optional The angle, in radians, to rotate by. Defaults to defaultRotateAmount.
See:

setPositionCartographic(cartographic)

Moves the camera to the provided cartographic position.
Name Type Description
cartographic Cartographic The new camera position.

setTransform(transform)

Sets the camera's transform without changing the current view.
Name Type Description
transform Matrix4 The camera transform.

twistLeft(amount)

Rotate the camera counter-clockwise around its direction vector by amount, in radians.
Name Type Description
amount Number optional The amount, in radians, to rotate by. Defaults to defaultLookAmount.
See:

twistRight(amount)

Rotate the camera clockwise around its direction vector by amount, in radians.
Name Type Description
amount Number optional The amount, in radians, to rotate by. Defaults to defaultLookAmount.
See:

viewRectangle(rectangle, ellipsoid)

View an rectangle on an ellipsoid or map.
Name Type Default Description
rectangle Rectangle The rectangle to view.
ellipsoid Ellipsoid Ellipsoid.WGS84 optional The ellipsoid to view.

worldToCameraCoordinates(cartesian, result)Cartesian4

Transform a vector or point from world coordinates to the camera's reference frame.
Name Type Description
cartesian Cartesian4 The vector or point to transform.
result Cartesian4 optional The object onto which to store the result.
Returns:
The transformed vector or point.

worldToCameraCoordinatesPoint(cartesian, result)Cartesian3

Transform a point from world coordinates to the camera's reference frame.
Name Type Description
cartesian Cartesian3 The point to transform.
result Cartesian3 optional The object onto which to store the result.
Returns:
The transformed point.

worldToCameraCoordinatesVector(cartesian, result)Cartesian3

Transform a vector from world coordinates to the camera's reference frame.
Name Type Description
cartesian Cartesian3 The vector to transform.
result Cartesian3 optional The object onto which to store the result.
Returns:
The transformed vector.

zoomIn(amount)

Zooms amount along the camera's view vector.
Name Type Description
amount Number optional The amount to move. Defaults to defaultZoomAmount.
See:

zoomOut(amount)

Zooms amount along the opposite direction of the camera's view vector.
Name Type Description
amount Number optional The amount to move. Defaults to defaultZoomAmount.
See:

Type Definitions

FlightCancelledCallback()

A function that will execute when a flight is cancelled.

FlightCompleteCallback()

A function that will execute when a flight completes.