使用 VRControls 时无法更改相机位置

编程入门 行业动态 更新时间:2024-10-25 02:26:44
本文介绍了使用 VRControls 时无法更改相机位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

...
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.

推荐答案

从 在 Sechelt 演示中找到了解决方案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();

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

更多推荐

[db:关键词]

本文发布于:2023-03-28 15:40:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/733739.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:位置   相机   VRControls

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!