Camera

external class Camera(scene: Scene)(source)

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.

// 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.
const camera = new Camera(scene);
camera.position = new Cartesian3();
camera.direction = Cartesian3.negate(Cartesian3.UNIT_Z, new Cartesian3());
camera.up = Cartesian3.clone(Cartesian3.UNIT_Y);
camera.frustum.fov = Math.PI_OVER_THREE;
camera.frustum.near = 1.0;
camera.frustum.far = 2.0;

Parameters

scene

The scene.

See also

Constructors

Link copied to clipboard
constructor(scene: Scene)

Types

Link copied to clipboard
object Companion
Link copied to clipboard
Link copied to clipboard
sealed interface FlyToOptions
Link copied to clipboard
sealed interface SetViewOptions

Properties

Link copied to clipboard

Gets the event that will be raised when the camera has changed by percentageChanged.

Link copied to clipboard

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

Link copied to clipboard

The default amount to rotate the camera when an argument is not provided to the look methods.

Link copied to clipboard

The default amount to move the camera when an argument is not provided to the move methods.

Link copied to clipboard

The default amount to rotate the camera when an argument is not provided to the rotate methods.

Link copied to clipboard

The default amount to move the camera when an argument is not provided to the zoom methods.

Link copied to clipboard

The view direction of the camera.

Link copied to clipboard

Gets the view direction of the camera in world coordinates.

Link copied to clipboard

The region of space in view.

Link copied to clipboard

Gets the camera heading in radians.

Link copied to clipboard

Gets the inverse camera transform.

Link copied to clipboard

Gets the inverse view matrix.

Link copied to clipboard

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 1.5. Only valid for 2D and the map is rotatable.

Link copied to clipboard

Gets the event that will be raised when the camera has stopped moving.

Link copied to clipboard

Gets the event that will be raised at when the camera starts to move.

Link copied to clipboard

The amount the camera has to change before the changed event is raised. The value is a percentage in the 0, 1 range.

Link copied to clipboard

Gets the camera pitch in radians.

Link copied to clipboard

The position of the camera.

Link copied to clipboard

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.

Link copied to clipboard

Gets the position of the camera in world coordinates.

Link copied to clipboard

The right direction of the camera.

Link copied to clipboard

Gets the right direction of the camera in world coordinates.

Link copied to clipboard

Gets the camera roll in radians.

Link copied to clipboard

Gets the camera's reference frame. The inverse of this transformation is appended to the view matrix.

Link copied to clipboard

The up direction of the camera.

Link copied to clipboard

Gets the up direction of the camera in world coordinates.

Link copied to clipboard

Gets the view matrix.

Functions

Link copied to clipboard
fun cameraToWorldCoordinates(cartesian: Cartesian4, result: Cartesian4? = definedExternally): Cartesian4

Transform a vector or point from the camera's reference frame to world coordinates.

Link copied to clipboard
fun cameraToWorldCoordinatesPoint(cartesian: Cartesian3, result: Cartesian3? = definedExternally): Cartesian3

Transform a point from the camera's reference frame to world coordinates.

Link copied to clipboard
fun cameraToWorldCoordinatesVector(cartesian: Cartesian3, result: Cartesian3? = definedExternally): Cartesian3

Transform a vector from the camera's reference frame to world coordinates.

Link copied to clipboard

Cancels the current camera flight and leaves the camera at its current location. If no flight is in progress, this this function does nothing.

Link copied to clipboard

Completes the current camera flight and moves the camera immediately to its final destination. If no flight is in progress, this this function does nothing.

Link copied to clipboard
fun computeViewRectangle(ellipsoid: Ellipsoid? = definedExternally, result: Rectangle? = definedExternally): Rectangle?

Computes the approximate visible rectangle on the ellipsoid.

Link copied to clipboard

Return the distance from the camera to the front of the bounding sphere.

Link copied to clipboard
fun flyHome(duration: Double? = definedExternally)

