You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
1.7 KiB
80 lines
1.7 KiB
package sig.modules.Controller;
|
|
|
|
import java.nio.ByteBuffer;
|
|
import java.nio.FloatBuffer;
|
|
import java.util.Arrays;
|
|
|
|
import org.lwjgl.glfw.GLFW;
|
|
|
|
|
|
public class Controller {
|
|
int identifier;
|
|
float[] axes;
|
|
byte[] buttons;
|
|
|
|
public Controller(int identifier) {
|
|
this.identifier=identifier;
|
|
FloatBuffer axisBuffer = GLFW.glfwGetJoystickAxes(identifier);
|
|
axes = new float[axisBuffer.limit()];
|
|
axisBuffer.get(axes);
|
|
ByteBuffer buttonBuffer = GLFW.glfwGetJoystickButtons(identifier);
|
|
buttons = new byte[buttonBuffer.limit()];
|
|
buttonBuffer.get(buttons);
|
|
}
|
|
|
|
public String outputAxes() {
|
|
return Arrays.toString(axes);
|
|
}
|
|
|
|
public String outputButtons() {
|
|
return Arrays.toString(buttons);
|
|
}
|
|
|
|
public float[] getAxes() {
|
|
return axes;
|
|
}
|
|
|
|
public byte[] getButtons() {
|
|
return buttons;
|
|
}
|
|
|
|
public float getAxisValue(int axisNumber) {
|
|
return axes[axisNumber];
|
|
}
|
|
|
|
public byte getButtonValue(int buttonNumber) {
|
|
return buttons[buttonNumber];
|
|
}
|
|
|
|
@Deprecated
|
|
public Type getType() {
|
|
return null;
|
|
}
|
|
|
|
@Deprecated
|
|
public String getName() {
|
|
return null;
|
|
}
|
|
|
|
public void poll() {
|
|
//System.out.println(Glfw.glfwGetJoystickParam(identifier, 1));
|
|
FloatBuffer axisBuffer = GLFW.glfwGetJoystickAxes(identifier);
|
|
axes = new float[axisBuffer.limit()];
|
|
axisBuffer.get(axes);
|
|
ByteBuffer buttonBuffer = GLFW.glfwGetJoystickButtons(identifier);
|
|
buttons = new byte[buttonBuffer.limit()];
|
|
buttonBuffer.get(buttons);
|
|
//System.out.println(outputAxes()+","+outputButtons());
|
|
}
|
|
|
|
@Deprecated
|
|
public Component[] getComponents() {
|
|
return new Component[]{};
|
|
}
|
|
|
|
@Deprecated
|
|
public Component getComponent(Identifier identifier2) {
|
|
return null;
|
|
}
|
|
|
|
}
|
|
|