Adr*_*isa 5 javascript three.js virtual-reality
我有以下代码:
...
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 );
...
Run Code Online (Sandbox Code Playgroud)
VRControls 与加速计同步工作,但我无法更改摄像机位置。它似乎卡在原点 (0,0,0) 处。在应用 VRControls 和 VREffect 之前它工作得很好。
在Mozilla VR Team 演示的 Sechelt 演示中找到了解决方案。我将在这里放一个代码片段作为其他 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();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1548 次 |
| 最近记录: |