Modified to pay attention to the joystick axis'

dead zone if it is larger than the globally defined
dead zone.
cleanup_build_scripts
Paul Speed 9 years ago
parent 84ccd71873
commit 2a2c71dadf
  1. 31
      jme3-core/src/main/java/com/jme3/input/InputManager.java

@ -96,7 +96,7 @@ public class InputManager implements RawInputListener {
private boolean eventsPermitted = false; private boolean eventsPermitted = false;
private boolean mouseVisible = true; private boolean mouseVisible = true;
private boolean safeMode = false; private boolean safeMode = false;
private float axisDeadZone = 0.05f; private float globalAxisDeadZone = 0.05f;
private Vector2f cursorPos = new Vector2f(); private Vector2f cursorPos = new Vector2f();
private Joystick[] joysticks; private Joystick[] joysticks;
private final IntMap<ArrayList<Mapping>> bindings = new IntMap<ArrayList<Mapping>>(); private final IntMap<ArrayList<Mapping>> bindings = new IntMap<ArrayList<Mapping>>();
@ -248,8 +248,8 @@ public class InputManager implements RawInputListener {
} }
} }
private void invokeAnalogsAndActions(int hash, float value, boolean applyTpf) { private void invokeAnalogsAndActions(int hash, float value, float effectiveDeadZone, boolean applyTpf) {
if (value < axisDeadZone) { if (value < effectiveDeadZone) {
invokeAnalogs(hash, value, !applyTpf); invokeAnalogs(hash, value, !applyTpf);
return; return;
} }
@ -304,17 +304,18 @@ public class InputManager implements RawInputListener {
int joyId = evt.getJoyIndex(); int joyId = evt.getJoyIndex();
int axis = evt.getAxisIndex(); int axis = evt.getAxisIndex();
float value = evt.getValue(); float value = evt.getValue();
if (value < axisDeadZone && value > -axisDeadZone) { float effectiveDeadZone = Math.max(globalAxisDeadZone, evt.getAxis().getDeadZone());
if (value < effectiveDeadZone && value > -effectiveDeadZone) {
int hash1 = JoyAxisTrigger.joyAxisHash(joyId, axis, true); int hash1 = JoyAxisTrigger.joyAxisHash(joyId, axis, true);
int hash2 = JoyAxisTrigger.joyAxisHash(joyId, axis, false); int hash2 = JoyAxisTrigger.joyAxisHash(joyId, axis, false);
Float val1 = axisValues.get(hash1); Float val1 = axisValues.get(hash1);
Float val2 = axisValues.get(hash2); Float val2 = axisValues.get(hash2);
if (val1 != null && val1.floatValue() > axisDeadZone) { if (val1 != null && val1.floatValue() > effectiveDeadZone) {
invokeActions(hash1, false); invokeActions(hash1, false);
} }
if (val2 != null && val2.floatValue() > axisDeadZone) { if (val2 != null && val2.floatValue() > effectiveDeadZone) {
invokeActions(hash2, false); invokeActions(hash2, false);
} }
@ -328,11 +329,11 @@ public class InputManager implements RawInputListener {
// Clear the reverse direction's actions in case we // Clear the reverse direction's actions in case we
// crossed center too quickly // crossed center too quickly
Float otherVal = axisValues.get(otherHash); Float otherVal = axisValues.get(otherHash);
if (otherVal != null && otherVal.floatValue() > axisDeadZone) { if (otherVal != null && otherVal.floatValue() > effectiveDeadZone) {
invokeActions(otherHash, false); invokeActions(otherHash, false);
} }
invokeAnalogsAndActions(hash, -value, true); invokeAnalogsAndActions(hash, -value, effectiveDeadZone, true);
axisValues.put(hash, -value); axisValues.put(hash, -value);
axisValues.remove(otherHash); axisValues.remove(otherHash);
} else { } else {
@ -342,11 +343,11 @@ public class InputManager implements RawInputListener {
// Clear the reverse direction's actions in case we // Clear the reverse direction's actions in case we
// crossed center too quickly // crossed center too quickly
Float otherVal = axisValues.get(otherHash); Float otherVal = axisValues.get(otherHash);
if (otherVal != null && otherVal.floatValue() > axisDeadZone) { if (otherVal != null && otherVal.floatValue() > effectiveDeadZone) {
invokeActions(otherHash, false); invokeActions(otherHash, false);
} }
invokeAnalogsAndActions(hash, value, true); invokeAnalogsAndActions(hash, value, effectiveDeadZone, true);
axisValues.put(hash, value); axisValues.put(hash, value);
axisValues.remove(otherHash); axisValues.remove(otherHash);
} }
@ -391,15 +392,15 @@ public class InputManager implements RawInputListener {
if (evt.getDX() != 0) { if (evt.getDX() != 0) {
float val = Math.abs(evt.getDX()) / 1024f; float val = Math.abs(evt.getDX()) / 1024f;
invokeAnalogsAndActions(MouseAxisTrigger.mouseAxisHash(MouseInput.AXIS_X, evt.getDX() < 0), val, false); invokeAnalogsAndActions(MouseAxisTrigger.mouseAxisHash(MouseInput.AXIS_X, evt.getDX() < 0), val, globalAxisDeadZone, false);
} }
if (evt.getDY() != 0) { if (evt.getDY() != 0) {
float val = Math.abs(evt.getDY()) / 1024f; float val = Math.abs(evt.getDY()) / 1024f;
invokeAnalogsAndActions(MouseAxisTrigger.mouseAxisHash(MouseInput.AXIS_Y, evt.getDY() < 0), val, false); invokeAnalogsAndActions(MouseAxisTrigger.mouseAxisHash(MouseInput.AXIS_Y, evt.getDY() < 0), val, globalAxisDeadZone, false);
} }
if (evt.getDeltaWheel() != 0) { if (evt.getDeltaWheel() != 0) {
float val = Math.abs(evt.getDeltaWheel()) / 100f; float val = Math.abs(evt.getDeltaWheel()) / 100f;
invokeAnalogsAndActions(MouseAxisTrigger.mouseAxisHash(MouseInput.AXIS_WHEEL, evt.getDeltaWheel() < 0), val, false); invokeAnalogsAndActions(MouseAxisTrigger.mouseAxisHash(MouseInput.AXIS_WHEEL, evt.getDeltaWheel() < 0), val, globalAxisDeadZone, false);
} }
} }
@ -477,7 +478,7 @@ public class InputManager implements RawInputListener {
* @param deadZone the deadzone for joystick axes. * @param deadZone the deadzone for joystick axes.
*/ */
public void setAxisDeadZone(float deadZone) { public void setAxisDeadZone(float deadZone) {
this.axisDeadZone = deadZone; this.globalAxisDeadZone = deadZone;
} }
/** /**
@ -486,7 +487,7 @@ public class InputManager implements RawInputListener {
* @return the deadzone for joystick axes. * @return the deadzone for joystick axes.
*/ */
public float getAxisDeadZone() { public float getAxisDeadZone() {
return axisDeadZone; return globalAxisDeadZone;
} }
/** /**

Loading…
Cancel
Save