描述:场景中有一个车辆,场景视角跟随车辆
一、第三人称视角跟随
原理:根据车辆位置和朝向,建立局部坐标系,并让相机看向这个位置
let center = this.trackedEntity.position.getValue(
viewer.clock.currentTime
);
let orientation = this.trackedEntity.orientation.getValue(
viewer.clock.currentTime
)
// 以车辆建立局部坐标系
let transform = Cesium.Transforms.eastNorthUpToFixedFrame(center);
// 取车辆的朝向,让车辆指向正北方向
transform = Cesium.Matrix4.fromRotationTranslation(Cesium.Matrix3.fromQuaternion(orientation), center);
// lookAtTransform的第二个参数,设置相机的朝向,heading设置为90则相机视角跟在车辆后面
viewer.camera.lookAtTransform(transform, new Cesium.HeadingPitchRange(Cesium.Math.toRadians(90), Cesium.Math.toRadians(-10.0), 25));
二、锁定视角
viewer.camera.lookAtTransform(transform, new Cesium.HeadingPitchRange(Cesium.Math.toRadians(90), Cesium.Math.toRadians(-10.0), 25));
lookAtTransform参数详解
三、解锁视角
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
标签:视角,viewer,transform,跟随,Cesium,lookAtTransform,cesium,Math
From: https://blog.csdn.net/AllBluefm/article/details/137544328