2

我正在使用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 行。

4

1 回答 1

0

看起来您已经找到了解决方案?这对我有用,也许你想用一个大约 1 而不是 Pi/2 的值来限制旋转更多

target.y = target.y > 1 ? 1 : target.y;
target.y = target.y < - 1 ? - 1 : target.y;
于 2015-06-09T10:56:30.620 回答