1.根据前后经纬度和高度计算变换矩阵-平移矩阵:
step1:根据tileset的边界球体中心点的笛卡尔坐标得到经纬度坐标
step2:根据经纬度和高度0,得到地面笛卡尔坐标
step3:根据经纬度和需要的高度,得到偏移后的笛卡尔坐标
step4:计算坐标变换,得到新的笛卡尔坐标
根据变换得到Matrix4变换矩阵
var cartographic = Cesium.Cartographic.fromCartesian(tileset.boundingSphere.center);
var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0);
var offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, height);
var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
1.根据旋转角度计算变换矩阵-旋转矩阵:
var hprRollZero = new Cesium.HeadingPitchRoll();
var position=Cesium.Cartesian3.fromDegrees(-123.075, 44.045000, 5000.0)
var converter= Cesium.Transforms.eastNorthUpToFixedFrame
var hpRoll = new Cesium.HeadingPitchRoll();
//计算原始的modelMatrix
var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(position, hprRollZero, Cesium.Ellipsoid.WGS84, converter);
scene.primitives.add(new Cesium.DebugModelMatrixPrimitive({
modelMatrix : modelMatrix,
length : 300.0,
width : 10.0
}));
//当hproll变化后,计算新的modelMatrix
//每次移动单位为1度,转为弧度
// turn right
hpRoll.heading += deltaRadians;
//
hpRoll.pitch -= deltaRadians;
var deltaRadians = Cesium.Math.toRadians(1.0);
var medelMaxtrix=Cesium.Transforms.headingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, converter, primitive.modelMatrix);