【问题标题】:Unable to change camera position when using VRControls使用 VRControls 时无法更改相机位置
【发布时间】:2015-12-26 09:58:49
【问题描述】:

我有以下代码:

...
camera = new THREE.PerspectiveCamera(75, screenRatio, 1, 10000 );
camera.position.z = -10; // position.set(0, 0, -10) also not working.
controls = new THREE.VRControls( camera );
effect = new THREE.VREffect( renderer );
effect.setSize( window.innerWidth, window.innerHeight );
...

VRControls 与加速度计同步工作,但我无法更改摄像机位置。它似乎卡在原点(0,0,0)。在应用 VRControls 和 VREffect 之前它工作得很好。

【问题讨论】:

    标签: javascript three.js virtual-reality


    【解决方案1】:

    Mozilla VR Team demos 的 Sechelt 演示中找到了解决方案。我这里放一个代码 sn-p 供其他 VR 初学者参考。

    将相机添加到组中而不是直接更新相机位置是移动相机的方式。

    var scene, renderer, cameraRatio, camera, controls, effect, dolly;
    
    function init() {
        scene = new THREE.Scene();
    
        renderer = new THREE.WebGLRenderer({ antialias: true });
        renderer.setSize( window.innerWidth, window.innerHeight );
        document.body.appendChild( renderer.domElement );
    
        cameraRatio = window.innerWidth / window.innerHeight;
        camera = new THREE.PerspectiveCamera( 75, cameraRatio, 1, 1000 );       
    
        controls = new THREE.VRControls( camera );
        effect = new THREE.VREffect( renderer );
        effect.setSize( window.innerWidth, window.innerHeight );
    
        // This helps move the camera
        dolly = new THREE.Group();
        dolly.position.set( 0, 0, 0 );
        scene.add( dolly );
        dolly.add( camera );
    
        ...
        // Of course, there should be lights, objects, etc
    }
    
    function animate() {
        dolly.position.x += 0.1;
        controls.update();
        effect.render( scene, camera );
    }
    
    init();
    animate();
    

    【讨论】:

    • 我不知道为什么需要小车组来改变相机的位置。 VRControls 是否总是将相机位置覆盖到原点?
    【解决方案2】:

    我认为相机现在是object。你可以试试object.position.set()

    【讨论】:

    • 出于某种原因,这在 VR 模式下似乎不起作用。
    猜你喜欢
    • 1970-01-01
    • 2014-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-13
    • 1970-01-01
    • 2021-02-01
    相关资源
    最近更新 更多