Fly the camera to the home view. Use {@link Camera#.DEFAULT_VIEW_RECTANGLE} to set the default view for the 3D scene. The home view for 2D and columbus view shows the entire map.

Link copied to clipboard

Flies the camera from its current position to a new position.

Link copied to clipboard
fun flyToBoundingSphere(boundingSphere: BoundingSphere, options: Camera.FlyToBoundingSphereOptions? = definedExternally)

Flies the camera to a location where the current view contains the provided bounding sphere.

Link copied to clipboard

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.

Link copied to clipboard
fun getPickRay(windowPosition: Cartesian2, result: Ray? = definedExternally): Ray?

Create a ray from the camera position through the pixel at windowPosition in world coordinates.

Link copied to clipboard
fun getPixelSize(boundingSphere: BoundingSphere, drawingBufferWidth: Double, drawingBufferHeight: Double): Double

Return the pixel size in meters.

Link copied to clipboard
fun getRectangleCameraCoordinates(rectangle: Rectangle, result: Cartesian3? = definedExternally): Cartesian3

Get the camera position needed to view a rectangle on an ellipsoid or map

Link copied to clipboard
fun look(axis: Cartesian3, angle: Double? = definedExternally)

Rotate each of the camera's orientation vectors around axis by angle

Link copied to clipboard
fun lookAt(target: Cartesian3, offset: Cartesian3)

Sets the camera position and orientation using a target and offset. The target must be given in world coordinates. The offset can be either a cartesian or heading/pitch/range in the local east-north-up reference frame centered at the target. If the offset is a cartesian, then it is an offset from the center of the reference frame defined by the transformation matrix. If the offset is heading/pitch/range, then the heading and the pitch angles are defined in the reference frame defined by the transformation matrix. The heading is the angle from y axis and increasing towards the x axis. Pitch is the rotation from the xy-plane. Positive pitch angles are below the plane. Negative pitch angles are above the plane. The range is the distance from the center.

fun lookAt(target: Cartesian3, offset: HeadingPitchRange)
Link copied to clipboard
fun lookAtTransform(transform: Matrix4)

Sets the camera position and orientation using a target and transformation matrix. The offset can be either a cartesian or heading/pitch/range. If the offset is a cartesian, then it is an offset from the center of the reference frame defined by the transformation matrix. If the offset is heading/pitch/range, then the heading and the pitch angles are defined in the reference frame defined by the transformation matrix. The heading is the angle from y axis and increasing towards the x axis. Pitch is the rotation from the xy-plane. Positive pitch angles are below the plane. Negative pitch angles are above the plane. The range is the distance from the center.

fun lookAtTransform(transform: Matrix4, offset: Cartesian3)
fun lookAtTransform(transform: Matrix4, offset: HeadingPitchRange)
Link copied to clipboard
fun lookDown(amount: Double? = definedExternally)

Rotates the camera around its right vector by amount, in radians, in the opposite direction of its up vector if not in 2D mode.

Link copied to clipboard
fun lookLeft(amount: Double? = definedExternally)

Rotates the camera around its up vector by amount, in radians, in the opposite direction of its right vector if not in 2D mode.

Link copied to clipboard
fun lookRight(amount: Double? = definedExternally)

Rotates the camera around its up vector by amount, in radians, in the direction of its right vector if not in 2D mode.

Link copied to clipboard
fun lookUp(amount: Double? = definedExternally)

Rotates the camera around its right vector by amount, in radians, in the direction of its up vector if not in 2D mode.

Link copied to clipboard
fun move(direction: Cartesian3, amount: Double? = definedExternally)

Translates the camera's position by amount along direction.

Link copied to clipboard
fun moveBackward(amount: Double? = definedExternally)

Translates the camera's position by amount along the opposite direction of the camera's view vector. When in 2D mode, this will zoom out the camera instead of translating the camera's position.

Link copied to clipboard
fun moveDown(amount: Double? = definedExternally)

Translates the camera's position by amount along the opposite direction of the camera's up vector.

Link copied to clipboard
fun moveForward(amount: Double? = definedExternally)

Translates the camera's position by amount along the camera's view vector. When in 2D mode, this will zoom in the camera instead of translating the camera's position.

Link copied to clipboard
fun moveLeft(amount: Double? = definedExternally)

Translates the camera's position by amount along the opposite direction of the camera's right vector.

Link copied to clipboard
fun moveRight(amount: Double? = definedExternally)

Translates the camera's position by amount along the camera's right vector.

Link copied to clipboard
fun moveUp(amount: Double? = definedExternally)

Translates the camera's position by amount along the camera's up vector.

Link copied to clipboard
fun pickEllipsoid(windowPosition: Cartesian2, ellipsoid: Ellipsoid? = definedExternally, result: Cartesian3? = definedExternally): Cartesian3?

Pick an ellipsoid or map.

Link copied to clipboard
fun rotate(axis: Cartesian3, angle: Double? = definedExternally)

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.

Link copied to clipboard
fun rotateDown(angle: Double? = definedExternally)

Rotates the camera around the center of the camera's reference frame by angle downwards.

Link copied to clipboard
fun rotateLeft(angle: Double? = definedExternally)

Rotates the camera around the center of the camera's reference frame by angle to the left.

Link copied to clipboard
fun rotateRight(angle: Double? = definedExternally)

Rotates the camera around the center of the camera's reference frame by angle to the right.

Link copied to clipboard
fun rotateUp(angle: Double? = definedExternally)

Rotates the camera around the center of the camera's reference frame by angle upwards.

Link copied to clipboard

Sets the camera position, orientation and transform.

Link copied to clipboard

Switches the frustum/projection to orthographic.

Link copied to clipboard

Switches the frustum/projection to perspective.

Link copied to clipboard
fun twistLeft(amount: Double? = definedExternally)

Rotate the camera counter-clockwise around its direction vector by amount, in radians.

Link copied to clipboard
fun twistRight(amount: Double? = definedExternally)

Rotate the camera clockwise around its direction vector by amount, in radians.

Link copied to clipboard
fun viewBoundingSphere(boundingSphere: BoundingSphere, offset: HeadingPitchRange? = definedExternally)

Sets the camera so that the current view contains the provided bounding sphere.

Link copied to clipboard
fun worldToCameraCoordinates(cartesian: Cartesian4, result: Cartesian4? = definedExternally): Cartesian4

Transform a vector or point from world coordinates to the camera's reference frame.

Link copied to clipboard
fun worldToCameraCoordinatesPoint(cartesian: Cartesian3, result: Cartesian3? = definedExternally): Cartesian3

Transform a point from world coordinates to the camera's reference frame.

Link copied to clipboard
fun worldToCameraCoordinatesVector(cartesian: Cartesian3, result: Cartesian3? = definedExternally): Cartesian3

Transform a vector from world coordinates to the camera's reference frame.

Link copied to clipboard
fun zoomIn(amount: Double? = definedExternally)

Zooms amount along the camera's view vector.

Link copied to clipboard
fun zoomOut(amount: Double? = definedExternally)

Zooms amount along the opposite direction of the camera's view vector.