为方便计算,y轴改为指向北极方向。

This commit is contained in:
tengge1 2019-04-06 20:15:34 +08:00
parent 9439fcb423
commit 610ce10242
3 changed files with 10 additions and 7 deletions

View File

@ -23,8 +23,6 @@ function Globe(camera, renderer, options) {
this.lat = 0;
this.alt = MathUtils.zoomToAlt(0);
this.rotation.x = - Math.PI / 2;
this.updateMatrix();
this.matrixAutoUpdate = false;
this.layer = new BingTiledLayer();

View File

@ -47,8 +47,8 @@ void main() {
vec3 transformed = vec3(
EARTH_RADIUS * cos(lat) * cos(lon),
EARTH_RADIUS * cos(lat) * sin(lon),
EARTH_RADIUS * sin(lat)
EARTH_RADIUS * sin(lat),
-EARTH_RADIUS * cos(lat) * sin(lon)
);
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(transformed, 1.0);

View File

@ -7,6 +7,11 @@ const MAX_PROJECTED_COORD = 20037508.3427892; // 墨卡托最大投影坐标(
/**
* 经纬度海拔转笛卡尔坐标
* 坐标系
* 原点地心
* x轴经度0纬度0
* y轴指向北极
* z轴西经90纬度0
* @param {THREE.Vector3} lonlat 经纬度弧度海拔
* @param {THREE.Vector3} xyz 笛卡尔坐标
*/
@ -21,8 +26,8 @@ function _lonlatToXYZ(lonlat, xyz) {
return xyz.set(
r * Math.cos(lat) * Math.cos(lon),
r * Math.cos(lat) * Math.sin(lon),
r * Math.sin(lat),
-r * Math.cos(lat) * Math.sin(lon),
);
}
@ -51,8 +56,8 @@ function lonlatToXYZ(lonlat, xyz) {
* @param {THREE.Vector3} lonlat 经纬度弧度海拔
*/
function _xyzToLonlat(xyz, lonlat) {
var lon = Math.atan(xyz.y / Math.sqrt(xyz.x ** 2 + xyz.y ** 2));
var lat = Math.atan(xyz.z / Math.sqrt(xyz.x ** 2 + xyz.y ** 2));
var lon = Math.acos(xyz.x / Math.sqrt(xyz.x ** 2 + xyz.z ** 2));
var lat = Math.atan(xyz.y / Math.sqrt(xyz.x ** 2 + xyz.z ** 2));
var alt = Math.sqrt(xyz.x ** 2 + xyz.y ** 2 + xyz.z ** 2) - WGS84.a;
if (lonlat === undefined) {