Hello Guest

[FIXED] Expose rumblers in Controller

  • 1 Replies
  • 8631 Views
[FIXED] Expose rumblers in Controller
« on: April 09, 2012, 14:49:15 »
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:

Code: [Select]

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).
« Last Edit: April 10, 2012, 11:46:10 by kappa »

*

Offline kappa

  • *****
  • 1319
Re: [RFE / Patch] Expose rumblers in Controller
« Reply #1 on: April 10, 2012, 11:45:55 »
thanks, patch committed.