PageSourceSearch

https://spotlight-timisoara.eu/wp-content/plugins/360-viewer/data/…/js/DeviceOrientationControls.js?ver=1.4.5

js spotlight-timisoara.eu collected 2026-09-24 10:16:34 UTC 2,648 bytes, 111 lines download raw bytes

1/**
2 * @author richt / http://richt.me
3 * @author WestLangley / http://github.com/WestLangley
4 *
5 * W3C Device Orientation control (http://w3c.github.io/deviceorientation/spec-source-orientation.html)
6 */
7
8THREE.DeviceOrientationControls = function ( object ) {
9
10	var scope = this;
11
12	this.object = object;
13	this.object.rotation.reorder( 'YXZ' );
14
15	this.enabled = true;
16
17	this.deviceOrientation = {};
18	this.screenOrientation = 0;
19
20	this.alphaOffset = 0; // radians
21
22	var onDeviceOrientationChangeEvent = function ( event ) {
23
24		scope.deviceOrientation = event;
25
26	};
27
28	var onScreenOrientationChangeEvent = function () {
29
30		scope.screenOrientation = window.orientation || 0;
31
32	};
33
34	// The angles alpha, beta and gamma form a set of intrinsic Tait-Bryan angles of type Z-X'-Y''
35
36	var setObjectQuaternion = function () {
37
38		var zee = new THREE.Vector3( 0, 0, 1 );
39
40		var euler = new THREE.Euler();
41
42		var q0 = new THREE.Quaternion();
43
44		var q1 = new THREE.Quaternion( - Math.sqrt( 0.5 ), 0, 0, Math.sqrt( 0.5 ) ); // - PI/2 around the x-axis
45
46		return function ( quaternion, alpha, beta, gamma, orient ) {
47
48			euler.set( beta, alpha, - gamma, 'YXZ' ); // 'ZXY' for the device, but 'YXZ' for us
49
50			quaternion.setFromEuler( euler ); // orient the device
51
52			quaternion.multiply( q1 ); // camera looks out the back of the device, not the top
53
54			quaternion.multiply( q0.setFromAxisAngle( zee, - orient ) ); // adjust for screen orientation
55
56		};
57
58	}();
59
60	this.connect = function () {
61
62		onScreenOrientationChangeEvent(); // run once on load
63
64		window.addEventListener( 'orientationchange', onScreenOrientationChangeEvent, false );
65		window.addEventListener( 'deviceorientation', onDeviceOrientationChangeEvent, false );
66
67		scope.enabled = true;
68
69	};
70
71	this.disconnect = function () {
72
73		window.removeEventListener( 'orientationchange', onScreenOrientationChangeEvent, false );
74		window.removeEventListener( 'deviceorientation', onDeviceOrientationChangeEvent, false );
75
76		scope.enabled = false;
77
78	};
79
80	this.update = function () {
81
82		if ( scope.enabled === false ) return;
83
84		var device = scope.deviceOrientation;
85
86		if ( device ) {
87
88			var alpha = device.alpha ? THREE.Math.degToRad( device.alpha ) + scope.alphaOffset : 0; // Z
89
90			var beta = device.beta ? THREE.Math.degToRad( device.beta ) : 0; // X'
91
92			var gamma = device.gamma ? THREE.Math.degToRad( device.gamma ) : 0; // Y''
93
94			var orient = scope.screenOrientation ? THREE.Math.degToRad( scope.screenOrientation ) : 0; // O
95
96			setObjectQuaternion( scope.object.quaternion, alpha, beta, gamma, orient );
97
98		}
99
100
101	};
102
103	this.dispose = function () {
104
105		scope.disconnect();
106
107	};
108
109	this.connect();
110
111};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.