OrbitControl or TrackballControl

前端 未结 2 1214
忘掉有多难
忘掉有多难 2020-12-09 11:25

I\'ve read a lot about these 2 controls and currently I\'m using TrackballControls.

I need to rotate an object along all three axis (Both controls already do that),

2条回答
  •  一个人的身影
    2020-12-09 11:59

    To force TrackballControls' to rotates only horizontal, find the implementation of function getMouseProjectionOnBall and add a single line:

    var getMouseProjectionOnBall = (function() {
        var vector = new THREE.Vector3();
        var objectUp = new THREE.Vector3();
        var mouseOnBall = new THREE.Vector3();
    
        return function(pageX, pageY) {
          mouseOnBall.set(
            (pageX - _this.screen.width * 0.5 - _this.screen.left) / (_this.screen.width * 0.5),
            (_this.screen.height * 0.5 + _this.screen.top - pageY) / (_this.screen.height * 0.5),
            0.0);
    
          mouseOnBall.setY(0); // add this
    
          var length = mouseOnBall.length();
    

    I'm still working on limit the angle in a range rather than disabling it...

提交回复
热议问题