A refactoring of the joystick class to provide more

information about buttons and axes and allow slightly
easier hook-up of stanard triggers.
The events have also been expanded to include the
actual JoystickAxis and JoystickButton objects.
Changes to the JInput joystick support coming next
commit.  Android joystick stuff was modified to compile
but is totally broken with this change until the code
can be properly updated.


git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9760 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
PSp..om 12 years ago
parent 8daa039ecc
commit 81837959b1
  1. 219
      engine/src/core/com/jme3/input/AbstractJoystick.java
  2. 111
      engine/src/core/com/jme3/input/DefaultJoystickAxis.java
  3. 77
      engine/src/core/com/jme3/input/DefaultJoystickButton.java
  4. 51
      engine/src/core/com/jme3/input/FlyByCamera.java
  5. 138
      engine/src/core/com/jme3/input/Joystick.java
  6. 72
      engine/src/core/com/jme3/input/JoystickAxis.java
  7. 47
      engine/src/core/com/jme3/input/JoystickButton.java
  8. 24
      engine/src/core/com/jme3/input/event/JoyAxisEvent.java
  9. 24
      engine/src/core/com/jme3/input/event/JoyButtonEvent.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<JoystickAxis> axes = new ArrayList<JoystickAxis>();
private List<JoystickButton> buttons = new ArrayList<JoystickButton>();
/**
* 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<JoystickAxis> 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<JoystickButton> 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.
*
* <p>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.
*
* <p>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() + "]";
}
}

@ -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 + "]";
}
}

@ -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() + "]";
}
}

@ -69,7 +69,9 @@ public class FlyByCamera implements AnalogListener, ActionListener {
"FLYCAM_RotateDrag", "FLYCAM_RotateDrag",
"FLYCAM_Rise", "FLYCAM_Rise",
"FLYCAM_Lower" "FLYCAM_Lower",
"FLYCAM_InvertY"
}; };
protected Camera cam; protected Camera cam;
@ -81,6 +83,7 @@ public class FlyByCamera implements AnalogListener, ActionListener {
protected boolean enabled = true; protected boolean enabled = true;
protected boolean dragToRotate = false; protected boolean dragToRotate = false;
protected boolean canRotate = false; protected boolean canRotate = false;
protected boolean invertY = false;
protected InputManager inputManager; protected InputManager inputManager;
/** /**
@ -239,11 +242,38 @@ public class FlyByCamera implements AnalogListener, ActionListener {
Joystick[] joysticks = inputManager.getJoysticks(); Joystick[] joysticks = inputManager.getJoysticks();
if (joysticks != null && joysticks.length > 0){ if (joysticks != null && joysticks.length > 0){
Joystick joystick = joysticks[0]; for (Joystick j : joysticks) {
joystick.assignAxis("FLYCAM_StrafeRight", "FLYCAM_StrafeLeft", JoyInput.AXIS_POV_X); mapJoystick(j);
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()); }
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");
} }
} }
@ -363,9 +393,9 @@ public class FlyByCamera implements AnalogListener, ActionListener {
}else if (name.equals("FLYCAM_Right")){ }else if (name.equals("FLYCAM_Right")){
rotateCamera(-value, initialUpVec); rotateCamera(-value, initialUpVec);
}else if (name.equals("FLYCAM_Up")){ }else if (name.equals("FLYCAM_Up")){
rotateCamera(-value, cam.getLeft()); rotateCamera(-value * (invertY ? -1 : 1), cam.getLeft());
}else if (name.equals("FLYCAM_Down")){ }else if (name.equals("FLYCAM_Down")){
rotateCamera(value, cam.getLeft()); rotateCamera(value * (invertY ? -1 : 1), cam.getLeft());
}else if (name.equals("FLYCAM_Forward")){ }else if (name.equals("FLYCAM_Forward")){
moveCamera(value, false); moveCamera(value, false);
}else if (name.equals("FLYCAM_Backward")){ }else if (name.equals("FLYCAM_Backward")){
@ -392,6 +422,11 @@ public class FlyByCamera implements AnalogListener, ActionListener {
if (name.equals("FLYCAM_RotateDrag") && dragToRotate){ if (name.equals("FLYCAM_RotateDrag") && dragToRotate){
canRotate = value; canRotate = value;
inputManager.setCursorVisible(!value); inputManager.setCursorVisible(!value);
} else if (name.equals("FLYCAM_InvertY")) {
// Toggle on the up.
if( !value ) {
invertY = !invertY;
}
} }
} }

@ -1,48 +1,20 @@
package com.jme3.input; package com.jme3.input;
import com.jme3.input.controls.JoyAxisTrigger; import java.util.List;
import com.jme3.input.controls.JoyButtonTrigger;
/** /**
* A joystick represents a single joystick that is installed in the system. * A joystick represents a single joystick that is installed in the system.
* *
* @author Kirill Vainer * @author Paul Speed, Kirill Vainer
*/ */
public final class Joystick { public interface 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;
}
/** /**
* Rumbles the joystick for the given amount/magnitude. * Rumbles the joystick for the given amount/magnitude.
* *
* @param amount The amount to rumble. Should be between 0 and 1. * @param amount The amount to rumble. Should be between 0 and 1.
*/ */
public void rumble(float amount){ public void rumble(float amount);
joyInput.setJoyRumble(joyId, amount);
}
/** /**
* Assign the mapping name to receive events from the given button index * 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. * @param buttonId The button index.
* *
* @see Joystick#getButtonCount() * @see Joystick#getButtonCount()
* @deprecated Use JoystickButton.assignButton() instead.
*/ */
public void assignButton(String mappingName, int buttonId){ public void assignButton(String mappingName, int buttonId);
if (buttonId < 0 || buttonId >= buttonCount)
throw new IllegalArgumentException();
inputManager.addMapping(mappingName, new JoyButtonTrigger(joyId, buttonId));
}
/** /**
* Assign the mappings to receive events from the given joystick axis. * Assign the mappings to receive events from the given joystick axis.
@ -68,11 +36,67 @@ public final class Joystick {
* @param axisId The axis index. * @param axisId The axis index.
* *
* @see Joystick#getAxisCount() * @see Joystick#getAxisCount()
* @deprecated Use JoystickAxis.assignAxis() instead.
*/ */
public void assignAxis(String positiveMapping, String negativeMapping, int axisId){ 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)); /**
} * 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<JoystickAxis> 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<JoystickButton> getButtons();
/**
* Returns the X axis for this joystick.
*
* <p>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.
*
* <p>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. * 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) * @see Joystick#assignAxis(java.lang.String, java.lang.String, int)
*/ */
public int getXAxisIndex(){ public int getXAxisIndex();
return axisXIndex;
}
/** /**
* Gets the index number for the Y axis on the joystick. * 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) * @see Joystick#assignAxis(java.lang.String, java.lang.String, int)
*/ */
public int getYAxisIndex(){ public int getYAxisIndex();
return axisYIndex;
}
/** /**
* Returns the number of axes on this joystick. * Returns the number of axes on this joystick.
* *
* @return the number of axes on this joystick. * @return the number of axes on this joystick.
*/ */
public int getAxisCount() { public int getAxisCount();
return axisCount;
}
/** /**
* Returns the number of buttons on this joystick. * Returns the number of buttons on this joystick.
* *
* @return the number of buttons on this joystick. * @return the number of buttons on this joystick.
*/ */
public int getButtonCount() { public int getButtonCount();
return buttonCount;
}
/** /**
* Returns the name of this joystick. * Returns the name of this joystick.
* *
* @return the name of this joystick. * @return the name of this joystick.
*/ */
public String getName() { public String getName();
return name;
}
/** /**
* Returns the joyId of this joystick. * Returns the joyId of this joystick.
* *
* @return the joyId of this joystick. * @return the joyId of this joystick.
*/ */
public int getJoyId() { public int getJoyId();
return joyId;
}
@Override
public String toString(){
return "Joystick[name=" + name + ", id=" + joyId + ", buttons=" + buttonCount
+ ", axes=" + axisCount + "]";
}
} }

