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.
// 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
The scene.
See also
Types
Properties
Gets the event that will be raised when the camera has changed by percentageChanged
.
If set, the camera will not be able to rotate past this axis in either direction.
The default amount to rotate the camera when an argument is not provided to the look methods.
The default amount to move the camera when an argument is not provided to the move methods.
The default amount to rotate the camera when an argument is not provided to the rotate methods.
The default amount to move the camera when an argument is not provided to the zoom methods.
The view direction of the camera.
Gets the view direction of the camera in world coordinates.
Gets the inverse camera transform.
Gets the inverse view matrix.
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.
Gets the event that will be raised when the camera has stopped moving.
Gets the event that will be raised at when the camera starts to move.
The amount the camera has to change before the changed
event is raised. The value is a percentage in the 0, 1 range.
The position of the camera.
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.
Gets the position of the camera in world coordinates.
The right direction of the camera.
Gets the right direction of the camera in world coordinates.
The up direction of the camera.
Gets the up direction of the camera in world coordinates.
Gets the view matrix.
Functions
Transform a vector or point from the camera's reference frame to world coordinates.
Transform a point from the camera's reference frame to world coordinates.
Transform a vector from the camera's reference frame to world coordinates.
Cancels the current camera flight and leaves the camera at its current location. If no flight is in progress, this this function does nothing.
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.
Computes the approximate visible rectangle on the ellipsoid.
Return the distance from the camera to the front of the bounding sphere.
Flies the camera from its current position to a new position.
Flies the camera to a location where the current view contains the provided bounding sphere.
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.
Create a ray from the camera position through the pixel at windowPosition
in world coordinates.
Return the pixel size in meters.
Get the camera position needed to view a rectangle on an ellipsoid or map
Rotate each of the camera's orientation vectors around axis
by angle
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.
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.
Translates the camera's position by amount
along direction
.
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.
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.
Pick an ellipsoid or map.
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.
Rotates the camera around the center of the camera's reference frame by angle downwards.
Rotates the camera around the center of the camera's reference frame by angle to the left.
Rotates the camera around the center of the camera's reference frame by angle to the right.
Sets the camera position, orientation and transform.
Switches the frustum/projection to orthographic.
Switches the frustum/projection to perspective.
Rotate the camera clockwise around its direction vector by amount, in radians.
Sets the camera so that the current view contains the provided bounding sphere.
Transform a vector or point from world coordinates to the camera's reference frame.
Transform a point from world coordinates to the camera's reference frame.
Transform a vector from world coordinates to the camera's reference frame.