Oune poquito de docito

+ Rename de certaine classe pour qu'elles respectent les conventions
This commit is contained in:
Antoine 2021-06-01 22:33:11 +02:00
parent 62b888da92
commit cf7a1ed85b
4 changed files with 20 additions and 26 deletions

View File

@ -1,7 +1,6 @@
package engine; package engine;
import engine.input.Input; import engine.input.KeyboardInput;
//import engine.input.gamepadInput;
import engine.input.GamepadInput; import engine.input.GamepadInput;
import engine.math.*; import engine.math.*;
import engine.object.*; import engine.object.*;
@ -73,7 +72,7 @@ public class Engine {
// On met la fenêtre au centre de l'écran principale // On met la fenêtre au centre de l'écran principale
glfwSetWindowPos(getWindow(), (vidmode.width() - width) / 2, (vidmode.height() - height) / 2); 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); glfwSetInputMode(getWindow(), GLFW_STICKY_KEYS, GLFW_TRUE);
// Contexte = zone cible des rendus // Contexte = zone cible des rendus

View File

@ -5,7 +5,7 @@ import engine.math.Vector3f;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.FloatBuffer; import java.nio.FloatBuffer;
import static engine.input.inputConst.*; 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
@ -36,6 +36,8 @@ import static org.lwjgl.glfw.GLFW.*;
public class GamepadInput { public class GamepadInput {
private final int gamepadNum; private final int gamepadNum;
private ByteBuffer gamepadButton;
private FloatBuffer gamepadAxes;
public boolean buttonA_pressed ; public boolean buttonA_pressed ;
public boolean buttonB_pressed ; public boolean buttonB_pressed ;
@ -98,8 +100,9 @@ public class GamepadInput {
} }
public void inputRefresh() { public void inputRefresh() {
ByteBuffer gamepadButton = glfwGetJoystickButtons(this.gamepadNum);
FloatBuffer gamepadAxes = glfwGetJoystickAxes(this.gamepadNum); this.gamepadButton = glfwGetJoystickButtons(this.gamepadNum);
this.gamepadAxes = glfwGetJoystickAxes(this.gamepadNum);
assert gamepadAxes != null; assert gamepadAxes != null;
assert gamepadButton != null; assert gamepadButton != null;
@ -153,7 +156,7 @@ public class GamepadInput {
} }
public boolean checkPressed(int keyCode){ public boolean checkPressed(int keyCode){
ByteBuffer gamepadButton = glfwGetJoystickButtons(GLFW_JOYSTICK_1); this.gamepadButton = glfwGetJoystickButtons(GLFW_JOYSTICK_1);
assert gamepadButton != null; assert gamepadButton != null;
@ -161,16 +164,12 @@ public class GamepadInput {
} }
/** /**
* * Envoie la position du stick pointé par axisId sous forme de direction général (9 directions)
* @param axisId * @param axisId l'identifiant du joystick (AXE X)
* @return * @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){ public int getAxisDiscreet(int axisId){
FloatBuffer gamepadAxes = glfwGetJoystickAxes(GLFW_JOYSTICK_1);
assert gamepadAxes != null;
float x = gamepadAxes.get(axisId); float x = gamepadAxes.get(axisId);
float y = gamepadAxes.get(axisId + 1); 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) * @param axisId l'identifiant du joystick (AXE X)
* @return un Vecteur représentant la position actuel du joystick * @return un Vecteur représentant la position actuel du joystick
*/ */
public Vector3f getAxisContinuous(int axisId){ public Vector3f getAxisContinuous(int axisId){
FloatBuffer gamepadAxes = glfwGetJoystickAxes(GLFW_JOYSTICK_1);
assert gamepadAxes != null;
float x = gamepadAxes.get(axisId); float x = gamepadAxes.get(axisId);
float y = gamepadAxes.get(axisId + 1); float y = gamepadAxes.get(axisId + 1);

View File

@ -1,6 +1,6 @@
package engine.input; package engine.input;
public class inputConst { public class InputConst {
/* /*
Button ID Button ID
*/ */

View File

@ -12,7 +12,7 @@ import java.nio.FloatBuffer;
import static org.lwjgl.glfw.GLFW.*; import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.opengl.GL11.*;
public class Input extends GLFWKeyCallback { public class KeyboardInput extends GLFWKeyCallback {
public static boolean[] keys = new boolean[65536]; public static boolean[] keys = new boolean[65536];
@ -89,18 +89,18 @@ public class Input extends GLFWKeyCallback {
public static void keyboardInput(ObjectGl token, int speed) { public static void keyboardInput(ObjectGl token, int speed) {
boolean keyPressed = false; 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); token.setTextureWrap(161,260,56,59, ObjectGl.STICK_BOTTOM);
keyPressed = true; keyPressed = true;
} else if (Input.isKeyDown(GLFW.GLFW_KEY_W)) { } else if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_W)) {
keyPressed = true; 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.translate(new Vector3f (speed * -5.0f, 0.0f, 0.0f));
token.setTextureWrap(121,0,57,82, ObjectGl.STICK_TOP); token.setTextureWrap(121,0,57,82, ObjectGl.STICK_TOP);
keyPressed = true; 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.translate(new Vector3f (speed * 5.0f, 0.0f, 0.0f));
token.setTextureWrap(178,0,62,82, ObjectGl.STICK_TOP); token.setTextureWrap(178,0,62,82, ObjectGl.STICK_TOP);
keyPressed = true; keyPressed = true;