@@ -277,6 +277,36 @@ void XInputController::setJoystick(XInputControl joy, int32_t x, int32_t y) {
277
277
setJoystickDirect (joy, x, y);
278
278
}
279
279
280
+ void XInputController::setJoystickX (XInputControl joy, int32_t x) {
281
+ const XInputMap_Joystick * joyData = getJoyFromEnum (joy);
282
+ if (joyData == nullptr ) return ; // Not a joystick
283
+
284
+ x = rescaleInput (x, *getRangeFromEnum (joy), XInputMap_Joystick::range);
285
+
286
+ if (getJoystickX (joy) == x) return ; // Axis hasn't changed
287
+
288
+ tx[joyData->x_low ] = lowByte (x);
289
+ tx[joyData->x_high ] = highByte (x);
290
+
291
+ newData = true ;
292
+ autosend ();
293
+ }
294
+
295
+ void XInputController::setJoystickY (XInputControl joy, int32_t y) {
296
+ const XInputMap_Joystick * joyData = getJoyFromEnum (joy);
297
+ if (joyData == nullptr ) return ; // Not a joystick
298
+
299
+ y = rescaleInput (y, *getRangeFromEnum (joy), XInputMap_Joystick::range);
300
+
301
+ if (getJoystickY (joy) == y) return ; // Axis hasn't changed
302
+
303
+ tx[joyData->y_low ] = lowByte (y);
304
+ tx[joyData->y_high ] = highByte (y);
305
+
306
+ newData = true ;
307
+ autosend ();
308
+ }
309
+
280
310
void XInputController::setJoystick (XInputControl joy, boolean up, boolean down, boolean left, boolean right, boolean useSOCD) {
281
311
const XInputMap_Joystick * joyData = getJoyFromEnum (joy);
282
312
if (joyData == nullptr ) return ; // Not a joystick
@@ -296,10 +326,12 @@ void XInputController::setJoystick(XInputControl joy, boolean up, boolean down,
296
326
// output from '0' if the per-axis inputs are different, in order to
297
327
// avoid the '-1' result from adding the int16 extremes
298
328
if (left != right) {
299
- x = (right * range.max ) - (left * range.min );
329
+ if (left == true ) { x = range.min ; }
330
+ else if (right == true ) { x = range.max ; }
300
331
}
301
332
if (up != down) {
302
- y = (up * range.max ) - (down * range.min );
333
+ if (up == true ) { y = range.max ; }
334
+ else if (down == true ) { y = range.min ; }
303
335
}
304
336
305
337
setJoystickDirect (joy, x, y);
0 commit comments