three-gamepad-controls 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,6 +46,16 @@ type GamepadInputOptions = {
46
46
  * @default false
47
47
  */
48
48
  rescale: boolean;
49
+ /**
50
+ * Whether the horizontal component of stick reads is inverted by default.
51
+ * @default false
52
+ */
53
+ invertX: boolean;
54
+ /**
55
+ * Whether the vertical component of stick reads is inverted by default.
56
+ * @default false
57
+ */
58
+ invertY: boolean;
49
59
  /**
50
60
  * Browser-assigned gamepad slot to use.
51
61
  *
@@ -83,17 +93,27 @@ type GamepadStickOptions = GamepadAxisOptions & {
83
93
  * @default false
84
94
  */
85
95
  rescale?: boolean;
96
+ /**
97
+ * Whether to invert the processed component from `xAxis`.
98
+ * @default false
99
+ */
100
+ invertX?: boolean;
101
+ /**
102
+ * Whether to invert the processed component from `yAxis`.
103
+ * @default false
104
+ */
105
+ invertY?: boolean;
86
106
  };
87
107
  /**
88
- * Two-dimensional stick input after dead zone processing.
108
+ * Two-dimensional stick input after configured stick processing.
89
109
  */
90
110
  type GamepadStick = {
91
111
  /**
92
- * Horizontal stick value.
112
+ * Processed horizontal stick value.
93
113
  */
94
114
  x: number;
95
115
  /**
96
- * Vertical stick value.
116
+ * Processed vertical stick value.
97
117
  */
98
118
  y: number;
99
119
  };
@@ -194,7 +214,7 @@ declare class GamepadInput extends EventDispatcher<GamepadInputEventMap> {
194
214
  */
195
215
  axis(axis: number, options?: GamepadAxisOptions): number;
196
216
  /**
197
- * Returns a two-axis stick after dead zone processing.
217
+ * Returns a two-axis stick after dead zone, rescale, and inversion processing.
198
218
  *
199
219
  * @param xAxis - Horizontal axis index.
200
220
  * @param yAxis - Vertical axis index.
@@ -5,7 +5,9 @@ import { EventDispatcher } from "three";
5
5
  const DEFAULT_GAMEPAD_INPUT_OPTIONS = {
6
6
  deadzone: .1,
7
7
  deadzoneMode: "axial",
8
- rescale: false
8
+ rescale: false,
9
+ invertX: false,
10
+ invertY: false
9
11
  };
10
12
  /**
11
13
  * Applies a dead zone and remaps the remaining magnitude to `[0, 1]`.
@@ -277,7 +279,7 @@ var GamepadInput = class extends EventDispatcher {
277
279
  return applyGamepadAxialDeadzone(value, this.#getDeadzone(options), false);
278
280
  }
279
281
  /**
280
- * Returns a two-axis stick after dead zone processing.
282
+ * Returns a two-axis stick after dead zone, rescale, and inversion processing.
281
283
  *
282
284
  * @param xAxis - Horizontal axis index.
283
285
  * @param yAxis - Vertical axis index.
@@ -287,14 +289,20 @@ var GamepadInput = class extends EventDispatcher {
287
289
  stick(xAxis, yAxis, options) {
288
290
  const deadzoneMode = options?.deadzoneMode ?? this.#options.deadzoneMode;
289
291
  const rescale = options?.rescale ?? this.#options.rescale;
292
+ const invertX = options?.invertX ?? this.#options.invertX;
293
+ const invertY = options?.invertY ?? this.#options.invertY;
290
294
  const threshold = this.#getDeadzone(options);
291
295
  const x = this.#gamepad?.axes[xAxis] ?? 0;
292
296
  const y = this.#gamepad?.axes[yAxis] ?? 0;
293
- if (deadzoneMode === "radial") return applyGamepadRadialDeadzone(x, y, threshold, rescale);
294
- return {
297
+ const processed = deadzoneMode === "radial" ? applyGamepadRadialDeadzone(x, y, threshold, rescale) : {
295
298
  x: applyGamepadAxialDeadzone(x, threshold, rescale),
296
299
  y: applyGamepadAxialDeadzone(y, threshold, rescale)
297
300
  };
301
+ if (!invertX && !invertY) return processed;
302
+ return {
303
+ x: processed.x === 0 ? 0 : invertX ? -processed.x : processed.x,
304
+ y: processed.y === 0 ? 0 : invertY ? -processed.y : processed.y
305
+ };
298
306
  }
299
307
  /**
300
308
  * Plays an effect through the active gamepad's primary vibration actuator.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "three-gamepad-controls",
3
3
  "description": "Gamepad support for Three.js controls.",
4
- "version": "0.17.0",
4
+ "version": "0.18.0",
5
5
  "homepage": "https://github.com/luckasnix/three-gamepad-controls#readme",
6
6
  "author": {
7
7
  "name": "Kasnix",