记录Cesium中完成巡逻飞行第一人称的视角调整:
完成思路:飞行巡逻时,监听此对象的实时坐标经纬度等数据,由此数据进行视角的优化调整。
效果图:
关键代码:
var ori = orientationProperty.getValue(that.viewer.clock.currentTime); //获取偏向角
var center = positionProperty.getValue(that.viewer.clock.currentTime); //获取位置
var test = Cesium.Cartesian3.fromDegrees(QueryResultl, QueryResultlat, cartographic.height)
var transform = Cesium.Matrix4.fromRotationTranslation(Cesium.Matrix3.fromQuaternion(ori), test); //将偏向角转为3*3矩阵,利用实时点位转为4*4矩阵
viewer.camera.lookAtTransform(transform, new Cesium.Cartesian3(-50, 0, 10)) //将相机向后面放一点
viewer.clock.onTick.addEventListener对clock增加监听事件;
viewer.clock.shouldAnimate =true 启动时钟开始转动
//监听时间变化
var that = this
that.viewer.clock.onTick.addEventListener(function(e){
if(that.viewer.clock.shouldAnimate === true){
// 此处为我代码中判断是什么视角,以下为第一人称视角
if(viewSelect == 'flyWithFirstPerson' || viewSelect==undefined) {
m_TrackManager.activeRount.setModelVisible(false); // 封装为模型隐藏
var centerCamera = positionProperty.getValue(that.viewer.clock.currentTime);//获取位置
var cartographic = Cesium.Cartographic.fromCartesian(centerCamera)
var QueryResultl = Cesium.Math.toDegrees(cartographic.longitude); //四舍五入 小数点后保留五位
var QueryResultlat = Cesium.Math.toDegrees(cartographic.latitude)
// 以下为可实时调整高度
cartographic.height = heightSplider
if(heightSplider){
cartographic.height = heightSplider
}else{
cartographic.height = 10
}
var ori = orientationProperty.getValue(that.viewer.clock.currentTime); //获取偏向角
var center = positionProperty.getValue(that.viewer.clock.currentTime); //获取位置
var test = Cesium.Cartesian3.fromDegrees(QueryResultl, QueryResultlat, cartographic.height)
var transform = Cesium.Matrix4.fromRotationTranslation(Cesium.Matrix3.fromQuaternion(ori), test); //将偏向角转为3*3矩阵,利用实时点位转为4*4矩阵
that.viewer.camera.lookAtTransform(transform, new Cesium.Cartesian3(-50, 0, 10)) //将相机向后面放一点
} else {
// 切换为其他视角
}
}
}