Cesium 键盘操作修改模型矩阵,调整位置和角度

    技术2022-07-13  87

    数据加载:

    let models = viewer.scene.primitives.add(Cesium.Model.fromGltf({ url: './tree/qtc1.gltf', modelMatrix: modelMatrixe, scale: 1, show: true, luminanceAtZenith: 0.8 }))

    模块加载:

    import { moveData } from "moveData.js"; moveData.moveData(models,Cesium);

     

    操作模块:

    export const moveData = {}; moveData.moveData = function (models,Cesium) { document.onkeydown=function(event){ let e = event || window.event || arguments.callee.caller.arguments[0]; //位置 if(e.key == 'ArrowUp'){ models.modelMatrix[12]=models.modelMatrix[12]+1 }else if(e.key == 'ArrowDown'){ models.modelMatrix[12]=models.modelMatrix[12]-1 }else if(e.key == 'ArrowLeft'){ models.modelMatrix[14]=models.modelMatrix[14]+1 }else if(e.key == 'ArrowRight'){ models.modelMatrix[14]=models.modelMatrix[14]-1 } //角度 else if(e.key == '8'){ m1=Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(1)) Cesium.Matrix4.multiplyByMatrix3(models.modelMatrix, m1, models.modelMatrix); }else if(e.key == '2'){ m1=Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(-1)) Cesium.Matrix4.multiplyByMatrix3(models.modelMatrix, m1, models.modelMatrix); }else if(e.key == '4'){ m1 = Cesium.Matrix3.fromRotationY(Cesium.Math.toRadians(1)); Cesium.Matrix4.multiplyByMatrix3(models.modelMatrix, m1, models.modelMatrix); }else if(e.key == '6'){ m1 = Cesium.Matrix3.fromRotationY(Cesium.Math.toRadians(-1)); Cesium.Matrix4.multiplyByMatrix3(models.modelMatrix, m1, models.modelMatrix); }else if(e.key === '1'){ m1 = Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(1)); Cesium.Matrix4.multiplyByMatrix3(models.modelMatrix, m1, models.modelMatrix); }else if(e.key == '3'){ m1 = Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(-1)); Cesium.Matrix4.multiplyByMatrix3(models.modelMatrix, m1, models.modelMatrix); } //高度 else if(e.key == '7'){ models.modelMatrix[13]=models.modelMatrix[13]+1 } else if(e.key == '9'){ models.modelMatrix[13]=models.modelMatrix[13]-1 } console.log(models.modelMatrix) } }

     

     

    Processed: 0.009, SQL: 9