2

TrackballControl 的意图是在轨迹球之外有一个“边界”来引发滚动吗?我个人不喜欢它。它有点不连续,并没有太多目的(恕我直言)。

如果没有,可以更改函数 getMouseProjectionOnBall,如下所示。这做了两件事(不一定“正确”):

  1. 标准化半径以填充两个轴
  2. 映射球外的 z 值(即 z 之前为 0 的位置)

我个人觉得这更自然。

想法?

 this.getMouseProjectionOnBall = function(clientX, clientY)  {
    var xnormalized = (clientX - _this.screen.width * 0.5 - _this.screen.offsetLeft) / (_this.screen.width / 2.0);
    var ynormalized = (_this.screen.height * 0.5 + _this.screen.offsetTop - clientY) / (_this.screen.height / 2.0);
    var mouseOnBall = new THREE.Vector3(
        xnormalized,
        ynormalized,
        0.0
    );

    var length = mouseOnBall.length();

    var ballRadius = 1.0;  // As a fraction of the screen 
    if (length > ballRadius * 0.70710678118654752440) {
        var temp = ballRadius / 1.41421356237309504880;
        mouseOnBall.z = temp * temp / length;

        // Remove old method.
        // This Left z = 0, which meant rotation axis
        // becomes z, which is a roll
        //mouseOnBall.normalize();

    } else {
        mouseOnBall.z = Math.sqrt(1.0 - length * length);
    }

    _eye.copy(_this.object.position).sub(_this.target);

    var projection = _this.object.up.clone().setLength(mouseOnBall.y);
    projection.add(_this.object.up.clone().cross(_eye).setLength(mouseOnBall.x));
    projection.add(_eye.setLength(mouseOnBall.z));

    return projection;

};
4

0 回答 0