12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- /**
- * @author dmarcos / https://github.com/dmarcos
- * @author mrdoob / http://mrdoob.com
- */
- THREE.VRControls = function ( object, callback ) {
- var scope = this;
- var vrInput;
- var onVRDevices = function ( devices ) {
- for ( var i = 0; i < devices.length; i ++ ) {
- var device = devices[ i ];
- if ( device instanceof PositionSensorVRDevice ) {
- vrInput = devices[ i ];
- return; // We keep the first we encounter
- }
- }
- if ( callback !== undefined ) {
- callback( 'HMD not available' );
- }
- };
- if ( navigator.getVRDevices !== undefined ) {
- navigator.getVRDevices().then( onVRDevices );
- } else if ( callback !== undefined ) {
- callback( 'Your browser is not VR Ready' );
- }
- // the Rift SDK returns the position in meters
- // this scale factor allows the user to define how meters
- // are converted to scene units.
- this.scale = 1;
- this.update = function () {
- if ( vrInput === undefined ) return;
- var state = vrInput.getState();
- if ( state.orientation !== null ) {
- object.quaternion.copy( state.orientation );
- }
- if ( state.position !== null ) {
- object.position.copy( state.position ).multiplyScalar( scope.scale );
- }
- };
- this.zeroSensor = function () {
- if ( vrInput === undefined ) return;
- if ( 'resetSensor' in vrInput) {
- vrInput.resetSensor();
- } else if ( 'zeroSensor' in vrInput) {
- vrInput.zeroSensor();
- }
- };
- };
|