在A-Frame中:如何获得VR摄像机 [英] In A-Frame: How do I get the VR camera

查看:115
本文介绍了在A-Frame中:如何获得VR摄像机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此示例中:
https://glitch.com/~query-aframe-cameras 我已经注册了一个组件,该组件可以按照用户所看的方向发射弹丸(略微提升仰角)

In this example:
https://glitch.com/~query-aframe-cameras I have registered a component which launches a projectile in the direction the user is looking (with a little boost for elevation)

空格键 Screen Tap 启动-一定要在地平线上方看!

Spacebar or Screen Tap to launch - be sure to be looking above the horizon!

在移动VR(立体摄像机)模式下失败:
弹丸继续发射,但从单声道的默认方向开始,而不是立体相机

It fails in mobile vr (stereo camera) mode:
Projectiles continue to fire, but from the default orientation of the mono, not the stereo camera

我正在使用:
var cam = document.querySelector('a-scene').camera.el.object3D;var camVec = new THREE.Vector3();var camDir = cam.getWorldDirection(camVec); 获取相机信息并将弹丸吐回去

I'm using:
var cam = document.querySelector('a-scene').camera.el.object3D; var camVec = new THREE.Vector3(); var camDir = cam.getWorldDirection(camVec); to get the camera information and spit the projectiles back

查询:我如何获得立体声相机信息

QUERY: HOW DO I GET THE STEREO CAMERA INFORMATION

推荐答案

问题将归因于THREE.js中的此错误.

The problem will be due to this bug in THREE.js.

https://github.com/mrdoob/three.js/issues/18448

按照已记录的解决方法,此处的代码可以在我的Quest 2上进行正确的方向跟踪.

Following the documented workaround, the code here works with correct direction tracking on my Quest 2.

https://cuddly-endurable-soap.glitch.me

(这里还有其他几处更改:要在我的VR头戴式耳机上进行测试,我还必须升级到A-Frame 1.1.0,并使代码在计时器上启动,因为我没有使用时按下的任何键都不能解决问题,但是).

(there's a couple of other changes in here: to test this on my VR headset I also had to upgrade to A-Frame 1.1.0, and make the code fire the balls on a timer, since I don't have any keys to press when using it! Neither of these was enough to fix the problem, though).

此代码将根据需要设置CamDir.

This code will set up CamDir as you need it.

var camQ = new THREE.Quaternion();
cam.updateMatrixWorld();
camQ.setFromRotationMatrix(cam.matrixWorld);
var camDir = new THREE.Vector3(0, 0, 1);
camDir.applyQuaternion(camQ);

以下代码也可以工作(并且效率更高),但是不太容易理解.

The following code also works (and is more efficient), but is less easy to understand.

var camDir = new THREE.Vector3();
var e = cam.matrixWorld.elements;
camDir.set(e[ 8 ], e[ 9 ], e[ 10 ]).normalize();

我是从这里捡起来的: https://lace-fern-ghost.glitch.me/

I picked it up from here: https://lace-fern-ghost.glitch.me/

我从这里找到了一个链接: https://github.com/aframevr/aframe/issues/4412

Which I found a link to from here: https://github.com/aframevr/aframe/issues/4412

(但我找不到任何参考来解释为什么这些组件matrixWorld.elements是在此处用于指示方向的正确组件).

(but I can't find any reference to explain why these components matrixWorld.elements are the right ones to use here to get the direction).

这篇关于在A-Frame中:如何获得VR摄像机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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