mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-04 10:19:24 +02:00
This commit is contained in:
parent
f0f62670c5
commit
7e26256cac
4563 changed files with 1246712 additions and 17558 deletions
149
node_modules/three/examples/js/controls/DeviceOrientationControls.js
generated
vendored
Normal file
149
node_modules/three/examples/js/controls/DeviceOrientationControls.js
generated
vendored
Normal file
|
@ -0,0 +1,149 @@
|
|||
/**
|
||||
* W3C Device Orientation control (http://w3c.github.io/deviceorientation/spec-source-orientation.html)
|
||||
*/
|
||||
|
||||
THREE.DeviceOrientationControls = function ( object ) {
|
||||
|
||||
var scope = this;
|
||||
var changeEvent = { type: 'change' };
|
||||
var EPS = 0.000001;
|
||||
|
||||
this.object = object;
|
||||
this.object.rotation.reorder( 'YXZ' );
|
||||
|
||||
this.enabled = true;
|
||||
|
||||
this.deviceOrientation = {};
|
||||
this.screenOrientation = 0;
|
||||
|
||||
this.alphaOffset = 0; // radians
|
||||
|
||||
var onDeviceOrientationChangeEvent = function ( event ) {
|
||||
|
||||
scope.deviceOrientation = event;
|
||||
|
||||
};
|
||||
|
||||
var onScreenOrientationChangeEvent = function () {
|
||||
|
||||
scope.screenOrientation = window.orientation || 0;
|
||||
|
||||
};
|
||||
|
||||
// The angles alpha, beta and gamma form a set of intrinsic Tait-Bryan angles of type Z-X'-Y''
|
||||
|
||||
var setObjectQuaternion = function () {
|
||||
|
||||
var zee = new THREE.Vector3( 0, 0, 1 );
|
||||
|
||||
var euler = new THREE.Euler();
|
||||
|
||||
var q0 = new THREE.Quaternion();
|
||||
|
||||
var q1 = new THREE.Quaternion( - Math.sqrt( 0.5 ), 0, 0, Math.sqrt( 0.5 ) ); // - PI/2 around the x-axis
|
||||
|
||||
return function ( quaternion, alpha, beta, gamma, orient ) {
|
||||
|
||||
euler.set( beta, alpha, - gamma, 'YXZ' ); // 'ZXY' for the device, but 'YXZ' for us
|
||||
|
||||
quaternion.setFromEuler( euler ); // orient the device
|
||||
|
||||
quaternion.multiply( q1 ); // camera looks out the back of the device, not the top
|
||||
|
||||
quaternion.multiply( q0.setFromAxisAngle( zee, - orient ) ); // adjust for screen orientation
|
||||
|
||||
};
|
||||
|
||||
}();
|
||||
|
||||
this.connect = function () {
|
||||
|
||||
onScreenOrientationChangeEvent(); // run once on load
|
||||
|
||||
// iOS 13+
|
||||
|
||||
if ( window.DeviceOrientationEvent !== undefined && typeof window.DeviceOrientationEvent.requestPermission === 'function' ) {
|
||||
|
||||
window.DeviceOrientationEvent.requestPermission().then( function ( response ) {
|
||||
|
||||
if ( response == 'granted' ) {
|
||||
|
||||
window.addEventListener( 'orientationchange', onScreenOrientationChangeEvent );
|
||||
window.addEventListener( 'deviceorientation', onDeviceOrientationChangeEvent );
|
||||
|
||||
}
|
||||
|
||||
} ).catch( function ( error ) {
|
||||
|
||||
console.error( 'THREE.DeviceOrientationControls: Unable to use DeviceOrientation API:', error );
|
||||
|
||||
} );
|
||||
|
||||
} else {
|
||||
|
||||
window.addEventListener( 'orientationchange', onScreenOrientationChangeEvent );
|
||||
window.addEventListener( 'deviceorientation', onDeviceOrientationChangeEvent );
|
||||
|
||||
}
|
||||
|
||||
scope.enabled = true;
|
||||
|
||||
};
|
||||
|
||||
this.disconnect = function () {
|
||||
|
||||
window.removeEventListener( 'orientationchange', onScreenOrientationChangeEvent );
|
||||
window.removeEventListener( 'deviceorientation', onDeviceOrientationChangeEvent );
|
||||
|
||||
scope.enabled = false;
|
||||
|
||||
};
|
||||
|
||||
this.update = ( function () {
|
||||
|
||||
var lastQuaternion = new THREE.Quaternion();
|
||||
|
||||
return function () {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
var device = scope.deviceOrientation;
|
||||
|
||||
if ( device ) {
|
||||
|
||||
var alpha = device.alpha ? THREE.MathUtils.degToRad( device.alpha ) + scope.alphaOffset : 0; // Z
|
||||
|
||||
var beta = device.beta ? THREE.MathUtils.degToRad( device.beta ) : 0; // X'
|
||||
|
||||
var gamma = device.gamma ? THREE.MathUtils.degToRad( device.gamma ) : 0; // Y''
|
||||
|
||||
var orient = scope.screenOrientation ? THREE.MathUtils.degToRad( scope.screenOrientation ) : 0; // O
|
||||
|
||||
setObjectQuaternion( scope.object.quaternion, alpha, beta, gamma, orient );
|
||||
|
||||
if ( 8 * ( 1 - lastQuaternion.dot( scope.object.quaternion ) ) > EPS ) {
|
||||
|
||||
lastQuaternion.copy( scope.object.quaternion );
|
||||
scope.dispatchEvent( changeEvent );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
} )();
|
||||
|
||||
this.dispose = function () {
|
||||
|
||||
scope.disconnect();
|
||||
|
||||
};
|
||||
|
||||
this.connect();
|
||||
|
||||
};
|
||||
|
||||
THREE.DeviceOrientationControls.prototype = Object.create( THREE.EventDispatcher.prototype );
|
||||
THREE.DeviceOrientationControls.prototype.constructor = THREE.DeviceOrientationControls;
|
Loading…
Add table
Add a link
Reference in a new issue