在轨迹球控件中消除无球滚动(带代码/修复)

时间:2013-04-25 12:56:20

标签: three.js

TrackballControl的目的是在轨迹球外面有一个“边界”,导致滚动吗?我个人不喜欢它。它有点不连续,并没有太多的目的(imho)。

如果没有,可以改变函数getMouseProjectionOnBall,类似于以下内容。这样做有两件事(不一定“正确”):

  1. 将半径标准化以填充两个轴
  2. 将z值映射到球外(即z之前为0)
  3. 我个人认为这更自然。

    思想?

     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;
    
    };
    

0 个答案:

没有答案