Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

THREE.VRController.onGamepadDisconnect needs to be called when contro… #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions VRController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/**
* @author Stewart Smith / http://stewartsmith.io
* @author Moar Technologies Corp / https://moar.io
* @author Jeff Nusz / http://custom-logic.com
Expand Down Expand Up @@ -661,7 +661,7 @@ THREE.VRController.verbosity = 0//0.5 or 0.7 are good...
// and have some connection / disconnection handlers.

THREE.VRController.controllers = []
THREE.VRController.onGamepadConnect = function( gamepad ){
THREE.VRController.onGamepadConnect = function( gamepad, index ){


// Let’s create a new controller object
Expand All @@ -675,10 +675,10 @@ THREE.VRController.onGamepadConnect = function( gamepad ){


// We also need to store this reference somewhere so that we have a list
// controllers that we know need updating, and by using the gamepad.index
// controllers that we know need updating, and by using the index
// as the key we also know which gamepads have already been found.

scope.controllers[ gamepad.index ] = controller
scope.controllers[ index ] = controller


// Now we’ll broadcast a global connection event.
Expand All @@ -695,7 +695,7 @@ THREE.VRController.onGamepadConnect = function( gamepad ){

}, 500 )
}
THREE.VRController.onGamepadDisconnect = function( gamepad ){
THREE.VRController.onGamepadDisconnect = function( index ){


// We need to find the controller that holds the reference to this gamepad.
Expand All @@ -707,11 +707,11 @@ THREE.VRController.onGamepadDisconnect = function( gamepad ){

var
scope = THREE.VRController,
controller = scope.controllers[ gamepad.index ]
controller = scope.controllers[ index ]

if( scope.verbosity >= 0.5 ) console.log( 'vr controller disconnected', controller )
controller.dispatchEvent({ type: 'disconnected', controller: controller })
scope.controllers[ gamepad.index ] = undefined
scope.controllers[ index ] = undefined
}


Expand Down Expand Up @@ -780,7 +780,7 @@ THREE.VRController.update = function(){

if( gamepad.pose.orientation !== null || gamepad.pose.position !== null ){

if( this.controllers[ i ] === undefined ) THREE.VRController.onGamepadConnect( gamepad )
if( this.controllers[ i ] === undefined ) THREE.VRController.onGamepadConnect( gamepad, i )
this.controllers[ i ].update()
}

Expand All @@ -791,8 +791,10 @@ THREE.VRController.update = function(){
// the controller! (At least in Chromium.) That doesn’t seem like
// the API’s intended behavior but it’s what I see in practice.

else if( this.controllers[ i ] !== undefined ) THREE.VRController.onGamepadDisconnect( gamepad )
else if( this.controllers[ i ] !== undefined ) THREE.VRController.onGamepadDisconnect( i )
}
// If the controller is disconnected and remove then we should update this.controllers accordingly
else if( this.controllers[ i ] !== undefined ) THREE.VRController.onGamepadDisconnect( i );
}
}
THREE.VRController.inspect = function(){
Expand Down Expand Up @@ -1473,4 +1475,4 @@ OrientationArmModel.prototype.quatAngle_ = function( q1, q2 ){
vec1.applyQuaternion( q1 );
vec2.applyQuaternion( q2 );
return vec1.angleTo( vec2 );
}
}