How can I reset the camera position when the user clicks the enter VR button in an A-Frame scene?
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.
I followed the pattern of this answer to setup the camera initially:
<!-- 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>
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');
}
here's a [code sandbox demo] that reproduces the problem state (http://blockbuilder.org/micahstubbs/94e06c2849b6c7c60105d0243bc1936a#mode=sidebyside)
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.
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)
Use camera.userHeight
to set a non-VR height.
<a-entity camera="userHeight: 1.6">
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-behavior
The <a-camera>
and default cameras have this by default.
来源:https://stackoverflow.com/questions/41624558/how-to-reset-camera-position-on-enter-vr