getAxisDiscreet && getAxisContinuous added
This commit is contained in:
parent
f4b7d5752d
commit
62b888da92
@ -215,14 +215,16 @@ public class Engine {
|
|||||||
lastFrame = System.currentTimeMillis();
|
lastFrame = System.currentTimeMillis();
|
||||||
// Game logic should fit here
|
// Game logic should fit here
|
||||||
|
|
||||||
if (present) { //sprite //bindings
|
if (present) {
|
||||||
GamepadInput gamepad1 = new GamepadInput(GLFW_JOYSTICK_1, false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false);
|
GamepadInput gamepad1 = new GamepadInput(GLFW_JOYSTICK_1);
|
||||||
gamepad1.inputRefresh();
|
gamepad1.inputRefresh();
|
||||||
|
|
||||||
System.out.println( " \n left :" + gamepad1.leftJoyLeft +
|
// System.out.println( " \n left :" + gamepad1.leftJoyLeft +
|
||||||
" \n right :" + gamepad1.leftJoyRight +
|
// " \n right :" + gamepad1.leftJoyRight +
|
||||||
" \n down :" + gamepad1.leftJoyDown +
|
// " \n down :" + gamepad1.leftJoyDown +
|
||||||
" \n up :" + gamepad1.leftJoyUp);
|
// " \n up :" + gamepad1.leftJoyUp);
|
||||||
|
|
||||||
|
System.out.println(gamepad1.getAxisDiscreet(GLFW_GAMEPAD_AXIS_LEFT_X));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Input.keyboardInput(zangief, speed);
|
// Input.keyboardInput(zangief, speed);
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package engine.input;
|
package engine.input;
|
||||||
|
|
||||||
|
import engine.math.Vector3f;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.FloatBuffer;
|
import java.nio.FloatBuffer;
|
||||||
|
|
||||||
import static engine.input.inputVariables.*;
|
import static engine.input.inputConst.*;
|
||||||
import static org.lwjgl.glfw.GLFW.*;
|
import static org.lwjgl.glfw.GLFW.*;
|
||||||
/* Buttons
|
/* Buttons
|
||||||
0 : Croix / A
|
0 : Croix / A
|
||||||
@ -67,35 +69,32 @@ public class GamepadInput {
|
|||||||
public boolean LT_pressed ;
|
public boolean LT_pressed ;
|
||||||
public boolean RT_pressed;
|
public boolean RT_pressed;
|
||||||
|
|
||||||
public GamepadInput (int gamepadNum, boolean buttonA_pressed,boolean buttonB_pressed,boolean buttonY_pressed, boolean buttonX_pressed, boolean LB_pressed,
|
public GamepadInput (int gamepadNum){
|
||||||
boolean RB_pressed, boolean select_pressed, boolean start_pressed,boolean R_JoyClick_pressed, boolean L_JoyClick_pressed , boolean up_pressed,
|
|
||||||
boolean down_pressed,boolean left_pressed,boolean right_pressed,boolean leftJoyRight,boolean leftJoyLeft,boolean leftJoyDown, boolean leftJoyUp,
|
|
||||||
boolean rightJoyLeft, boolean rightJoyRight, boolean rightJoyDown,boolean rightJoyUp,boolean LT_pressed, boolean RT_pressed){
|
|
||||||
this.gamepadNum = gamepadNum;
|
this.gamepadNum = gamepadNum;
|
||||||
this.buttonA_pressed = buttonA_pressed;
|
this.buttonA_pressed = false;
|
||||||
this.buttonB_pressed = buttonB_pressed;
|
this.buttonB_pressed = false;
|
||||||
this.buttonY_pressed = buttonY_pressed;
|
this.buttonY_pressed = false;
|
||||||
this.buttonX_pressed =buttonX_pressed;
|
this.buttonX_pressed = false;
|
||||||
this.LB_pressed =LB_pressed;
|
this.LB_pressed = false;
|
||||||
this.RB_pressed =RB_pressed;
|
this.RB_pressed = false;
|
||||||
this.select_pressed =select_pressed;
|
this.select_pressed = false;
|
||||||
this.start_pressed =start_pressed;
|
this.start_pressed = false;
|
||||||
this.R_JoyClick_pressed =R_JoyClick_pressed;
|
this.R_JoyClick_pressed = false;
|
||||||
this.L_JoyClick_pressed =L_JoyClick_pressed;
|
this.L_JoyClick_pressed = false;
|
||||||
this.up_pressed =up_pressed;
|
this.up_pressed = false;
|
||||||
this.down_pressed =down_pressed;
|
this.down_pressed = false;
|
||||||
this.left_pressed =left_pressed;
|
this.left_pressed = false;
|
||||||
this.right_pressed =right_pressed;
|
this.right_pressed = false;
|
||||||
this.leftJoyRight =leftJoyRight;
|
this.leftJoyRight = false;
|
||||||
this.leftJoyLeft =leftJoyLeft;
|
this.leftJoyLeft = false;
|
||||||
this.leftJoyDown =leftJoyDown;
|
this.leftJoyDown = false;
|
||||||
this.leftJoyUp =leftJoyUp;
|
this.leftJoyUp = false;
|
||||||
this.rightJoyLeft =rightJoyLeft;
|
this.rightJoyLeft = false;
|
||||||
this.rightJoyRight =rightJoyRight;
|
this.rightJoyRight = false;
|
||||||
this.rightJoyDown =rightJoyDown;
|
this.rightJoyDown = false;
|
||||||
this.rightJoyUp =rightJoyUp;
|
this.rightJoyUp = false;
|
||||||
this.LT_pressed =LT_pressed;
|
this.LT_pressed = false;
|
||||||
this.RT_pressed =RT_pressed;
|
this.RT_pressed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void inputRefresh() {
|
public void inputRefresh() {
|
||||||
@ -155,12 +154,62 @@ public class GamepadInput {
|
|||||||
|
|
||||||
public boolean checkPressed(int keyCode){
|
public boolean checkPressed(int keyCode){
|
||||||
ByteBuffer gamepadButton = glfwGetJoystickButtons(GLFW_JOYSTICK_1);
|
ByteBuffer gamepadButton = glfwGetJoystickButtons(GLFW_JOYSTICK_1);
|
||||||
FloatBuffer gamepadAxes = glfwGetJoystickAxes(GLFW_JOYSTICK_1);
|
|
||||||
|
|
||||||
assert gamepadAxes != null;
|
|
||||||
assert gamepadButton != null;
|
assert gamepadButton != null;
|
||||||
|
|
||||||
return gamepadButton.get(keyCode) == 1;
|
return gamepadButton.get(keyCode) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param axisId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getAxisDiscreet(int axisId){
|
||||||
|
|
||||||
|
FloatBuffer gamepadAxes = glfwGetJoystickAxes(GLFW_JOYSTICK_1);
|
||||||
|
|
||||||
|
assert gamepadAxes != null;
|
||||||
|
|
||||||
|
float x = gamepadAxes.get(axisId);
|
||||||
|
float y = gamepadAxes.get(axisId + 1);
|
||||||
|
|
||||||
|
float magnitude = (float) Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
|
||||||
|
float angle = (float) Math.toDegrees(2 * Math.atan(y /(x + magnitude)));
|
||||||
|
|
||||||
|
if (magnitude < 0.1) return CENTER;
|
||||||
|
if (angle < 22.5 && angle > -22.5) return RIGHT;
|
||||||
|
else if (angle > -67.5 && angle < -22.5) return UPPER_RIGHT;
|
||||||
|
else if (angle > -112.5 && angle < -67.5) return UP;
|
||||||
|
else if (angle > -157.5 && angle < -112.5) return UPPER_LEFT;
|
||||||
|
else if (angle < -157.5 || angle > 157.5) return LEFT;
|
||||||
|
else if (angle < 157.5 && angle > 112.5) return LOWER_LEFT;
|
||||||
|
else if (angle < 112.5 && angle > 67.5) return DOWN;
|
||||||
|
else if (angle < 67.5 && angle > 22.5) return LOWER_RIGHT;
|
||||||
|
|
||||||
|
return -1; // TEST
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param axisId l'identifiant du joystick (AXE X)
|
||||||
|
* @return un Vecteur représentant la position actuel du joystick
|
||||||
|
*/
|
||||||
|
public Vector3f getAxisContinuous(int axisId){
|
||||||
|
|
||||||
|
FloatBuffer gamepadAxes = glfwGetJoystickAxes(GLFW_JOYSTICK_1);
|
||||||
|
|
||||||
|
assert gamepadAxes != null;
|
||||||
|
|
||||||
|
float x = gamepadAxes.get(axisId);
|
||||||
|
float y = gamepadAxes.get(axisId + 1);
|
||||||
|
|
||||||
|
if (x < 0.1 && x > -0.1) x = 0;
|
||||||
|
if (y < 0.1 && y > -0.1) y = 0;
|
||||||
|
|
||||||
|
System.out.println("x: " + x + " y: " + y);
|
||||||
|
|
||||||
|
return new Vector3f(x,y);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
17
src/engine/input/inputConst.java
Normal file
17
src/engine/input/inputConst.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package engine.input;
|
||||||
|
|
||||||
|
public class inputConst {
|
||||||
|
/*
|
||||||
|
Button ID
|
||||||
|
*/
|
||||||
|
public final static int buttonA=0, buttonB=1, buttonX=2, buttonY=3, LB = 4, RB = 5, select = 6, start = 7,
|
||||||
|
L_JoystickClick = 8, R_JoystickClick =9, up = 10, right = 11, down = 12, left = 13;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Axis ID
|
||||||
|
*/
|
||||||
|
public final static int leftJoyX_Axe = 0, leftJoyY_Axe = 1, rightJoyX_Axe = 2, rightJoyY_Axe = 3, LT = 4, RT = 5;
|
||||||
|
|
||||||
|
public final static int RIGHT = 0, UPPER_RIGHT = 1, UP = 2, UPPER_LEFT = 3, LEFT = 4, LOWER_LEFT = 5,
|
||||||
|
DOWN = 6, LOWER_RIGHT = 7, CENTER = 8;
|
||||||
|
}
|
@ -1,7 +0,0 @@
|
|||||||
package engine.input;
|
|
||||||
|
|
||||||
public class inputVariables {
|
|
||||||
public final static int buttonA=0, buttonB=1, buttonX=2, buttonY=3, LB = 4, RB = 5, select = 6, start = 7,
|
|
||||||
L_JoystickClick = 8, R_JoystickClick =9, up = 10, right = 11, down = 12, left = 13,
|
|
||||||
leftJoyX_Axe = 0, leftJoyY_Axe = 1, rightJoyX_Axe = 2, rightJoyY_Axe = 3, LT = 4, RT = 5;
|
|
||||||
}
|
|
@ -10,6 +10,11 @@ public class Vector3f {
|
|||||||
z = 0.0f;
|
z = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vector3f(float x, float y){
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
public Vector3f(float x, float y, float z){
|
public Vector3f(float x, float y, float z){
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user