我正在使用THREE.js WebGL 地球仪,并希望删除阻止您将地球仪倒置旋转的约束:北极向下,反之亦然。
这是我目前的实验:https ://mgiraldo.github.io/edda-globe
我尝试修改onMouseMove
函数(这是我认为问题所在),但我的几何数学是有限的。功能:
function onMouseMove(event) {
if (event.type!="touchmove") {
mouse.x = - event.clientX;
mouse.y = event.clientY;
} else {
mouse.x = - event.touches[0].clientX;
mouse.y = event.touches[0].clientY;
}
var zoomDamp = distance/1000;
target.x = targetOnDown.x + (mouse.x - mouseOnDown.x) * 0.005 * zoomDamp;
target.y = targetOnDown.y + (mouse.y - mouseOnDown.y) * 0.005 * zoomDamp;
target.y = target.y > PI_HALF ? PI_HALF : target.y;
target.y = target.y < - PI_HALF ? - PI_HALF : target.y;
}
我认为问题恰恰在于以下几点:
target.y = target.y > PI_HALF ? PI_HALF : target.y;
target.y = target.y < - PI_HALF ? - PI_HALF : target.y;
完整代码在这里:https ://github.com/mgiraldo/edda-globe/blob/gh-pages/globe/globe.js#L321-338
编辑:创建了一个Codepen 以便于测试。onMouseMove
在第 318-334 行。