| var scene = viewer.scene; |
| |
| let radian = Cesium.Math.toRadians(3.0); |
| |
| let speed = 60; |
| |
| let speedVector = new Cesium.Cartesian3(); |
| |
| let position = Cesium.Cartesian3.fromDegrees(102.23292685840103, 27.825718192817853, 2500.0); |
| |
| |
| let hpRoll = new Cesium.HeadingPitchRoll(); |
| let fixedFrameTransforms = Cesium.Transforms.localFrameToFixedFrameGenerator('north', 'west'); |
| |
| let modelPrimitive = scene.primitives.add(Cesium.Model.fromGltf({ |
| url: 'Assets/SampleData/models/CesiumAir/Cesium_Air.glb', |
| modelMatrix: Cesium.Transforms.headingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, fixedFrameTransforms), |
| minimumPixelSize: 128 |
| })); |
| |
| |
| let flag = { |
| moveUp: false, |
| moveDown: false, |
| moveLeft: false, |
| moveRight: false |
| }; |
| |
| |
| function setFlagStatus(key, value) { |
| switch (key.keyCode) { |
| case 37: |
| |
| flag.moveLeft = value; |
| break; |
| case 38: |
| |
| flag.moveUp = value; |
| break; |
| case 39: |
| |
| flag.moveRight = value; |
| break; |
| case 40: |
| flag.moveDown = value; |
| |
| break; |
| } |
| } |
| |
| document.addEventListener('keydown', (e) => { |
| setFlagStatus(e, true); |
| }); |
| |
| document.addEventListener('keyup', (e) => { |
| setFlagStatus(e, false); |
| }); |
| |
| viewer.clock.onTick.addEventListener((clock) => { |
| |
| if (flag.moveUp) { |
| |
| if (flag.moveLeft) { |
| hpRoll.heading -= radian; |
| } |
| |
| if (flag.moveRight) { |
| hpRoll.heading += radian; |
| } |
| moveModel(true); |
| } |
| |
| if (flag.moveDown) { |
| if (flag.moveLeft) { |
| hpRoll.heading += radian; |
| } |
| |
| if (flag.moveRight) { |
| hpRoll.heading -= radian; |
| } |
| moveModel(false); |
| } |
| }); |
| |
| |
| function moveModel(isUP) { |
| |
| if (isUP > 0) { |
| speedVector = Cesium.Cartesian3.multiplyByScalar(Cesium.Cartesian3.UNIT_X, speed, speedVector); |
| } else { |
| speedVector = Cesium.Cartesian3.multiplyByScalar(Cesium.Cartesian3.UNIT_X, -speed, speedVector); |
| } |
| |
| position = Cesium.Matrix4.multiplyByPoint(modelPrimitive.modelMatrix, speedVector, position); |
| |
| Cesium.Transforms.headingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, fixedFrameTransforms, modelPrimitive.modelMatrix); |
| } |