babylon.arcrotatecamera.input.gamepad.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  2. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  3. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  4. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  5. return c > 3 && r && Object.defineProperty(target, key, r), r;
  6. };
  7. var BABYLON;
  8. (function (BABYLON) {
  9. var ArcRotateCameraGamepadInput = (function () {
  10. function ArcRotateCameraGamepadInput() {
  11. var _this = this;
  12. this.gamepadRotationSensibility = 80;
  13. this.gamepadMoveSensibility = 40;
  14. this._gamepads = new BABYLON.Gamepads(function (gamepad) { _this._onNewGameConnected(gamepad); });
  15. }
  16. ArcRotateCameraGamepadInput.prototype.attachCamera = function (camera) {
  17. this.camera = camera;
  18. };
  19. ArcRotateCameraGamepadInput.prototype.detach = function () {
  20. this._gamepads.dispose();
  21. };
  22. ArcRotateCameraGamepadInput.prototype.checkInputs = function () {
  23. if (this.gamepad) {
  24. var camera = this.camera;
  25. var RSValues = this.gamepad.rightStick;
  26. if (RSValues.x != 0) {
  27. var normalizedRX = RSValues.x / this.gamepadRotationSensibility;
  28. if (normalizedRX != 0 && Math.abs(normalizedRX) > 0.005) {
  29. camera.inertialAlphaOffset += normalizedRX;
  30. }
  31. }
  32. if (RSValues.y != 0) {
  33. var normalizedRY = RSValues.y / this.gamepadRotationSensibility;
  34. if (normalizedRY != 0 && Math.abs(normalizedRY) > 0.005) {
  35. camera.inertialBetaOffset += normalizedRY;
  36. }
  37. }
  38. var LSValues = this.gamepad.leftStick;
  39. if (LSValues.y != 0) {
  40. var normalizedLY = LSValues.y / this.gamepadMoveSensibility;
  41. if (normalizedLY != 0 && Math.abs(normalizedLY) > 0.005) {
  42. this.camera.inertialRadiusOffset -= normalizedLY;
  43. }
  44. }
  45. }
  46. };
  47. ArcRotateCameraGamepadInput.prototype._onNewGameConnected = function (gamepad) {
  48. // Only the first gamepad can control the camera
  49. if (gamepad.index === 0) {
  50. this.gamepad = gamepad;
  51. }
  52. };
  53. ArcRotateCameraGamepadInput.prototype.getTypeName = function () {
  54. return "ArcRotateCameraGamepadInput";
  55. };
  56. ArcRotateCameraGamepadInput.prototype.getSimpleName = function () {
  57. return "gamepad";
  58. };
  59. __decorate([
  60. BABYLON.serialize()
  61. ], ArcRotateCameraGamepadInput.prototype, "gamepadRotationSensibility", void 0);
  62. __decorate([
  63. BABYLON.serialize()
  64. ], ArcRotateCameraGamepadInput.prototype, "gamepadMoveSensibility", void 0);
  65. return ArcRotateCameraGamepadInput;
  66. })();
  67. BABYLON.ArcRotateCameraGamepadInput = ArcRotateCameraGamepadInput;
  68. BABYLON.CameraInputTypes["ArcRotateCameraGamepadInput"] = ArcRotateCameraGamepadInput;
  69. })(BABYLON || (BABYLON = {}));