[FIXED] Expose rumblers in Controller

Started by Orangy Tang, April 09, 2012, 14:49:15

Previous topic - Next topic

Orangy Tang

So I'd like to get vibration/rumble feedback when using a pad. Currently I'm flicking between Win7 and OSX/Snow Leopard to develop on, and using either 360 or PS3 pads.

Firstly, I added a small change to expose JInput's rumble:

Index: src/java/org/lwjgl/input/Controller.java
===================================================================
--- src/java/org/lwjgl/input/Controller.java	(revision 3758)
+++ src/java/org/lwjgl/input/Controller.java	(working copy)
@@ -270,4 +270,21 @@
 	 * @param zone The dead zone to use for the RZ axis
 	 */
 	void setRZAxisDeadZone(float zone);
+	
+	
+	/** Returns the number of rumblers this controller supports */
+	int getRumblerCount();
+	
+	/** Returns the name of the specified rumbler
+	 * 
+	 * @param index The rumbler index
+	 */
+	String getRumblerName(final int index);
+	
+	/** Sets the vibration strength of the specified rumbler
+	 * 
+	 * @param index The index of the rumbler
+	 * @param strength The strength to vibrate at
+	 */
+	void setRumblerStrength(final int index, final float strength);
 }
Index: src/java/org/lwjgl/input/JInputController.java
===================================================================
--- src/java/org/lwjgl/input/JInputController.java	(revision 3758)
+++ src/java/org/lwjgl/input/JInputController.java	(working copy)
@@ -38,6 +38,7 @@
 import net.java.games.input.Component.Identifier.Button;
 import net.java.games.input.Event;
 import net.java.games.input.EventQueue;
+import net.java.games.input.Rumbler;
 
 /**
  * A wrapper round a JInput controller that attempts to make the interface
@@ -56,6 +57,8 @@
 	private ArrayList<Component> axes = new ArrayList<Component>();
 	/** The POVs that have been detected on the JInput controller */
 	private ArrayList<Component> pov = new ArrayList<Component>();
+	/** The rumblers exposed by the controller */
+	private Rumbler[] rumblers;
 	/** The state of the buttons last check */
 	private boolean[] buttonState;
 	/** The values that were read from the pov last check */
@@ -86,7 +89,7 @@
 	 * @param index The index this controller has been assigned to
 	 * @param target The target JInput controller this class is wrapping
 	 */
-	JInputController(int index,net.java.games.input.Controller target) {
+	JInputController(final int index, net.java.games.input.Controller target) {
 		this.target = target;
 		this.index = index;
 
@@ -148,6 +151,8 @@
 			axesMax[i] = 1.0f;
 			deadZones[i] = 0.05f;
 		}
+		
+		rumblers = target.getRumblers();
 	}
 
 	/*
@@ -506,5 +511,16 @@
 		return 0;
 	}
 
+	public int getRumblerCount() {
+		return rumblers.length;
+	}
+	
+	public String getRumblerName(final int index) {
+		return rumblers[index].getAxisName();
+	}
+	
+	public void setRumblerStrength(final int index, final float strength) {
+		rumblers[index].rumble(strength);
+	}
 
 }


Could this be added to the LWJGL repository please?

Unfortunately, on OSX with a PS3 controller it doesn't expose any rumblers. That might be JInput or OSX, I haven't got to the bottom of that yet. And I'm going to test on Win7 with a few pads soon and chase up how well they work (or not).

kappa