cesium中orientation可以设置朝向,由position和HeadingPitchRoll共同决定,类型为headingPitchRollQuaternion,值是一个四元数。
一、设置orientation
// entity位置
let position = Cesium.Cartesian3.fromDegrees(113.295660, 38.1905, 0);
// orientation
let orientation = Cesium.Transforms.headingPitchRollQuaternion(
position,
new Cesium.HeadingPitchRoll(Cesium.Math.toRadians(10), Cesium.Math.toRadians(20), Cesium.Math.toRadians(30)),
);
二、orientation转hpr,得到对应的HeadingPitchRoll
// 四元数计算三维旋转矩阵
let mtx3 = Cesium.Matrix3.fromQuaternion(orientation, new Cesium.Matrix3());
// 四维转换矩阵
let mtx4 = Cesium.Matrix4.fromRotationTranslation(mtx3, position, new Cesium.Matrix4());
// 计算HeadingPitchRoll,结果为弧度
let hpr = Cesium.Transforms.fixedFrameToHeadingPitchRoll(
mtx4,
Cesium.Ellipsoid.WGS84,
Cesium.Transforms.eastNorthUpToFixedFrame,
new Cesium.HeadingPitchRoll(),
);
// 转成角度
let heading = Cesium.Math.toDegrees(hpr.heading);
let pitch= Cesium.Math.toDegrees(hpr.pitch);
let roll= Cesium.Math.toDegrees(hpr.roll);