相机类,它由位置、方向和视锥体定义。
视锥体(viewing frustum)由6个(上、下、左、右、近、远)平面限定,每个平面可由
Cartesian4对象表示,其中x,y和z分量定义垂直于平面的单位向量,w分量是平面距原点/相机位置的距离。
| Name | Type | Description |
|---|---|---|
scene |
Scene | 场景对象。 |
Example:
// 创建相机对象。
var camera = new Cesium.Camera(scene);
Members
-
Gets the event that will be raised when the camera has changed by
percentageChanged. -
direction : Cartesian3
-
相机视图方向。
-
视野中的空间区域,即视锥体。
-
Default Value:
- PerspectiveFrustum
- PerspectiveOffCenterFrustum
- OrthographicFrustum
PerspectiveFrustum()See:
-
获取相机方位角,单位为弧度。
-
获取相机的俯仰角,单位为弧度。
-
position : Cartesian3
-
相机对象的位置。
-
right : Cartesian3
-
相机的右(right)方向。
-
获取相机旋转角度,单位为弧度。
-
up : Cartesian3
-
相机的上(up)方向。
Methods
-
相机从当前位置飞行到新的空间位置。
Name Type Description optionsObject 对象具有以下属性: Name Type Description destinationCartesian3 | Rectangle 相机在WGS84世界坐标系中的最终位置,或是自顶向下视图中可见的矩形区域。 orientationObject optional 包含了方位(direction)、上方向(up)以及方位角(heading)、俯仰角(pitch)、滚动角(roll)属性的对象。 默认情况下,3D中方位(direction)指向框架中心,在Columbus视图中指向负z方向。 在3D中上方向(up)指向本地北方向,而在Columbus视图中指向正y方向。在无限滚动模式下,二维视图不使用方向(orientation)。 durationNumber optional 飞行持续时间(以秒为单位)。如果省略,由飞行距离计算合理的持续时间。 completeCamera~FlightCompleteCallback optional 飞行完成时执行的功能。 cancelCamera~FlightCancelledCallback optional 飞行取消时执行的功能。 endTransformMatrix4 optional 飞行完成时相机将处于的参考系的变换矩阵。 maximumHeightNumber optional 飞行中的最大高度。 easingFunctionEasingFunction | EasingFunction~Callback optional 释放时调用功能。 Throws:
-
DeveloperError : 若提供了方向(direction )、上方向(up)两者之一,则两者都需要提供。
Example:
// 1. 飞向通过top-down视图表示的位置 viewer.camera.flyTo({ destination : Cesium.Cartesian3.fromDegrees(-117.16, 32.71, 15000.0) }); // 2. 飞向通过top-down视图表示的矩形 viewer.camera.flyTo({ destination : Cesium.Rectangle.fromDegrees(west, south, east, north) }); // 3. 飞向利用单位向量表示方向(orientatin)的位置 viewer.camera.flyTo({ destination : Cesium.Cartesian3.fromDegrees(-122.19, 46.25, 5000.0), orientation : { direction : new Cesium.Cartesian3(-0.04231243104240401, -0.20123236049443421, -0.97862924300734), up : new Cesium.Cartesian3(-0.47934589305293746, -0.8553216253114552, 0.1966022179118339) } }); // 4. 飞向利用方位角(heading)、俯仰角(pitch)、滚动角(roll)表示方向(orientatin)的位置 viewer.camera.flyTo({ destination : Cesium.Cartesian3.fromDegrees(-122.19, 46.25, 5000.0), orientation : { heading : Cesium.Math.toRadians(175.0), pitch : Cesium.Math.toRadians(-35.0), roll : 0.0 } }); -
-
通过目标(target)和偏移(offset)设置相机位置、方向。
目标(target)以世界坐标方式表示;偏移(offset)是在以目标为中心的本地“东-北-上”参考系中的笛卡尔坐标或“方位角/俯仰角/范围(heading/pitch/range)”。
如果偏移(offset)由笛卡尔坐标表示,它表示距离由变换矩阵定义的参考系中心的偏移量。 如果偏移(offset)由“heading/pitch/range”表示,方位角(heading)和俯仰角(pitch)的角度由根据变换矩阵定义的参考系确定,方位角(heading)从y轴开始朝向x轴增加,俯仰角(pitch)为从xy平面的旋转角度,正的俯仰角位于平面下方,负的俯仰角位于平面上方。
范围(range)为距中心点的距离。在2D中必须为自上而下视图,相机位于俯视目标的上方,目标上方的高度值是偏移量的大小。方位角根据偏移确定,如果不能从偏移确定方位角,则方位角为北方向。Name Type Description targetCartesian3 目标在世界坐标中的空间位置。 offsetCartesian3 | HeadingPitchRange 距以目标为中心的本地“东-北-上”参考系的偏移。 Throws:
-
DeveloperError : 变形时不支持lookAt方法。
Example:
// 1. 利用笛卡尔坐标设置偏移 var center = Cesium.Cartesian3.fromDegrees(-98.0, 40.0); viewer.camera.lookAt(center, new Cesium.Cartesian3(0.0, -4790000.0, 3930000.0)); // 2. 利用HeadingPitchRange设置偏移 var center = Cesium.Cartesian3.fromDegrees(-72.0, 40.0); var heading = Cesium.Math.toRadians(50.0); var pitch = Cesium.Math.toRadians(-20.0); var range = 5000.0; viewer.camera.lookAt(center, new Cesium.HeadingPitchRange(heading, pitch, range)); -
-
设置相机位置、方向和变换。
Name Type Description optionsObject 对象具有以下属性: Name Type Description destinationCartesian3 | Rectangle optional 相机在WGS84世界坐标系中的最终位置,或是自顶向下视图中可见的矩形区域。 orientationObject optional 包含了方位(direction)、上方向(up)以及方位角(heading)、俯仰角(pitch)、滚动角(roll)属性的对象。 默认情况下,3D中方位(direction)指向框架中心,在Columbus视图中指向负z方向。 在3D中上方向(up)指向本地北方向,而在Columbus视图中指向正y方向。在无限滚动模式下,二维视图不使用方向(orientation)。 endTransformMatrix4 optional 表示相机参考坐标系的变换矩阵。 Example:
// 1. 通过top-down视图设置位置。 viewer.camera.setView({ destination : Cesium.Cartesian3.fromDegrees(-117.16, 32.71, 15000.0) }); // 2. 通过方位角、俯仰角、滚动角设置视图。 viewer.camera.setView({ destination : cartesianPosition, orientation: { heading : Cesium.Math.toRadians(90.0), // east, default value is 0.0 (north) pitch : Cesium.Math.toRadians(-90), // default value (looking down) roll : 0.0 // default value } }); // 3. 相机空间位置不变,改变方位角、俯仰角和滚动角。 viewer.camera.setView({ orientation: { heading : Cesium.Math.toRadians(90.0), // east, default value is 0.0 (north) pitch : Cesium.Math.toRadians(-90), // default value (looking down) roll : 0.0 // default value } }); // 4. 通过自顶向下视图查看矩形。 viewer.camera.setView({ destination : Cesium.Rectangle.fromDegrees(west, south, east, north) }); // 5. 通过使用单位向量的方向(orientation)设置相机位置。 viewer.camera.setView({ destination : Cesium.Cartesian3.fromDegrees(-122.19, 46.25, 5000.0), orientation : { direction : new Cesium.Cartesian3(-0.04231243104240401, -0.20123236049443421, -0.97862924300734), up : new Cesium.Cartesian3(-0.47934589305293746, -0.8553216253114552, 0.1966022179118339) } });
