目录
当前位置: 首页 > 文档资料 > Cesium 中文文档 >

Camera控制

优质
小牛编辑
118浏览
2023-12-01

操作方式

cesium提供了三种方式,可以对camera进行操作,这三种方式,有三个共同的参数,heading,pitch,roll,那么,这三个参数分别是什么呢?
cesium原文如下:

Heading is the rotation about the negative z axis. Pitch is the rotation about the negative y axis. Roll is the rotation about the positive x axis

Roll 是围绕X轴旋转,

Pitch 是围绕Y轴旋转,

Heading 是围绕Z轴旋转,下图中yaw

cesium提供三种方式的三种方式分别为,setView,flyto,lookAt,使用方法如下:

第一种setView

有两种计算视角方式:

  • Cartesian3方式:
view.camera.setView({
  destination : Cesium.Cartesian3.fromDegrees(116.435314,39.960521, 15000.0), // 设置位置

  orientation: {
    heading : Cesium.Math.toRadians(20.0), // 方向
    pitch : Cesium.Math.toRadians(-90.0),// 倾斜角度
    roll : 0
  }
});
  • rectangle 方式:
view.camera.setView({

destination: Cesium.Rectangle.fromDegrees(0.0, 20.0, 10.0, 30.0),//west, south, east, north

orientation: {

heading : Cesium.Math.toRadians(20.0), // 方向

pitch : Cesium.Math.toRadians(-90.0),// 倾斜角度

roll : 0

} });

第二种方式,flyto

view.camera.flyTo({
  destination :Cesium.Cartesian3.fromDegrees(116.435314,39.960521, 15000.0), // 设置位置
  orientation: {
    heading :Cesium.Math.toRadians(20.0), // 方向
    pitch :Cesium.Math.toRadians(-90.0),// 倾斜角度
    roll :0
  },
  duration:5, // 设置飞行持续时间,默认会根据距离来计算
  complete:function () {
  // 到达位置后执行的回调函数
  },
  cancle:function () {
  // 如果取消飞行则会调用此函数
  },
  pitchAdjustHeight:-90, // 如果摄像机飞越高于该值,则调整俯仰俯仰的俯仰角度,并将地球保持在视口中。
  maximumHeight:5000, // 相机最大飞行高度
  flyOverLongitude:100, // 如果到达目的地有2种方式,设置具体值后会强制选择方向飞过这个经度(这个,很好用)
});

第三种方式lookAt

var center = Cesium.Cartesian3.fromDegrees(114.44455, 22.0444);//camera视野的中心点坐标
var heading = Cesium.Math.toRadians(50.0);
var pitch = Cesium.Math.toRadians(-20.0);
var range = 5000.0;
view.camera.lookAt(center, new Cesium.HeadingPitchRange(heading, pitch, range));

如果有些人加载了室内模型,可能还要用WASDQR像在游戏中一样的行走,cesium也能实现此功能,且听下回分解。