2017-04-06 44 views
0

有沒有什麼方法可以讓相機在銫3D視圖中查看地球的另一半?銫 - 在3D視圖中將相機飛向地球的另一半

+0

你能更具體?您在相機飛行部分遇到問題嗎?或確定要飛往的位置? – Zac

+0

這個銫sandcastle顯示如何使用flyTo - http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Camera.html&label=Showcases操縱相機位置 – Zac

回答

1

我認爲你正在做這樣的事情。
1 - 獲取當前位置
2 - 計算目標
3 - flyTo()目標

現場演示:http://cesiumjs.org/Cesium/Apps/Sandcastle/?src=Hello%20World.html&label=Showcases&gist=4c6e1b30ae619b8e5cba621f4f12f59d

var viewer = new Cesium.Viewer('cesiumContainer'); 
var scene = viewer.scene; 

var btn = document.getElementById('swap'); 
btn.addEventListener('click', goToOtherSide); 

function goToOtherSide() { 
    // Get the position of the camera 
    var currentPosition = getPosition(); 

    // Get the position on the other side of the earth 
    var nextPosition = getOtherSide(currentPosition); 

    // Use flyTo with the new position, and maintain the height 
    viewer.camera.flyTo({ 
     destination : Cesium.Cartesian3.fromDegrees(+nextPosition.lon, +nextPosition.lat, viewer.camera.positionCartographic.height) 
    }); 
} 

function getPosition() { 
    var center = viewer.camera.pickEllipsoid(
     new Cesium.Cartesian2(viewer.canvas.width/2, viewer.canvas.height/2), Cesium.Ellipsoid.WGS84); 
    var cartographic = scene.globe.ellipsoid.cartesianToCartographic(center); 
    var lat = Cesium.Math.toDegrees(cartographic.latitude).toFixed(2); 
    var lon = Cesium.Math.toDegrees(cartographic.longitude).toFixed(2); 
    return { 
     lat: lat, 
     lon: lon 
    }; 
} 

function getOtherSide(currentPosition) { 
    var ln = +currentPosition.lon + 180; 
    if (ln > 180) { 
     ln -= 360; 
    } 

    var lt = -currentPosition.lat; 

    return { 
     lat: lt, 
     lon: ln 
    }; 
} 
相關問題