Bootstrap

cesium实现向卫星添加传感器并跟随卫星移动

cesium实现向卫星添加传感器并跟随卫星移动

import * as Cesium from 'cesium'
import "./CesiumSensors.js";

/* eslint-disable */

// 添加矩形传感器
export default function entityAddSensor(viewer, satellite) {// 场景,卫星实体
    viewer.scene.primitives.removeAll();// 删除所有传感器
    var rectangularPyramidSensor = new CesiumSensors.RectangularPyramidSensorVolume(); // 矩形棱锥传感器体积
    rectangularPyramidSensor.radius = 20000000.0;
    rectangularPyramidSensor.xHalfAngle = Cesium.Math.toRadians(25.0);// 矩形的长
    rectangularPyramidSensor.yHalfAngle = Cesium.Math.toRadians(15.0);// 矩形的宽
    rectangularPyramidSensor.lateralSurfaceMaterial = Cesium.Material.fromType('Color');// 侧面材料
    rectangularPyramidSensor.lateralSurfaceMaterial.uniforms.color = new Cesium.Color(0.0, 1.0, 1.0, 0.5);

    viewer.scene.preRender.addEventListener((scene,time)=>{ // preRender: 获取在场景更新之后以及场景渲染之前立即引发的事件。事件的订阅者将Scene实例作为第一个参数,将当前时间作为第二个参数。
        let modelMatrix  = satellite.computeModelMatrix(time); // 在指定时间计算实体转换的模型矩阵, -> Matrix4
        Cesium.Matrix4.multiply(modelMatrix, Cesium.Matrix4.fromRotationTranslation(Cesium.Matrix3.fromRotationY(Cesium.Math.toRadians(-180))), modelMatrix)// multiply 计算两个矩阵的乘积;  fromRotationTranslation 从表示旋转的Matrix3和表示平移的Catresian3中计算Matrix4实例
        rectangularPyramidSensor.modelMatrix = modelMatrix
    })
    viewer.scene.primitives.add(rectangularPyramidSensor);
}

CesiumSensors.js 资源下载链接:https://download.csdn.net/download/qq_41176306/16714510

;