viewer.scene.preUpdate.addEventListener( ()=> {
speedVector = Cesium.Cartesian3.multiplyByScalar(
Cesium.Cartesian3.UNIT_X,
speed / 10,
speedVector
);
position = Cesium.Matrix4.multiplyByPoint(
planePrimitive.modelMatrix,
speedVector,
position
);
pathPosition.addSample(Cesium.JulianDate.now(), position);
let pt = viewer.scene.clampToHeight(position, [planePrimitive]);
if (Cesium.defined(pt)) {
Cesium.Transforms.headingPitchRollToFixedFrame(
pt,
hpRoll,
Cesium.Ellipsoid.WGS84,
fixedFrameTransform,
planePrimitive.modelMatrix
);
}
if (needFollow) {
if (planePrimitive && Cesium.defined(planePrimitive._boundingSphere)){
Cesium.Matrix4.multiplyByPoint(
planePrimitive.modelMatrix,
planePrimitive.boundingSphere.center,
center
);
hpRange.heading = hpRoll.heading;
hpRange.pitch = Cesium.Math.toRadians(-15);
hpRange.range = 30;
camera.lookAt(center, hpRange);
}
}
});