Skip to content

Commit

Permalink
Improve the way the controller can be manually rotated so it turns in…
Browse files Browse the repository at this point in the history
… the direction the mouse is being dragged
  • Loading branch information
richtr committed Jul 14, 2015
1 parent 58564cb commit 3edf88b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions controller/js/DeviceOrientationEmulatorControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,6 @@ var DeviceOrientationEmulatorControls = function( object, domElement ) {

return function() {

objQuat.copy( tmpQuat );

if ( appState === CONTROLLER_STATE.MANUAL_ROTATE ) {

lat = ( startY - currentY ) * scrollSpeedY;
Expand All @@ -225,14 +223,20 @@ var DeviceOrientationEmulatorControls = function( object, domElement ) {
phi = THREE.Math.degToRad( lat );
theta = THREE.Math.degToRad( lon );

// Apply y-based quaternion rotation
// Reset objQuat
objQuat.set(0,0,0,1);

// Apply y-based mouse rotation
rotQuat.set( 0, Math.sin( theta / 2 ), 0, Math.cos( theta / 2 ) );
objQuat.multiply( rotQuat );

// Apply z-based quaternion rotation
// Apply z-based mouse rotation
rotQuat.set( Math.sin( phi / 2 ), 0, 0, Math.cos( phi / 2 ) );
objQuat.multiply( rotQuat );

// Apply existing object rotation to calculated mouse rotation
objQuat.multiply( tmpQuat );

this.object.quaternion.copy( objQuat );

} else if ( appState === CONTROLLER_STATE.MANUAL_ZOOM ) {
Expand Down

0 comments on commit 3edf88b

Please sign in to comment.