cesium 设置飞机的heading pitch roll(航向等)

cesium 设置飞机的heading pitch roll

知识点普及:

  • pitch是围绕X轴旋转,也叫做俯仰角,
  • heading(yaw)是围绕Y轴旋转,也叫偏航角,(平行于z轴,就是水平旋转的,其他同理)
  • roll是围绕Z轴旋转,也叫翻滚角,

代码:

var drone;
var head=0;
var pitch = 0.0;
var roll = 0.0;
var czml= [
{
    "id":"document",
    "name":"SampleFlight",
    "version":"1.0",
    "clock":{
        "interval":"20170711T16Z/20170711T1620Z",
        "currentTime":"20170711T16Z",
        "multiplier":2,
        "range":"LOOP_STOP",
        "step":"SYSTEM_CLOCK_MULTIPLIER"
    }
},
{
    "id":"Aircraft/Aircraft1",
    "name":"Aircraft1",
    "availability":"20170711T16Z/20170711T162001.65996549888041Z",
    "billboard":{
        "color":{
            "rgba":[
                0,
                0,
                0,
                0
            ]
        },
        "eyeOffset":{
            "cartesian":[
                0,
                0,
                0
            ]
        },
        "horizontalOrigin":"LEFT","image":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAjSURBVChTYyAa/EcDUGEIgIphAKg0XRSAAFQMDqDChAADAwDC13+BJ+0oDwAAAABJRU5ErkJgggAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
        "pixelOffset":{
            "cartesian2":[
                0,
                0
            ]
        },
        "scale":0.5,
        "show":true,
        "verticalOrigin":"CENTER"
    },
    "path": {
        "show": [{
            "interval": "20190926T19Z/20190926T193001.65996549900046Z",
            "boolean": true
        }],
        "width": 5,
        "material": {
            "solidColor": {
                "color": {
                    "rgba": [0, 255, 255, 255]
                }
            }
        },
        "resolution": 1200
    },
    "position":{
        "interpolationAlgorithm": "LAGRANGE",
        "interpolationDegree": 5,
        "cartographicDegrees":[118.8184261322,32.0604277464,1000]
    }
}]  //加载自定义的飞行器模型(gltf格式)
function addRealPlane() {
/*
    //加载gltf格式数据到cesium
    var scene=viewer.scene;
    var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(
        Cesium.Cartesian3.fromDegrees(118.832927,32.005737,6.0));        //gltf数据加载位置
    var model = scene.primitives.add(Cesium.Model.fromGltf({
        url : 'http://localhost/cesium_xxf_test/Apps/SampleData/models/CesiumAir/Cesium_Air.gltf',        //Cesium_Air  Multi ScanEagle uav0701 ok
        modelMatrix : modelMatrix,
        scale : 1    //放大倍数
    }));
    viewer.camera.flyTo({
        destination : Cesium.Cartesian3.fromDegrees(118.832927,32.005737,6)     //相机飞入点
    });
    viewer.flyTo({
        destination : Cesium.Cartesian3.fromDegrees(118.832927,32.005737,6)     //相机飞入点
    });
    viewer.zoomTo(model);
    console.log("开始添加模拟飞行器模型");
    var dronePromise = Cesium.CzmlDataSource.load('http://localhost/cesium_xxf_test/Apps/SampleData/sampleFlight_nj.czml');
    dronePromise.then(function(dataSource) {
        try {
            viewer.dataSources.add(dataSource);
             drone = dataSource.entities.getById('Aircraft/Aircraft1');
            //固定翼
            drone.model = {
                uri: 'http://localhost/cesium_xxf_test/Apps/SampleData/models/CesiumAir/Cesium_Air  .gltf', // 模型的位置
                //  uri: httproot+'SampleData/models/CesiumAir/UAV.gltf', //ok
                  scale:10, // 模型比例,放大10倍
                asynchronous: true,
                allowPicking: true
            };
            drone.position = Cesium.Cartesian3.fromDegrees(118.832927,32.005737,0);
            drone._id = "only_drone_test";
            drone.name = "飞行器-only_drone_test";
          //  drone.scale = 100;
            drone.minimumPixelSize = 1000;
            drone.viewFrom = new Cesium.Cartesian3(0, 0, 0);
            viewer.zoomTo(drone);
            viewer.flyTo(drone);
        }catch(e){
            console.error(e.message);
        }
    });
    //设置一个定时器,每秒添加10度的航向
    var timeinterval = setInterval(dronechange,1000);
}
//改变航向
function dronechange() {
    if(drone){
        //仅改变位置
        var position = Cesium.Cartesian3.fromDegrees(118.832927,32.005737,0);
        drone.position = position;
        var hpr = new Cesium.HeadingPitchRoll(Cesium.Math.toRadians(head), pitch, roll);
        var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);
        // var orientation = Cesium.Transforms.headingPitchRollQuaternion(drone.position, hpr); //这种写法会报错,不知道为什么
        drone.orientation = orientation;
        head=head+10;
    }
}

你可能感兴趣的:(cesium)