4、cesium位置初始化

cesium位置初始化

cesium位置初始化,就是在你刚加载3d页面的时候,相机所指向的位置(或者其他一些需要初始化的地方。)

话不多说,直接上案例,有不懂的请加下面的学习群,一起讨论。

1     viewer.scene.camera.flyTo({
2         destination: new Cesium.Cartesian3.fromDegrees(118.16029, 30.15988, 29600.209),
3         orientation: {
4             heading: Cesium.Math.toRadians(0),
5             pitch: Cesium.Math.toRadians(-90),
6             roll: Cesium.Math.toRadians(0)
7         },
8         duration: 3.0
9     })

其中的flyto是你飞到某个位置的一个方法。

118.16029, 30.15988, 29600.209这三个数分别是你的经度、纬度还有高程的位置。
heading: Cesium.Math.toRadians(0),
pitch: Cesium.Math.toRadians(-90),
roll: Cesium.Math.toRadians(0)        请看下面的文档解释:
 duration: 3.0这句话的意思是,你飞到这个位置所用的时间是3秒。


附带转换方法
  // 假设当前模型的经纬度坐标为{114, 30, 1000} 方位角{heading: 30, pitch: 20, roll: 10} 都是角度来计算 
 2         // 1. 根据坐标, 方位角计算世界矩阵
 3         var position = Cesium.Cartesian3.fromDegrees(114, 30, 1000);
 4         var heading = Cesium.Math.toRadians(30);
 5         var pitch = Cesium.Math.toRadians(20);
 6         var roll = Cesium.Math.toRadians(10);
 7         var headingPitchRoll = new Cesium.HeadingPitchRoll(heading, pitch, roll);
 8  
 9         var m = Cesium.Transforms.headingPitchRollToFixedFrame(position, headingPitchRoll, Cesium.Ellipsoid.WGS84, Cesium.Transforms.eastNorthUpToFixedFrame, new Cesium.Matrix4());
10         console.log(m);
11  
12         // 2. 根据矩阵求方位角
13         // 我们就用上面得到的矩阵 m 来做测试
14         // 计算中心处的变换矩阵
15         var m1 = Cesium.Transforms.eastNorthUpToFixedFrame(Cesium.Matrix4.getTranslation(m, new Cesium.Cartesian3()), Cesium.Ellipsoid.WGS84, new Cesium.Matrix4());
16         // 矩阵相除
17         var m3 = Cesium.Matrix4.multiply(Cesium.Matrix4.inverse(m1, new Cesium.Matrix4()), m, new Cesium.Matrix4());
18         // 得到旋转矩阵
19         var mat3 = Cesium.Matrix4.getRotation(m3, new Cesium.Matrix3());
20         // 计算四元数
21         var q = Cesium.Quaternion.fromRotationMatrix(mat3);
22         // 计算旋转角(弧度)
23         var hpr = Cesium.HeadingPitchRoll.fromQuaternion(q);
24         // 得到角度
25         var heading = Cesium.Math.toDegrees(hpr.heading);
26         var pitch = Cesium.Math.toDegrees(hpr.pitch);
27         var roll = Cesium.Math.toDegrees(hpr.roll);
28         console.log('heading : ' + heading, 'pitch : ' + pitch, 'roll : ' + roll);
相关学习群:854184700;有问题可一起讨论。

猜你喜欢

转载自www.cnblogs.com/yaosusu/p/11482282.html