提交 9b0c629f 编写于 作者: S Serena Li 提交者: Mr.doob

Can specify alpha offset angle (#8538)

This allows users to specify an offset angle for the alpha value. Can be used to set an initial view direction when the device orientation controls are called.

(Also ran it through whitespace checker)
上级 bacdc87e
......@@ -5,7 +5,7 @@
* W3C Device Orientation control (http://w3c.github.io/deviceorientation/spec-source-orientation.html)
*/
THREE.DeviceOrientationControls = function ( object ) {
THREE.DeviceOrientationControls = function( object ) {
var scope = this;
......@@ -17,13 +17,17 @@ THREE.DeviceOrientationControls = function ( object ) {
this.deviceOrientation = {};
this.screenOrientation = 0;
var onDeviceOrientationChangeEvent = function ( event ) {
this.alpha = 0;
this.alphaOffsetAngle = 0;
var onDeviceOrientationChangeEvent = function( event ) {
scope.deviceOrientation = event;
};
var onScreenOrientationChangeEvent = function () {
var onScreenOrientationChangeEvent = function() {
scope.screenOrientation = window.orientation || 0;
......@@ -31,7 +35,7 @@ THREE.DeviceOrientationControls = function ( object ) {
// The angles alpha, beta and gamma form a set of intrinsic Tait-Bryan angles of type Z-X'-Y''
var setObjectQuaternion = function () {
var setObjectQuaternion = function() {
var zee = new THREE.Vector3( 0, 0, 1 );
......@@ -41,15 +45,15 @@ THREE.DeviceOrientationControls = function ( object ) {
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 ) {
return function( quaternion, alpha, beta, gamma, orient ) {
euler.set( beta, alpha, - gamma, 'YXZ' ); // 'ZXY' for the device, but 'YXZ' for us
euler.set( beta, alpha, - gamma, 'YXZ' ); // 'ZXY' for the device, but 'YXZ' for us
quaternion.setFromEuler( euler ); // orient the device
quaternion.setFromEuler( euler ); // orient the device
quaternion.multiply( q1 ); // camera looks out the back of the device, not the top
quaternion.multiply( q1 ); // camera looks out the back of the device, not the top
quaternion.multiply( q0.setFromAxisAngle( zee, - orient ) ); // adjust for screen orientation
quaternion.multiply( q0.setFromAxisAngle( zee, - orient ) ); // adjust for screen orientation
}
......@@ -75,20 +79,28 @@ THREE.DeviceOrientationControls = function ( object ) {
};
this.update = function () {
this.update = function() {
if ( scope.enabled === false ) return;
var alpha = scope.deviceOrientation.alpha ? THREE.Math.degToRad( scope.deviceOrientation.alpha ) : 0; // Z
var beta = scope.deviceOrientation.beta ? THREE.Math.degToRad( scope.deviceOrientation.beta ) : 0; // X'
var gamma = scope.deviceOrientation.gamma ? THREE.Math.degToRad( scope.deviceOrientation.gamma ) : 0; // Y''
var orient = scope.screenOrientation ? THREE.Math.degToRad( scope.screenOrientation ) : 0; // O
var alpha = scope.deviceOrientation.alpha ? THREE.Math.degToRad( scope.deviceOrientation.alpha ) + this.alphaOffsetAngle : 0; // Z
var beta = scope.deviceOrientation.beta ? THREE.Math.degToRad( scope.deviceOrientation.beta ) : 0; // X'
var gamma = scope.deviceOrientation.gamma ? THREE.Math.degToRad( scope.deviceOrientation.gamma ) : 0; // Y''
var orient = scope.screenOrientation ? THREE.Math.degToRad( scope.screenOrientation ) : 0; // O
setObjectQuaternion( scope.object.quaternion, alpha, beta, gamma, orient );
this.alpha = alpha;
};
this.updateAlphaOffsetAngle = function( angle ) {
this.alphaOffsetAngle = angle;
this.update();
};
this.dispose = function () {
this.dispose = function() {
this.disconnect();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册