使用VRControl时无法更改相机位置 [英] Unable to change camera position when using VRControls

查看:109
本文介绍了使用VRControl时无法更改相机位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

...
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之前它工作得很好。

VRControls are working in sync with the accelerometer, but I can't change the cameras position. It seems stuck in the origin point (0,0,0). It was working just fine before applying VRControls and VREffect.

推荐答案

Mozilla VR团队演示。我将这里放一个代码片段作为其他VR初学者的参考。

Found the solution inside Sechelt demo from Mozilla VR Team demos. I'll put here a code snippet as reference for other VR beginners.

将摄像机添加到一个组而不是直接更新摄像机位置是移动摄像机的方法。

Adding the camera to a group instead of updating the camera position directly is the way to move the camera.

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();

这篇关于使用VRControl时无法更改相机位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