如何在进入VR时重置摄像机位置? [英] how to reset camera position on enter VR?

查看:900
本文介绍了如何在进入VR时重置摄像机位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户单击A帧场景中的Enter VR按钮时,如何重置摄像头位置?

How can I reset the camera position when the user clicks the enter VR button in an A-Frame scene?

我为台式机设置了一个不错的摄像头位置 wasd-controls 用户,但想重置位置旋转当Vive用户进入VR时。

I set a nice camera position for desktop wasd-controls users, but want to reset the position and rotation when a Vive user enters VR.

我按照此答案初始设置相机:

  <!-- Player -->
  <a-entity id='cameraWrapper' position='1 1.8034 1' rotation='-35 40 0'>
    <a-entity camera look-controls wasd-controls="fly: true"></a-entity>
  </a-entity>

在这里,我尝试重置位置旋转 window.onvrdisplaypresentchange 事件:

and here I attempt to reset the position and rotation with the window.onvrdisplaypresentchange event from the WebVR API:

      //
      // if a VR display (like the Vive headset begins presenting
      // (if the scene goes into VR mode)
      // reset the camera position and rotation
      //
      window.onvrdisplaypresentchange = function() {
        d3.select('#cameraWrapper')
          .attr('position', '0 0 0')
          .attr('rotation', '0 0 0');
      }

这是一个[代码沙箱演示],它再现了问题状态(< a href = http://blockbuilder.org/micahstubbs/94e06c2849b6c7c60105d0243bc1936a#mode=sidebyside rel = nofollow noreferrer> http://blockbuilder.org/micahstubbs/94e06c2849b6c7c60105d0243 bc1936a#mode = sidebyside )

here's a [code sandbox demo] that reproduces the problem state (http://blockbuilder.org/micahstubbs/94e06c2849b6c7c60105d0243bc1936a#mode=sidebyside)

我正在使用 A帧主控 8月29日实验版的Chromium,使用-enable-webvr -enable-gamepad -extensions 标志已启用。

I'm developing this scene with A-Frame Master and the Aug 29 experimental build of Chromium with the --enable-webvr and --enable-gamepad-extensions flags enabled.

编辑:我真正想做的是还重置摄像机的位置x,z 旋转x,y,z 到Vive hmd的值,除了重置位置y (这就是 camera = userHeight:1.6 为我们所做的事情)

edit: what I really want to do is also reset the camera's position x,z and rotation x,y,z to the Vive hmd's values, in addition to resetting position y (which is what camera="userHeight: 1.6" does for us)

推荐答案

使用 camera.userHeight 设置非VR高度。

< a-entity camera = userHeight:1.6>

非VR摄像机的高度为1.6m。在VR中,此高度将被删除。当退出VR时,将重新应用1.6m的高度。

The camera in non-VR will be 1.6m high. In VR, this height will be removed. When going back out of VR, the 1.6m height will be re-applied.

https://aframe.io/docs/0.4.0/components/camera.html#vr-行为

< a-camera> 和默认相机默认情况下具有此功能。

The <a-camera> and default cameras have this by default.

这篇关于如何在进入VR时重置摄像机位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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