diff --git a/engine/src/core/com/jme3/input/AbstractJoystick.java b/engine/src/core/com/jme3/input/AbstractJoystick.java new file mode 100644 index 000000000..ba7b06b1b --- /dev/null +++ b/engine/src/core/com/jme3/input/AbstractJoystick.java @@ -0,0 +1,219 @@ +package com.jme3.input; + +import java.util.*; + +import com.jme3.input.controls.JoyAxisTrigger; +import com.jme3.input.controls.JoyButtonTrigger; + +/** + * A joystick represents a single joystick that is installed in the system. + * + * @author Kirill Vainer, Paul Speed + */ +public abstract class AbstractJoystick implements Joystick { + + private InputManager inputManager; + private JoyInput joyInput; + private int joyId; + private String name; + + private List axes = new ArrayList(); + private List buttons = new ArrayList(); + + /** + * Creates a new joystick instance. Only used internally. + */ + protected AbstractJoystick(InputManager inputManager, JoyInput joyInput, + int joyId, String name) { + this.inputManager = inputManager; + this.joyInput = joyInput; + this.joyId = joyId; + this.name = name; + } + + protected InputManager getInputManager() { + return inputManager; + } + + protected JoyInput getJoyInput() { + return joyInput; + } + + protected void addAxis( JoystickAxis axis ) { + axes.add(axis); + } + + protected void addButton( JoystickButton button ) { + buttons.add(button); + } + + /** + * Rumbles the joystick for the given amount/magnitude. + * + * @param amount The amount to rumble. Should be between 0 and 1. + */ + @Override + public void rumble(float amount){ + joyInput.setJoyRumble(joyId, amount); + } + + /** + * Assign the mapping name to receive events from the given button index + * on the joystick. + * + * @param mappingName The mapping to receive joystick button events. + * @param buttonId The button index. + * + * @see Joystick#getButtonCount() + * @deprecated Use JoystickButton.assignButton() instead. + */ + @Override + public void assignButton(String mappingName, int buttonId){ + if (buttonId < 0 || buttonId >= getButtonCount()) + throw new IllegalArgumentException(); + + inputManager.addMapping(mappingName, new JoyButtonTrigger(joyId, buttonId)); + } + + /** + * Assign the mappings to receive events from the given joystick axis. + * + * @param positiveMapping The mapping to receive events when the axis is negative + * @param negativeMapping The mapping to receive events when the axis is positive + * @param axisId The axis index. + * + * @see Joystick#getAxisCount() + * @deprecated Use JoystickAxis.assignAxis() instead. + */ + @Override + public void assignAxis(String positiveMapping, String negativeMapping, int axisId){ + + // For backwards compatibility + if( axisId == JoyInput.AXIS_POV_X ) { + axisId = getPovXAxis().getAxisId(); + } else if( axisId == JoyInput.AXIS_POV_Y ) { + axisId = getPovYAxis().getAxisId(); + } + + inputManager.addMapping(positiveMapping, new JoyAxisTrigger(joyId, axisId, false)); + inputManager.addMapping(negativeMapping, new JoyAxisTrigger(joyId, axisId, true)); + } + + /** + * Returns the JoystickAxis with the specified name. + * + * @param name The name of the axis to search for as returned by JoystickAxis.getName(). + */ + @Override + public JoystickAxis getAxis(String name) { + for( JoystickAxis axis : axes ) { + if( axis.getName().equals(name) ) + return axis; + } + return null; + } + + /** + * Returns a read-only list of all joystick axes for this Joystick. + */ + @Override + public List getAxes() { + return Collections.unmodifiableList(axes); + } + + /** + * Returns the number of axes on this joystick. + * + * @return the number of axes on this joystick. + */ + @Override + public int getAxisCount() { + return axes.size(); + } + + /** + * Returns the JoystickButton with the specified name. + * + * @param name The name of the button to search for as returned by JoystickButton.getName(). + */ + @Override + public JoystickButton getButton(String name) { + for( JoystickButton b : buttons ) { + if( b.getName().equals(name) ) + return b; + } + return null; + } + + /** + * Returns a read-only list of all joystick buttons for this Joystick. + */ + @Override + public List getButtons() { + return Collections.unmodifiableList(buttons); + } + + /** + * Returns the number of buttons on this joystick. + * + * @return the number of buttons on this joystick. + */ + @Override + public int getButtonCount() { + return buttons.size(); + } + + /** + * Returns the name of this joystick. + * + * @return the name of this joystick. + */ + @Override + public String getName() { + return name; + } + + /** + * Returns the joyId of this joystick. + * + * @return the joyId of this joystick. + */ + @Override + public int getJoyId() { + return joyId; + } + + /** + * Gets the index number for the X axis on the joystick. + * + *

E.g. for most gamepads, the left control stick X axis will be returned. + * + * @return The axis index for the X axis for this joystick. + * + * @see Joystick#assignAxis(java.lang.String, java.lang.String, int) + */ + @Override + public int getXAxisIndex(){ + return getXAxis().getAxisId(); + } + + /** + * Gets the index number for the Y axis on the joystick. + * + *

E.g. for most gamepads, the left control stick Y axis will be returned. + * + * @return The axis index for the Y axis for this joystick. + * + * @see Joystick#assignAxis(java.lang.String, java.lang.String, int) + */ + @Override + public int getYAxisIndex(){ + return getYAxis().getAxisId(); + } + + @Override + public String toString(){ + return "Joystick[name=" + name + ", id=" + joyId + ", buttons=" + getButtonCount() + + ", axes=" + getAxisCount() + "]"; + } +} diff --git a/engine/src/core/com/jme3/input/DefaultJoystickAxis.java b/engine/src/core/com/jme3/input/DefaultJoystickAxis.java new file mode 100644 index 000000000..e91a0542e --- /dev/null +++ b/engine/src/core/com/jme3/input/DefaultJoystickAxis.java @@ -0,0 +1,111 @@ +package com.jme3.input; + +import com.jme3.input.controls.JoyAxisTrigger; + +/** + * Default implementation of the JoystickAxis interface. + * + * @author Paul Speed + */ +public class DefaultJoystickAxis implements JoystickAxis { + + private InputManager inputManager; + private Joystick parent; + private int axisIndex; + private String name; + private String logicalId; + private boolean isAnalog; + private boolean isRelative; + private float deadZone; + + /** + * Creates a new joystick axis instance. Only used internally. + */ + public DefaultJoystickAxis(InputManager inputManager, Joystick parent, + int axisIndex, String name, String logicalId, + boolean isAnalog, boolean isRelative, float deadZone ) { + this.inputManager = inputManager; + this.parent = parent; + this.axisIndex = axisIndex; + this.name = name; + this.logicalId = logicalId; + this.isAnalog = isAnalog; + this.isRelative = isRelative; + this.deadZone = deadZone; + } + + /** + * Assign the mappings to receive events from the given joystick axis. + * + * @param positiveMapping The mapping to receive events when the axis is negative + * @param negativeMapping The mapping to receive events when the axis is positive + */ + public void assignAxis(String positiveMapping, String negativeMapping){ + inputManager.addMapping(positiveMapping, new JoyAxisTrigger(parent.getJoyId(), axisIndex, false)); + inputManager.addMapping(negativeMapping, new JoyAxisTrigger(parent.getJoyId(), axisIndex, true)); + } + + /** + * Returns the joystick to which this axis object belongs. + */ + public Joystick getJoystick() { + return parent; + } + + /** + * Returns the name of this joystick. + * + * @return the name of this joystick. + */ + public String getName() { + return name; + } + + /** + * Returns the logical identifier of this joystick axis. + * + * @return the logical identifier of this joystick. + */ + public String getLogicalId() { + return logicalId; + } + + /** + * Returns the axisId of this joystick axis. + * + * @return the axisId of this joystick axis. + */ + public int getAxisId() { + return axisIndex; + } + + /** + * Returns true if this is an analog axis, meaning the values + * are a continuous range instead of 1, 0, and -1. + */ + public boolean isAnalog() { + return isAnalog; + } + + /** + * Returns true if this axis presents relative values. + */ + public boolean isRelative() { + return isRelative; + } + + /** + * Returns the suggested dead zone for this axis. Values less than this + * can be safely ignored. + */ + public float getDeadZone() { + return deadZone; + } + + @Override + public String toString(){ + return "JoystickAxis[name=" + name + ", parent=" + parent.getName() + ", id=" + axisIndex + + ", logicalId=" + logicalId + ", isAnalog=" + isAnalog + + ", isRelative=" + isRelative + ", deadZone=" + deadZone + "]"; + } +} diff --git a/engine/src/core/com/jme3/input/DefaultJoystickButton.java b/engine/src/core/com/jme3/input/DefaultJoystickButton.java new file mode 100644 index 000000000..57bef8a4c --- /dev/null +++ b/engine/src/core/com/jme3/input/DefaultJoystickButton.java @@ -0,0 +1,77 @@ +package com.jme3.input; + +import com.jme3.input.controls.JoyButtonTrigger; + +/** + * Default implementation of the JoystickButton interface. + * + * @author Paul Speed + */ +public class DefaultJoystickButton implements JoystickButton { + + private InputManager inputManager; + private Joystick parent; + private int buttonIndex; + private String name; + private String logicalId; + + public DefaultJoystickButton( InputManager inputManager, Joystick parent, int buttonIndex, + String name, String logicalId ) { + this.inputManager = inputManager; + this.parent = parent; + this.buttonIndex = buttonIndex; + this.name = name; + this.logicalId = logicalId; + } + + /** + * Assign the mapping name to receive events from the given button index + * on the joystick. + * + * @param mappingName The mapping to receive joystick button events. + */ + public void assignButton(String mappingName) { + inputManager.addMapping(mappingName, new JoyButtonTrigger(parent.getJoyId(), buttonIndex)); + } + + /** + * Returns the joystick to which this axis object belongs. + */ + public Joystick getJoystick() { + return parent; + } + + /** + * Returns the name of this joystick. + * + * @return the name of this joystick. + */ + public String getName() { + return name; + } + + /** + * Returns the logical identifier of this joystick axis. + * + * @return the logical identifier of this joystick. + */ + public String getLogicalId() { + return logicalId; + } + + /** + * Returns the unique buttonId of this joystick axis within a given + * InputManager context. + * + * @return the buttonId of this joystick axis. + */ + public int getButtonId() { + return buttonIndex; + } + + @Override + public String toString(){ + return "JoystickButton[name=" + getName() + ", parent=" + parent.getName() + ", id=" + getButtonId() + + ", logicalId=" + getLogicalId() + "]"; + } +} diff --git a/engine/src/core/com/jme3/input/FlyByCamera.java b/engine/src/core/com/jme3/input/FlyByCamera.java index dc33b745a..5bfee8743 100644 --- a/engine/src/core/com/jme3/input/FlyByCamera.java +++ b/engine/src/core/com/jme3/input/FlyByCamera.java @@ -69,7 +69,9 @@ public class FlyByCamera implements AnalogListener, ActionListener { "FLYCAM_RotateDrag", "FLYCAM_Rise", - "FLYCAM_Lower" + "FLYCAM_Lower", + + "FLYCAM_InvertY" }; protected Camera cam; @@ -81,6 +83,7 @@ public class FlyByCamera implements AnalogListener, ActionListener { protected boolean enabled = true; protected boolean dragToRotate = false; protected boolean canRotate = false; + protected boolean invertY = false; protected InputManager inputManager; /** @@ -239,14 +242,41 @@ public class FlyByCamera implements AnalogListener, ActionListener { Joystick[] joysticks = inputManager.getJoysticks(); if (joysticks != null && joysticks.length > 0){ - Joystick joystick = joysticks[0]; - joystick.assignAxis("FLYCAM_StrafeRight", "FLYCAM_StrafeLeft", JoyInput.AXIS_POV_X); - joystick.assignAxis("FLYCAM_Forward", "FLYCAM_Backward", JoyInput.AXIS_POV_Y); - joystick.assignAxis("FLYCAM_Right", "FLYCAM_Left", joystick.getXAxisIndex()); - joystick.assignAxis("FLYCAM_Down", "FLYCAM_Up", joystick.getYAxisIndex()); + for (Joystick j : joysticks) { + mapJoystick(j); + } } } + protected void mapJoystick( Joystick joystick ) { + + // Map it differently if there are Z axis + if( joystick.getAxis( JoystickAxis.Z_ROTATION ) != null && joystick.getAxis( JoystickAxis.Z_AXIS ) != null ) { + + // Make the left stick move + joystick.getXAxis().assignAxis( "FLYCAM_StrafeRight", "FLYCAM_StrafeLeft" ); + joystick.getYAxis().assignAxis( "FLYCAM_Backward", "FLYCAM_Forward" ); + + // And the right stick control the camera + joystick.getAxis( JoystickAxis.Z_ROTATION ).assignAxis( "FLYCAM_Down", "FLYCAM_Up" ); + joystick.getAxis( JoystickAxis.Z_AXIS ).assignAxis( "FLYCAM_Right", "FLYCAM_Left" ); + + // And let the dpad be up and down + joystick.getPovYAxis().assignAxis("FLYCAM_Rise", "FLYCAM_Lower"); + + if( joystick.getButton( "Button 8" ) != null ) { + // Let the stanard select button be the y invert toggle + joystick.getButton( "Button 8" ).assignButton( "FLYCAM_InvertY" ); + } + + } else { + joystick.getPovXAxis().assignAxis("FLYCAM_StrafeRight", "FLYCAM_StrafeLeft"); + joystick.getPovYAxis().assignAxis("FLYCAM_Forward", "FLYCAM_Backward"); + joystick.getXAxis().assignAxis("FLYCAM_Right", "FLYCAM_Left"); + joystick.getYAxis().assignAxis("FLYCAM_Down", "FLYCAM_Up"); + } + } + /** * Registers the FlyByCamera to receive input events from the provided * Dispatcher. @@ -363,9 +393,9 @@ public class FlyByCamera implements AnalogListener, ActionListener { }else if (name.equals("FLYCAM_Right")){ rotateCamera(-value, initialUpVec); }else if (name.equals("FLYCAM_Up")){ - rotateCamera(-value, cam.getLeft()); + rotateCamera(-value * (invertY ? -1 : 1), cam.getLeft()); }else if (name.equals("FLYCAM_Down")){ - rotateCamera(value, cam.getLeft()); + rotateCamera(value * (invertY ? -1 : 1), cam.getLeft()); }else if (name.equals("FLYCAM_Forward")){ moveCamera(value, false); }else if (name.equals("FLYCAM_Backward")){ @@ -392,7 +422,12 @@ public class FlyByCamera implements AnalogListener, ActionListener { if (name.equals("FLYCAM_RotateDrag") && dragToRotate){ canRotate = value; inputManager.setCursorVisible(!value); - } + } else if (name.equals("FLYCAM_InvertY")) { + // Toggle on the up. + if( !value ) { + invertY = !invertY; + } + } } } diff --git a/engine/src/core/com/jme3/input/Joystick.java b/engine/src/core/com/jme3/input/Joystick.java index dd706d802..e8a080afd 100644 --- a/engine/src/core/com/jme3/input/Joystick.java +++ b/engine/src/core/com/jme3/input/Joystick.java @@ -1,48 +1,20 @@ package com.jme3.input; -import com.jme3.input.controls.JoyAxisTrigger; -import com.jme3.input.controls.JoyButtonTrigger; +import java.util.List; /** * A joystick represents a single joystick that is installed in the system. * - * @author Kirill Vainer + * @author Paul Speed, Kirill Vainer */ -public final class Joystick { - - private InputManager inputManager; - private JoyInput joyInput; - private int joyId; - private int buttonCount; - private int axisCount; - private int axisXIndex, axisYIndex; - private String name; - - /** - * Creates a new joystick instance. Only used internally. - */ - public Joystick(InputManager inputManager, JoyInput joyInput, - int joyId, String name, int buttonCount, int axisCount, - int xAxis, int yAxis){ - this.inputManager = inputManager; - this.joyInput = joyInput; - this.joyId = joyId; - this.name = name; - this.buttonCount = buttonCount; - this.axisCount = axisCount; - - this.axisXIndex = xAxis; - this.axisYIndex = yAxis; - } +public interface Joystick { /** * Rumbles the joystick for the given amount/magnitude. * * @param amount The amount to rumble. Should be between 0 and 1. */ - public void rumble(float amount){ - joyInput.setJoyRumble(joyId, amount); - } + public void rumble(float amount); /** * Assign the mapping name to receive events from the given button index @@ -52,13 +24,9 @@ public final class Joystick { * @param buttonId The button index. * * @see Joystick#getButtonCount() + * @deprecated Use JoystickButton.assignButton() instead. */ - public void assignButton(String mappingName, int buttonId){ - if (buttonId < 0 || buttonId >= buttonCount) - throw new IllegalArgumentException(); - - inputManager.addMapping(mappingName, new JoyButtonTrigger(joyId, buttonId)); - } + public void assignButton(String mappingName, int buttonId); /** * Assign the mappings to receive events from the given joystick axis. @@ -68,11 +36,67 @@ public final class Joystick { * @param axisId The axis index. * * @see Joystick#getAxisCount() + * @deprecated Use JoystickAxis.assignAxis() instead. */ - public void assignAxis(String positiveMapping, String negativeMapping, int axisId){ - inputManager.addMapping(positiveMapping, new JoyAxisTrigger(joyId, axisId, false)); - inputManager.addMapping(negativeMapping, new JoyAxisTrigger(joyId, axisId, true)); - } + public void assignAxis(String positiveMapping, String negativeMapping, int axisId); + + /** + * Returns the JoystickAxis with the specified name. + * + * @param name The name of the axis to search for as returned by JoystickAxis.getName(). + */ + public JoystickAxis getAxis(String name); + + /** + * Returns a read-only list of all joystick axes for this Joystick. + */ + public List getAxes(); + + /** + * Returns the JoystickButton with the specified name. + * + * @param name The name of the button to search for as returned by JoystickButton.getName(). + */ + public JoystickButton getButton(String name); + + /** + * Returns a read-only list of all joystick buttons for this Joystick. + */ + public List getButtons(); + + /** + * Returns the X axis for this joystick. + * + *

E.g. for most gamepads, the left control stick X axis will be returned. + * + * @see JoystickAxis#assignAxis(java.lang.String, java.lang.String) + */ + public JoystickAxis getXAxis(); + + /** + * Returns the Y axis for this joystick. + * + *

E.g. for most gamepads, the left control stick Y axis will be returned. + * + * @see JoystickAxis#assignAxis(java.lang.String, java.lang.String) + */ + public JoystickAxis getYAxis(); + + /** + * Returns the POV X axis for this joystick. This is a convenience axis + * providing an x-axis subview of the HAT axis. + * + * @see JoystickAxis#assignAxis(java.lang.String, java.lang.String) + */ + public JoystickAxis getPovXAxis(); + + /** + * Returns the POV Y axis for this joystick. This is a convenience axis + * providing an y-axis subview of the HAT axis. + * + * @see JoystickAxis#assignAxis(java.lang.String, java.lang.String) + */ + public JoystickAxis getPovYAxis(); /** * Gets the index number for the X axis on the joystick. @@ -83,9 +107,7 @@ public final class Joystick { * * @see Joystick#assignAxis(java.lang.String, java.lang.String, int) */ - public int getXAxisIndex(){ - return axisXIndex; - } + public int getXAxisIndex(); /** * Gets the index number for the Y axis on the joystick. @@ -96,50 +118,34 @@ public final class Joystick { * * @see Joystick#assignAxis(java.lang.String, java.lang.String, int) */ - public int getYAxisIndex(){ - return axisYIndex; - } + public int getYAxisIndex(); /** * Returns the number of axes on this joystick. * * @return the number of axes on this joystick. */ - public int getAxisCount() { - return axisCount; - } + public int getAxisCount(); /** * Returns the number of buttons on this joystick. * * @return the number of buttons on this joystick. */ - public int getButtonCount() { - return buttonCount; - } + public int getButtonCount(); /** * Returns the name of this joystick. * * @return the name of this joystick. */ - public String getName() { - return name; - } + public String getName(); /** * Returns the joyId of this joystick. * * @return the joyId of this joystick. */ - public int getJoyId() { - return joyId; - } - - @Override - public String toString(){ - return "Joystick[name=" + name + ", id=" + joyId + ", buttons=" + buttonCount - + ", axes=" + axisCount + "]"; - } + public int getJoyId(); } diff --git a/engine/src/core/com/jme3/input/JoystickAxis.java b/engine/src/core/com/jme3/input/JoystickAxis.java new file mode 100644 index 000000000..371761021 --- /dev/null +++ b/engine/src/core/com/jme3/input/JoystickAxis.java @@ -0,0 +1,72 @@ +package com.jme3.input; + +import com.jme3.input.controls.JoyAxisTrigger; +import com.jme3.input.controls.JoyButtonTrigger; + +/** + * Represents a single axis of a Joystick. + * + * @author Paul Speed + */ +public interface JoystickAxis { + + public static final String X_AXIS = "X Axis"; + public static final String Y_AXIS = "Y Axis"; + public static final String Z_AXIS = "Z Axis"; + public static final String Z_ROTATION = "Z Rotation"; + + public static final String POV_X = "JME:POV_X"; + public static final String POV_Y = "JME:POV_Y"; + + /** + * Assign the mappings to receive events from the given joystick axis. + * + * @param positiveMapping The mapping to receive events when the axis is negative + * @param negativeMapping The mapping to receive events when the axis is positive + */ + public void assignAxis(String positiveMapping, String negativeMapping); + + /** + * Returns the joystick to which this axis object belongs. + */ + public Joystick getJoystick(); + + /** + * Returns the name of this joystick. + * + * @return the name of this joystick. + */ + public String getName(); + + /** + * Returns the logical identifier of this joystick axis. + * + * @return the logical identifier of this joystick. + */ + public String getLogicalId(); + + /** + * Returns the unique axisId of this joystick axis within a given + * InputManager context. + * + * @return the axisId of this joystick axis. + */ + public int getAxisId(); + + /** + * Returns true if this is an analog axis, meaning the values + * are a continuous range instead of 1, 0, and -1. + */ + public boolean isAnalog(); + + /** + * Returns true if this axis presents relative values. + */ + public boolean isRelative(); + + /** + * Returns the suggested dead zone for this axis. Values less than this + * can be safely ignored. + */ + public float getDeadZone(); +} diff --git a/engine/src/core/com/jme3/input/JoystickButton.java b/engine/src/core/com/jme3/input/JoystickButton.java new file mode 100644 index 000000000..509a8fee6 --- /dev/null +++ b/engine/src/core/com/jme3/input/JoystickButton.java @@ -0,0 +1,47 @@ +package com.jme3.input; + +import com.jme3.input.controls.JoyAxisTrigger; +import com.jme3.input.controls.JoyButtonTrigger; + +/** + * Represents a single button of a Joystick. + * + * @author Paul Speed + */ +public interface JoystickButton { + + /** + * Assign the mapping name to receive events from the given button index + * on the joystick. + * + * @param mappingName The mapping to receive joystick button events. + */ + public void assignButton(String mappingName); + + /** + * Returns the joystick to which this axis object belongs. + */ + public Joystick getJoystick(); + + /** + * Returns the name of this joystick. + * + * @return the name of this joystick. + */ + public String getName(); + + /** + * Returns the logical identifier of this joystick axis. + * + * @return the logical identifier of this joystick. + */ + public String getLogicalId(); + + /** + * Returns the unique buttonId of this joystick axis within a given + * InputManager context. + * + * @return the buttonId of this joystick axis. + */ + public int getButtonId(); +} diff --git a/engine/src/core/com/jme3/input/event/JoyAxisEvent.java b/engine/src/core/com/jme3/input/event/JoyAxisEvent.java index 2896b0bbf..500a835e3 100644 --- a/engine/src/core/com/jme3/input/event/JoyAxisEvent.java +++ b/engine/src/core/com/jme3/input/event/JoyAxisEvent.java @@ -34,24 +34,32 @@ package com.jme3.input.event; import com.jme3.input.InputManager; import com.jme3.input.Joystick; +import com.jme3.input.JoystickAxis; /** * Joystick axis event. * - * @author Kirill Vainer + * @author Kirill Vainer, Paul Speed */ public class JoyAxisEvent extends InputEvent { - private int joyIdx; - private int axisIdx; + private JoystickAxis axis; private float value; - public JoyAxisEvent(int joyIdx, int axisIdx, float value) { - this.joyIdx = joyIdx; - this.axisIdx = axisIdx; + public JoyAxisEvent(JoystickAxis axis, float value) { + this.axis = axis; this.value = value; } + /** + * Returns the JoystickAxis that triggered this event. + * + * @see JoystickAxis#assignAxis(java.lang.String, java.lang.String, int) + */ + public JoystickAxis getAxis() { + return axis; + } + /** * Returns the joystick axis index. * @@ -60,7 +68,7 @@ public class JoyAxisEvent extends InputEvent { * @see Joystick#assignAxis(java.lang.String, java.lang.String, int) */ public int getAxisIndex() { - return axisIdx; + return axis.getAxisId(); } /** @@ -71,7 +79,7 @@ public class JoyAxisEvent extends InputEvent { * @see InputManager#getJoysticks() */ public int getJoyIndex() { - return joyIdx; + return axis.getJoystick().getJoyId(); } /** diff --git a/engine/src/core/com/jme3/input/event/JoyButtonEvent.java b/engine/src/core/com/jme3/input/event/JoyButtonEvent.java index 9afd06bcd..2574a1214 100644 --- a/engine/src/core/com/jme3/input/event/JoyButtonEvent.java +++ b/engine/src/core/com/jme3/input/event/JoyButtonEvent.java @@ -33,24 +33,32 @@ package com.jme3.input.event; import com.jme3.input.Joystick; +import com.jme3.input.JoystickButton; /** * Joystick button event. * - * @author Kirill Vainer + * @author Kirill Vainer, Paul Speed */ public class JoyButtonEvent extends InputEvent { - private int joyIdx; - private int btnIdx; + private JoystickButton button; private boolean pressed; - public JoyButtonEvent(int joyIdx, int btnIdx, boolean pressed) { - this.joyIdx = joyIdx; - this.btnIdx = btnIdx; + public JoyButtonEvent(JoystickButton button, boolean pressed) { + this.button = button; this.pressed = pressed; } + /** + * Returns the JoystickButton that triggered this event. + * + * @see JoystickAxis#assignAxis(java.lang.String, java.lang.String, int) + */ + public JoystickButton getButton() { + return button; + } + /** * The button index. * @@ -59,7 +67,7 @@ public class JoyButtonEvent extends InputEvent { * @see Joystick#assignButton(java.lang.String, int) */ public int getButtonIndex() { - return btnIdx; + return button.getButtonId(); } /** @@ -70,7 +78,7 @@ public class JoyButtonEvent extends InputEvent { * @see com.jme3.input.InputManager#getJoysticks() */ public int getJoyIndex() { - return joyIdx; + return button.getJoystick().getJoyId(); } /**