|
|
@ -3,11 +3,12 @@ package jme3test.input; |
|
|
|
import com.jme3.app.SimpleApplication; |
|
|
|
import com.jme3.app.SimpleApplication; |
|
|
|
import com.jme3.input.JoyInput; |
|
|
|
import com.jme3.input.JoyInput; |
|
|
|
import com.jme3.input.Joystick; |
|
|
|
import com.jme3.input.Joystick; |
|
|
|
|
|
|
|
import com.jme3.input.controls.ActionListener; |
|
|
|
import com.jme3.input.controls.AnalogListener; |
|
|
|
import com.jme3.input.controls.AnalogListener; |
|
|
|
import com.jme3.input.controls.JoyAxisTrigger; |
|
|
|
import com.jme3.input.controls.JoyAxisTrigger; |
|
|
|
import com.jme3.system.AppSettings; |
|
|
|
import com.jme3.system.AppSettings; |
|
|
|
|
|
|
|
|
|
|
|
public class TestJoystick extends SimpleApplication implements AnalogListener { |
|
|
|
public class TestJoystick extends SimpleApplication implements AnalogListener, ActionListener { |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args){ |
|
|
|
public static void main(String[] args){ |
|
|
|
TestJoystick app = new TestJoystick(); |
|
|
|
TestJoystick app = new TestJoystick(); |
|
|
@ -23,25 +24,24 @@ public class TestJoystick extends SimpleApplication implements AnalogListener { |
|
|
|
if (joysticks == null) |
|
|
|
if (joysticks == null) |
|
|
|
throw new IllegalStateException("Cannot find any joysticks!"); |
|
|
|
throw new IllegalStateException("Cannot find any joysticks!"); |
|
|
|
|
|
|
|
|
|
|
|
for (Joystick joy : joysticks){ |
|
|
|
for (int i = 0; i < joysticks.length; i++){ |
|
|
|
|
|
|
|
Joystick joy = joysticks[i]; |
|
|
|
System.out.println(joy.toString()); |
|
|
|
System.out.println(joy.toString()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
joy.assignAxis("Joy Right", "Joy Left", joy.getXAxisIndex()); |
|
|
|
|
|
|
|
joy.assignAxis("Joy Down", "Joy Up", joy.getYAxisIndex()); |
|
|
|
|
|
|
|
joy.assignAxis("DPAD Right", "DPAD Left", JoyInput.AXIS_POV_X); |
|
|
|
|
|
|
|
joy.assignAxis("DPAD Up", "DPAD Down", JoyInput.AXIS_POV_Y); |
|
|
|
|
|
|
|
joy.assignButton("Button", 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
inputManager.addMapping("DPAD Left", new JoyAxisTrigger(0, JoyInput.AXIS_POV_X, true)); |
|
|
|
|
|
|
|
inputManager.addMapping("DPAD Right", new JoyAxisTrigger(0, JoyInput.AXIS_POV_X, false)); |
|
|
|
|
|
|
|
inputManager.addMapping("DPAD Down", new JoyAxisTrigger(0, JoyInput.AXIS_POV_Y, true)); |
|
|
|
|
|
|
|
inputManager.addMapping("DPAD Up", new JoyAxisTrigger(0, JoyInput.AXIS_POV_Y, false)); |
|
|
|
|
|
|
|
inputManager.addListener(this, "DPAD Left", "DPAD Right", "DPAD Down", "DPAD Up"); |
|
|
|
inputManager.addListener(this, "DPAD Left", "DPAD Right", "DPAD Down", "DPAD Up"); |
|
|
|
|
|
|
|
|
|
|
|
inputManager.addMapping("Joy Left", new JoyAxisTrigger(0, 0, true)); |
|
|
|
|
|
|
|
inputManager.addMapping("Joy Right", new JoyAxisTrigger(0, 0, false)); |
|
|
|
|
|
|
|
inputManager.addMapping("Joy Down", new JoyAxisTrigger(0, 1, true)); |
|
|
|
|
|
|
|
inputManager.addMapping("Joy Up", new JoyAxisTrigger(0, 1, false)); |
|
|
|
|
|
|
|
inputManager.addListener(this, "Joy Left", "Joy Right", "Joy Down", "Joy Up"); |
|
|
|
inputManager.addListener(this, "Joy Left", "Joy Right", "Joy Down", "Joy Up"); |
|
|
|
|
|
|
|
inputManager.addListener(this, "Button"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void onAnalog(String name, float isPressed, float tpf) { |
|
|
|
public void onAnalog(String name, float isPressed, float tpf) { |
|
|
|
System.out.println(name + " = " + isPressed); |
|
|
|
System.out.println(name + " = " + isPressed / tpf); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void onAction(String name, boolean isPressed, float tpf) { |
|
|
|
public void onAction(String name, boolean isPressed, float tpf) { |
|
|
|