1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
export function updateModelMatrix({tilesetId,sourceCenter,positionLatlng, scale={x:1,y:1,z:1},rotate={x:0,y:0,z:0}}) { const matrixMove = Cesium.Matrix4.fromTranslation(Cesium.Cartesian3.subtract( Cesium.Cartesian3.fromDegrees(positionLatlng.lng,positionLatlng.lat,positionLatlng.height), sourceCenter, new Cesium.Cartesian3() )) const backto_matrix = Cesium.Matrix4.fromTranslation(sourceCenter); const moveto_vec = Cesium.Cartesian3.multiplyByScalar(sourceCenter, -1, new Cesium.Cartesian3()); const moveto_matrix = Cesium.Matrix4.fromTranslation(moveto_vec); const scaleMatrix = Cesium.Matrix4.fromScale(new Cesium.Cartesian3(scale.x, scale.y, scale.z)) const tempScaleMatrix = Cesium.Matrix4.multiply(scaleMatrix,moveto_matrix,new Cesium.Matrix4()) const rotateZMatrix = Cesium.Matrix4.fromRotation(Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(rotate.z))) const rotateYMatrix = Cesium.Matrix4.fromRotation(Cesium.Matrix3.fromRotationY(Cesium.Math.toRadians(rotate.y))) const rotateXMatrix = Cesium.Matrix4.fromRotation(Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(rotate.x))) const rotateMatrixTemp = Cesium.Matrix4.multiply(rotateZMatrix,rotateYMatrix,new Cesium.Matrix4()) const rotateMatrix = Cesium.Matrix4.multiply(rotateXMatrix,rotateMatrixTemp,new Cesium.Matrix4()) const yuanDianRotateScaleMatrix = Cesium.Matrix4.multiply(rotateMatrix,tempScaleMatrix,new Cesium.Matrix4()) const yuanDianMoveMatrix = Cesium.Matrix4.multiply(matrixMove,yuanDianRotateScaleMatrix,new Cesium.Matrix4()) const matrix4Final = Cesium.Matrix4.multiply(backto_matrix,yuanDianMoveMatrix,new Cesium.Matrix4()) const tileset = getTilesetById(tilesetId) tileset.modelMatrix = matrix4Final
}
|