1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- /**
- * @author dmarcos / https://github.com/dmarcos
- * @author mrdoob / http://mrdoob.com
- */
- THREE.VRControls = function ( object, callback ) {
- var scope = this;
- // Allow for multiple VR input devices.
- var vrInputs = [];
- var onVRDevices = function ( devices ) {
- for ( var i = 0; i < devices.length; i ++ ) {
- var device = devices[ i ];
- if ( device instanceof PositionSensorVRDevice ) {
- vrInputs.push( devices[ i ] );
- }
- }
- 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 () {
- for ( var i = 0; i < vrInputs.length; i++ ) {
- var vrInput = vrInputs[ i ];
- 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 () {
- for ( var i = 0; i < vrInputs.length; i++ ) {
- var vrInput = vrInputs[ i ];
- vrInput.zeroSensor();
- }
- };
- };
|