Handling camera in VR

camera
webvr

#1

How to reset the camera back to its initial position when it’s coming out of the WebVR mode.

Note : “I am using WebVR.js”


#2

You might want to add an event listener to vrdisplaypresentchange. Something like…

window.addEventListener( 'vrdisplaypresentchange', () =>  {

  const device = renderer.vr.getDevice();

  if ( device && device.isPresenting === false ) {

    // reset your camera   

  }

} );

#3

Hi, thanks for your response.

I added event “vrdisplaypresentchange” , but camera is not resetting its original position.

window.addEventListener( 'vrdisplaypresentchange', function ( event ) {

	var str = event.display.isPresenting ? 'EXIT VR' : 'ENTER VR';
	_device = event.display;
	if(event.display.isPresenting){
		cameOut = true;
		camera.position.z = 0;
		camera.position.y = 0;
		camera.position.x = 0;
		camera.rotation.x = 0;
		camera.rotation.y = 0;
		camera.rotation.z = 0;
		
		camera.lookAt( scene.position );
		renderer.setSize( window.innerWidth, window.innerHeight )
	}

}, false );		

Can u check the code, please tell me what went wrong.

Thanks


#4

I guess you have to change:

if ( event.display.isPresenting ) {

to

if ( event.display.isPresenting === false ) {

You want to reset the camera if the device is not presenting.