Skip to content

Commit

Permalink
Merge pull request #3270 from BabylonJS/davrous
Browse files Browse the repository at this point in the history
Better gaze & interaction
  • Loading branch information
davrous committed Nov 30, 2017
2 parents b59510e + b83526f commit 875f2d3
Showing 1 changed file with 69 additions and 42 deletions.
111 changes: 69 additions & 42 deletions src/Cameras/VR/babylon.vrExperienceHelper.ts
Expand Up @@ -458,58 +458,78 @@ module BABYLON {
}

private _onNewGamepadConnected(gamepad: Gamepad) {
if (gamepad.leftStick && gamepad.type !== BABYLON.Gamepad.POSE_ENABLED) {
gamepad.onleftstickchanged((stickValues) => {
// Listening to classic/xbox gamepad only if no VR controller is active
if ((!this._leftLaserPointer && !this._rightLaserPointer) ||
((this._leftLaserPointer && !this._leftLaserPointer.isVisible) &&
(this._rightLaserPointer && !this._rightLaserPointer.isVisible))) {
if (!this._teleportationRequestInitiated) {
if (stickValues.y < -this._padSensibilityUp) {
this._teleportationRequestInitiated = true;
if (gamepad.type !== BABYLON.Gamepad.POSE_ENABLED) {
if (gamepad.leftStick) {
gamepad.onleftstickchanged((stickValues) => {
// Listening to classic/xbox gamepad only if no VR controller is active
if ((!this._leftLaserPointer && !this._rightLaserPointer) ||
((this._leftLaserPointer && !this._leftLaserPointer.isVisible) &&
(this._rightLaserPointer && !this._rightLaserPointer.isVisible))) {
if (!this._teleportationRequestInitiated) {
if (stickValues.y < -this._padSensibilityUp) {
this._teleportationRequestInitiated = true;
}
}
else {
if (stickValues.y > -this._padSensibilityDown) {
if (this._teleportationAllowed) {
this._teleportCamera();
}
this._teleportationRequestInitiated = false;
}
}
}
else {
if (stickValues.y > -this._padSensibilityDown) {
if (this._teleportationAllowed) {
this._teleportCamera();
});
}
if (gamepad.rightStick) {
gamepad.onrightstickchanged((stickValues) => {
if (!this._rotationLeftAsked) {
if (stickValues.x < -this._padSensibilityUp) {
this._rotationLeftAsked = true;
if (this._rotationAllowed) {
this._rotateCamera(false);
}
this._teleportationRequestInitiated = false;
}
}
}
});
}
if (gamepad.rightStick) {
gamepad.onrightstickchanged((stickValues) => {
if (!this._rotationLeftAsked) {
if (stickValues.x < -this._padSensibilityUp) {
this._rotationLeftAsked = true;
if (this._rotationAllowed) {
this._rotateCamera(false);
else {
if (stickValues.x > -this._padSensibilityDown) {
this._rotationLeftAsked = false;
}
}
}
else {
if (stickValues.x > -this._padSensibilityDown) {
this._rotationLeftAsked = false;

if (!this._rotationRightAsked) {
if (stickValues.x > this._padSensibilityUp) {
this._rotationRightAsked = true;
if (this._rotationAllowed) {
this._rotateCamera(true);
}
}
}
}

if (!this._rotationRightAsked) {
if (stickValues.x > this._padSensibilityUp) {
this._rotationRightAsked = true;
if (this._rotationAllowed) {
this._rotateCamera(true);
else {
if (stickValues.x < this._padSensibilityDown) {
this._rotationRightAsked = false;
}
}
}
else {
if (stickValues.x < this._padSensibilityDown) {
this._rotationRightAsked = false;
});
}
if (gamepad.type === BABYLON.Gamepad.XBOX) {
(<Xbox360Pad>gamepad).onbuttondown((buttonPressed: Xbox360Button) => {
if (buttonPressed === Xbox360Button.A) {
this._pointerDownOnMeshAsked = true;
if (this._currentMeshSelected && this._currentHit) {
this._scene.simulatePointerDown(this._currentHit);
}
}
}
});
});
(<Xbox360Pad>gamepad).onbuttonup((buttonPressed: Xbox360Button) => {
if (buttonPressed === Xbox360Button.A) {
if (this._currentMeshSelected && this._currentHit) {
this._scene.simulatePointerUp(this._currentHit);
}
this._pointerDownOnMeshAsked = false;
}
});
}
}
}

Expand Down Expand Up @@ -919,6 +939,7 @@ module BABYLON {

// Moving the gazeTracker on the mesh face targetted
if (hit && hit.pickedPoint) {
this._gazeTracker.isVisible = true;
var multiplier = 1;
if (this._isActionableMesh) {
multiplier = 3;
Expand Down Expand Up @@ -967,13 +988,19 @@ module BABYLON {
this._leftLaserPointer.position.z = -hit.distance / 2;
}
}
else {
this._gazeTracker.isVisible = false;
}

if (hit && hit.pickedMesh) {
this._currentHit = hit;
if (this._pointerDownOnMeshAsked) {
this._scene.simulatePointerMove(this._currentHit);
}
// The object selected is the floor, we're in a teleportation scenario
if (hit.pickedMesh.name.indexOf(this._floorMeshName) !== -1 && hit.pickedPoint) {
// Moving the teleportation area to this targetted point
this._moveTeleportationSelectorTo(hit)
this._moveTeleportationSelectorTo(hit);
return;
}
// If not, we're in a selection scenario
Expand Down

0 comments on commit 875f2d3

Please sign in to comment.