@ -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();
}

@ -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();
}

@ -34,24 +34,32 @@ package com.jme3.input.event;
import com.jme3.input.InputManager; import com.jme3.input.InputManager;
import com.jme3.input.Joystick; import com.jme3.input.Joystick;
import com.jme3.input.JoystickAxis;
/** /**
* Joystick axis event. * Joystick axis event.
* *
* @author Kirill Vainer * @author Kirill Vainer, Paul Speed
*/ */
public class JoyAxisEvent extends InputEvent { public class JoyAxisEvent extends InputEvent {
private int joyIdx; private JoystickAxis axis;
private int axisIdx;
private float value; private float value;
public JoyAxisEvent(int joyIdx, int axisIdx, float value) { public JoyAxisEvent(JoystickAxis axis, float value) {
this.joyIdx = joyIdx; this.axis = axis;
this.axisIdx = axisIdx;
this.value = value; 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. * Returns the joystick axis index.
* *
@ -60,7 +68,7 @@ public class JoyAxisEvent extends InputEvent {
* @see Joystick#assignAxis(java.lang.String, java.lang.String, int) * @see Joystick#assignAxis(java.lang.String, java.lang.String, int)
*/ */
public int getAxisIndex() { public int getAxisIndex() {
return axisIdx; return axis.getAxisId();
} }
/** /**
@ -71,7 +79,7 @@ public class JoyAxisEvent extends InputEvent {
* @see InputManager#getJoysticks() * @see InputManager#getJoysticks()
*/ */
public int getJoyIndex() { public int getJoyIndex() {
return joyIdx; return axis.getJoystick().getJoyId();
} }
/** /**

@ -33,24 +33,32 @@
package com.jme3.input.event; package com.jme3.input.event;
import com.jme3.input.Joystick; import com.jme3.input.Joystick;
import com.jme3.input.JoystickButton;
/** /**
* Joystick button event. * Joystick button event.
* *
* @author Kirill Vainer * @author Kirill Vainer, Paul Speed
*/ */
public class JoyButtonEvent extends InputEvent { public class JoyButtonEvent extends InputEvent {
private int joyIdx; private JoystickButton button;
private int btnIdx;
private boolean pressed; private boolean pressed;
public JoyButtonEvent(int joyIdx, int btnIdx, boolean pressed) { public JoyButtonEvent(JoystickButton button, boolean pressed) {
this.joyIdx = joyIdx; this.button = button;
this.btnIdx = btnIdx;
this.pressed = pressed; 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. * The button index.
* *
@ -59,7 +67,7 @@ public class JoyButtonEvent extends InputEvent {
* @see Joystick#assignButton(java.lang.String, int) * @see Joystick#assignButton(java.lang.String, int)
*/ */
public int getButtonIndex() { public int getButtonIndex() {
return btnIdx; return button.getButtonId();
} }
/** /**
@ -70,7 +78,7 @@ public class JoyButtonEvent extends InputEvent {
* @see com.jme3.input.InputManager#getJoysticks() * @see com.jme3.input.InputManager#getJoysticks()
*/ */
public int getJoyIndex() { public int getJoyIndex() {
return joyIdx; return button.getJoystick().getJoyId();
} }
/** /**

Loading…
Cancel
Save