【问题标题】:camera angle movement control enable and disable in three js?三个js中的摄像机角度移动控制启用和禁用?
【发布时间】:2018-03-31 09:21:30
【问题描述】:

我使用了轨道控制。我创建了 2 个按钮 enabledisablecontrols.rotate=false 这不起作用。在我的代码下面。我犯了什么错误?

camera3D = new THREE.PerspectiveCamera(angle, width / height, near, far);
        camera3D.position.set(0, 10, 500);

        controls = new THREE.OrbitControls( camera3D, renderer3D.domElement );
        controls.rotateSpeed = 0.50;
        controls.zoomSpeed = 1.2;

this.disableMode = function(){
            console.log('disable work');
            controls.enabled = false;
            controls.rotate = false;
            controls.update();

        }

【问题讨论】:

  • 我猜应该是controls.enableRotate = false;
  • controls.enableRotate = false; 这也不是禁用模式。旋转我的相机角度@Mugen87
  • 你使用的是最新版的three.jsOrbitControls吗?
  • 是的,我认为是最新版本。
  • 你能用这个小提琴证明这个问题吗:jsfiddle.net/f2Lommf5/4062。我已经为你添加了OrbitControls

标签: javascript canvas three.js


【解决方案1】:

您需要做的就是将 minPolarAngle 和 maxPolarAngle 设置为相同的值。

试试这个:

var controls = new THREE.OrbitControls(camera, DOMElement);

// controls.addEventListener( 'change', render ); // call this only in static scenes 
// (i.e., if there is no animation loop)

controls.enableDamping = true; 
// an animation loop is required when either damping or auto-rotation are enabled

controls.dampingFactor = 0.05;
controls.screenSpacePanning = true;
controls.minDistance = 22;
controls.maxDistance = 115;

// Angle in radians

// this can be used to fix your problem.
// Just setup to 0 or any other angle you needed...
// Must bve same value `minPolarAngle` and `maxPolarAngle`.

controls.minPolarAngle = 0; // 1.5 * Math.PI / 12; 
controls.maxPolarAngle = 0; // 1.5 * Math.PI / 3;

controls.minAzimuthAngle = - Math.PI / 2;
controls.maxAzimuthAngle = - Math.PI / 2;

controls.target.set(1, 4, -8.5); 

【讨论】:

    猜你喜欢
    • 2013-02-19
    • 2021-09-23
    • 1970-01-01
    • 2021-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多