diff --git a/src/engine/Engine.java b/src/engine/Engine.java index dcebdcb..ade39db 100644 --- a/src/engine/Engine.java +++ b/src/engine/Engine.java @@ -1,7 +1,6 @@ package engine; -import engine.input.Input; -//import engine.input.gamepadInput; +import engine.input.KeyboardInput; import engine.input.GamepadInput; import engine.math.*; import engine.object.*; @@ -73,7 +72,7 @@ public class Engine { // On met la fenêtre au centre de l'écran principale glfwSetWindowPos(getWindow(), (vidmode.width() - width) / 2, (vidmode.height() - height) / 2); - glfwSetKeyCallback(getWindow(), new Input()); + glfwSetKeyCallback(getWindow(), new KeyboardInput()); glfwSetInputMode(getWindow(), GLFW_STICKY_KEYS, GLFW_TRUE); // Contexte = zone cible des rendus diff --git a/src/engine/input/GamepadInput.java b/src/engine/input/GamepadInput.java index 319bc31..9b68c50 100644 --- a/src/engine/input/GamepadInput.java +++ b/src/engine/input/GamepadInput.java @@ -5,7 +5,7 @@ import engine.math.Vector3f; import java.nio.ByteBuffer; import java.nio.FloatBuffer; -import static engine.input.inputConst.*; +import static engine.input.InputConst.*; import static org.lwjgl.glfw.GLFW.*; /* Buttons 0 : Croix / A @@ -36,6 +36,8 @@ import static org.lwjgl.glfw.GLFW.*; public class GamepadInput { private final int gamepadNum; + private ByteBuffer gamepadButton; + private FloatBuffer gamepadAxes; public boolean buttonA_pressed ; public boolean buttonB_pressed ; @@ -97,9 +99,10 @@ public class GamepadInput { this.RT_pressed = false; } - public void inputRefresh() { - ByteBuffer gamepadButton = glfwGetJoystickButtons(this.gamepadNum); - FloatBuffer gamepadAxes = glfwGetJoystickAxes(this.gamepadNum); + public void inputRefresh() { + + this.gamepadButton = glfwGetJoystickButtons(this.gamepadNum); + this.gamepadAxes = glfwGetJoystickAxes(this.gamepadNum); assert gamepadAxes != null; assert gamepadButton != null; @@ -153,7 +156,7 @@ public class GamepadInput { } public boolean checkPressed(int keyCode){ - ByteBuffer gamepadButton = glfwGetJoystickButtons(GLFW_JOYSTICK_1); + this.gamepadButton = glfwGetJoystickButtons(GLFW_JOYSTICK_1); assert gamepadButton != null; @@ -161,16 +164,12 @@ public class GamepadInput { } /** - * - * @param axisId - * @return + * Envoie la position du stick pointé par axisId sous forme de direction général (9 directions) + * @param axisId l'identifiant du joystick (AXE X) + * @return la direction du stick valeur possible : RIGHT, UPPER_RIGHT, UP, UPPER_LEFT, LEFT, LOWER_LEFT, DOWN, LOWER_RIGHT, CENTER; */ 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); @@ -191,16 +190,12 @@ public class GamepadInput { } /** - * + * Envoie la position du stick pointé par axisID (AXE X) sous forme de Vecteur * @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); diff --git a/src/engine/input/inputConst.java b/src/engine/input/InputConst.java similarity index 95% rename from src/engine/input/inputConst.java rename to src/engine/input/InputConst.java index 4fb4fc1..e45db72 100644 --- a/src/engine/input/inputConst.java +++ b/src/engine/input/InputConst.java @@ -1,6 +1,6 @@ package engine.input; -public class inputConst { +public class InputConst { /* Button ID */ diff --git a/src/engine/input/Input.java b/src/engine/input/KeyboardInput.java similarity index 92% rename from src/engine/input/Input.java rename to src/engine/input/KeyboardInput.java index e734f2d..25fe04c 100644 --- a/src/engine/input/Input.java +++ b/src/engine/input/KeyboardInput.java @@ -12,7 +12,7 @@ import java.nio.FloatBuffer; import static org.lwjgl.glfw.GLFW.*; import static org.lwjgl.opengl.GL11.*; -public class Input extends GLFWKeyCallback { +public class KeyboardInput extends GLFWKeyCallback { public static boolean[] keys = new boolean[65536]; @@ -89,18 +89,18 @@ public class Input extends GLFWKeyCallback { public static void keyboardInput(ObjectGl token, int speed) { boolean keyPressed = false; - if (Input.isKeyDown(GLFW.GLFW_KEY_S)) { + if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_S)) { token.setTextureWrap(161,260,56,59, ObjectGl.STICK_BOTTOM); keyPressed = true; - } else if (Input.isKeyDown(GLFW.GLFW_KEY_W)) { + } else if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_W)) { keyPressed = true; } - if (Input.isKeyDown(GLFW.GLFW_KEY_A)) { + if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_A)) { token.translate(new Vector3f (speed * -5.0f, 0.0f, 0.0f)); token.setTextureWrap(121,0,57,82, ObjectGl.STICK_TOP); keyPressed = true; } - else if (Input.isKeyDown(GLFW.GLFW_KEY_D)) { + else if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_D)) { token.translate(new Vector3f (speed * 5.0f, 0.0f, 0.0f)); token.setTextureWrap(178,0,62,82, ObjectGl.STICK_TOP); keyPressed = true;