From 9612db9b4966dae17cea09bd7c3337ce5464b009 Mon Sep 17 00:00:00 2001 From: Antoine Date: Fri, 28 May 2021 13:02:48 +0200 Subject: [PATCH 1/7] =?UTF-8?q?Modification=20du=20constructeur=20d'Engine?= =?UTF-8?q?=20ajout=20de=20la=20largeur=20et=20la=20hauteur=20de=20la=20fe?= =?UTF-8?q?n=C3=AAtre=20ainsi=20que=20l'aspect=20ratio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shaders/StylishShaders/PerlinNoise.glsl | 4 ++-- src/engine/Engine.java | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/shaders/StylishShaders/PerlinNoise.glsl b/shaders/StylishShaders/PerlinNoise.glsl index b3f4362..7ff344f 100644 --- a/shaders/StylishShaders/PerlinNoise.glsl +++ b/shaders/StylishShaders/PerlinNoise.glsl @@ -18,14 +18,14 @@ void main() vec2 fragCoordTemp = fragCoord; fragCoordTemp = 8. * fragCoordTemp / fragCoordTemp.y-vec2(7,4); - perlinNoise = sin(perlinNoise + time); + perlinNoise = sin(perlinNoise + time*15); perlinNoise = mix(perlinNoise,color,0.5f); vec4 tex = texture(texture1, texCoord); if (tex.a == 0.0){ FragColor = tex; } else{ - FragColor = mix(tex, perlinNoise, 0.5); + FragColor = mix(tex, perlinNoise, 0.5f); FragColor.a = 1.0f; } } diff --git a/src/engine/Engine.java b/src/engine/Engine.java index b09c2ca..70f2c0e 100644 --- a/src/engine/Engine.java +++ b/src/engine/Engine.java @@ -27,14 +27,18 @@ public class Engine { private boolean running; + private final int width; + private final int height; + /** * Create the engine and initial attributes use .init() to start the engine */ - public Engine() { + public Engine(int width, int height, float aspectRatio) { this.running = false; this.objectsGl = new ArrayList<>(); - float width = 1280.0f; - ObjectGl.projection = Matrix4f.orthographic(-width, width, -width * 9.0f / 16.0f, width * 9.0f / 16.0f, 0.1f, 100.0f); + this.width = width; + this.height = height; + ObjectGl.projection = Matrix4f.orthographic(-width, width, -width * aspectRatio, width * aspectRatio, 0.1f, 100.0f); ObjectGl.view = Matrix4f.translate(new Vector3f(0.0f,0.0f,1.0f)); } @@ -54,8 +58,8 @@ public class Engine { glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); //Compatible MAC glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //Le core profile est l'interface 'avancé' d'openGL - int width = 1280; - int height = 720; + int width = this.width; + int height = this.height; this.setWindow(glfwCreateWindow(width, height, "Boulevard Combattant", NULL, NULL)); assert getWindow() != NULL; @@ -115,7 +119,7 @@ public class Engine { /** * Add obj to the render queue - * @param obj + * @param obj ObjectGl to render */ public void add_objectGl(ObjectGl obj){ objectsGl.add(obj); @@ -157,7 +161,7 @@ public class Engine { }; public static void main(String[] args) { - Engine engine = new Engine(); + Engine engine = new Engine(1280, 720, 9.0f/16.0f); int speed = 10 ; //vitesse déplacement Object engine.init(); @@ -170,7 +174,7 @@ public class Engine { zangief.setTextureWrap(58,0,62,84, ObjectGl.STICK_TOP); engine.add_objectGl(zangief); zangief.translate(new Vector3f(-5000.0f,500.0f,10.0f)); - zangief.setColor(new Vector3f(0.0f, 0.0f, 1.0f)); + zangief.setColor(new Vector3f(1.0f, 1.0f, 1.0f)); zangief.useTime = true; zangief.setShader("shaders/StylishShaders/BasicVert.glsl","shaders/StylishShaders/PerlinNoise.glsl"); From 68580ce40b09208e06c5cb292c23d8709a1c09d0 Mon Sep 17 00:00:00 2001 From: Antoine Date: Fri, 28 May 2021 13:37:03 +0200 Subject: [PATCH 2/7] =?UTF-8?q?Correct=20camera:=20l'espace=20de=20jeu=20e?= =?UTF-8?q?st=20compris=20entre=20les=20coordonn=C3=A9es=20-1000:1000=20et?= =?UTF-8?q?=20-1000*aspectRatio:1000*aspectRatio=20Peut-=C3=AAtre=20fix?= =?UTF-8?q?=C3=A9=20l'aspect=20ratio=20du=20jeu=20pour=20ne=20pas=20avoir?= =?UTF-8?q?=20certains=20probl=C3=A8mes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/engine/Engine.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/Engine.java b/src/engine/Engine.java index 70f2c0e..34c6f3c 100644 --- a/src/engine/Engine.java +++ b/src/engine/Engine.java @@ -38,7 +38,7 @@ public class Engine { this.objectsGl = new ArrayList<>(); this.width = width; this.height = height; - ObjectGl.projection = Matrix4f.orthographic(-width, width, -width * aspectRatio, width * aspectRatio, 0.1f, 100.0f); + ObjectGl.projection = Matrix4f.orthographic(-1000, 1000, -1000 * aspectRatio, 1000 * aspectRatio, 0.1f, 100.0f); ObjectGl.view = Matrix4f.translate(new Vector3f(0.0f,0.0f,1.0f)); } From dea8cbd562c3c0148d103457c88329122f5fef59 Mon Sep 17 00:00:00 2001 From: Indy Date: Fri, 28 May 2021 15:07:48 +0200 Subject: [PATCH 3/7] conf file json --- conf/config.json | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 conf/config.json diff --git a/conf/config.json b/conf/config.json new file mode 100644 index 0000000..6d19807 --- /dev/null +++ b/conf/config.json @@ -0,0 +1,24 @@ +{ + + "arena": [ + "arena1.png", + "arena2.png", + "aléatoire" + ], + "nb_players": [ + "1", + "2" + ], + "character1": [ + "character1.png", + "character2.png", + "aléatoire" + ], + "character2": [ + "character1.png", + "character1_swapcolor.png", + "character2.png", + "character2_swapcolor.png", + "aléatoire" + ] +} From 2cbf37511adac864edcdb9267ae1263f68896455 Mon Sep 17 00:00:00 2001 From: Boyeau Indy Date: Fri, 28 May 2021 13:12:18 +0000 Subject: [PATCH 4/7] Update config.json --- conf/config.json | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/conf/config.json b/conf/config.json index 6d19807..42db175 100644 --- a/conf/config.json +++ b/conf/config.json @@ -1,24 +1,23 @@ -{ - - "arena": [ - "arena1.png", - "arena2.png", - "aléatoire" - ], - "nb_players": [ - "1", - "2" - ], - "character1": [ - "character1.png", - "character2.png", - "aléatoire" - ], - "character2": [ - "character1.png", - "character1_swapcolor.png", - "character2.png", - "character2_swapcolor.png", - "aléatoire" - ] -} +{ + "arena": [ + "arena1.png", + "arena2.png", + "alatoire" + ], + "nb_players": [ + "1", + "2" + ], + "character1": [ + "character1.png", + "character2.png", + "alatoire" + ], + "character2": [ + "character1.png", + "character1_swapcolor.png", + "character2.png", + "character2_swapcolor.png", + "alatoire" + ] +} From 3fdcebf93bf6d30e7a1aaad65351039e9901b3b1 Mon Sep 17 00:00:00 2001 From: Boyeau Indy Date: Fri, 28 May 2021 13:12:48 +0000 Subject: [PATCH 5/7] Update config.json --- conf/config.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/conf/config.json b/conf/config.json index 42db175..e891bd8 100644 --- a/conf/config.json +++ b/conf/config.json @@ -2,7 +2,7 @@ "arena": [ "arena1.png", "arena2.png", - "alatoire" + "random" ], "nb_players": [ "1", @@ -11,13 +11,13 @@ "character1": [ "character1.png", "character2.png", - "alatoire" + "random" ], "character2": [ "character1.png", "character1_swapcolor.png", "character2.png", "character2_swapcolor.png", - "alatoire" + "random" ] } From a4573fd3c08ba7f5e5c539d84e7c73f85ca3eb0e Mon Sep 17 00:00:00 2001 From: Indy Date: Fri, 28 May 2021 16:05:30 +0200 Subject: [PATCH 6/7] replace json file --- {conf => src/configuration}/config.json | 6 ++++++ 1 file changed, 6 insertions(+) rename {conf => src/configuration}/config.json (77%) diff --git a/conf/config.json b/src/configuration/config.json similarity index 77% rename from conf/config.json rename to src/configuration/config.json index e891bd8..028c17f 100644 --- a/conf/config.json +++ b/src/configuration/config.json @@ -19,5 +19,11 @@ "character2.png", "character2_swapcolor.png", "random" + ], + "resolution": [ + "1280 x 1024", + "1680 x 1050", + "1920 x 1080", + "800 x 600" ] } From 0185a14b0ba6b3ee9357b8064ef538fb5ba0dc77 Mon Sep 17 00:00:00 2001 From: Antoine Date: Fri, 28 May 2021 18:34:49 +0200 Subject: [PATCH 7/7] Input """cleanup""" --- src/engine/Engine.java | 147 +++++++++-------------------------------- src/engine/Input.java | 89 ++++++++++++++++++++++++- 2 files changed, 119 insertions(+), 117 deletions(-) diff --git a/src/engine/Engine.java b/src/engine/Engine.java index 34c6f3c..534319f 100644 --- a/src/engine/Engine.java +++ b/src/engine/Engine.java @@ -22,7 +22,7 @@ public class Engine { private static long window; private final List objectsGl; - + private static boolean present = glfwJoystickPresent(GLFW_JOYSTICK_1); private boolean running; @@ -39,7 +39,7 @@ public class Engine { this.width = width; this.height = height; ObjectGl.projection = Matrix4f.orthographic(-1000, 1000, -1000 * aspectRatio, 1000 * aspectRatio, 0.1f, 100.0f); - ObjectGl.view = Matrix4f.translate(new Vector3f(0.0f,0.0f,1.0f)); + ObjectGl.view = Matrix4f.translate(new Vector3f(0.0f, 0.0f, 1.0f)); } /** @@ -62,8 +62,8 @@ public class Engine { int height = this.height; this.setWindow(glfwCreateWindow(width, height, "Boulevard Combattant", NULL, NULL)); assert getWindow() != NULL; - - + + System.out.println(present); // On récupère les informations du moniteur principal @@ -71,7 +71,7 @@ public class Engine { assert vidmode != null; // 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()); glfwSetInputMode(getWindow(), GLFW_STICKY_KEYS, GLFW_TRUE); @@ -95,14 +95,14 @@ public class Engine { /** * */ - public void update(){ + public void update() { glfwPollEvents(); } /** * */ - public void render(){ + public void render() { glClearColor(0.2f, 0.3f, 0.3f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -119,25 +119,26 @@ public class Engine { /** * Add obj to the render queue + * * @param obj ObjectGl to render */ - public void add_objectGl(ObjectGl obj){ + public void add_objectGl(ObjectGl obj) { objectsGl.add(obj); } - public void remove_objectGl(ObjectGl obj){ + public void remove_objectGl(ObjectGl obj) { objectsGl.remove(obj); } - public boolean isRunning(){ + public boolean isRunning() { return running; } - public void setRunning(boolean b){ + public void setRunning(boolean b) { running = b; } - public boolean shouldClose(){ + public boolean shouldClose() { return glfwWindowShouldClose(getWindow()); } @@ -153,16 +154,16 @@ public class Engine { * Est appelé àa chaque modification de la taille de la fenêtre, et modifie la taille de la zone de rendu * pour quelle corresponde à la taille de la fenêtre */ - private static final GLFWFramebufferSizeCallback resizeWindow = new GLFWFramebufferSizeCallback(){ + private static final GLFWFramebufferSizeCallback resizeWindow = new GLFWFramebufferSizeCallback() { @Override - public void invoke(long window, int width, int height){ - glViewport(0,0,width,height); + public void invoke(long window, int width, int height) { + glViewport(0, 0, width, height); } }; public static void main(String[] args) { - Engine engine = new Engine(1280, 720, 9.0f/16.0f); - int speed = 10 ; //vitesse déplacement Object + Engine engine = new Engine(1280, 720, 9.0f / 16.0f); + int speed = 10; //vitesse déplacement Object engine.init(); // Add objects to render @@ -170,32 +171,32 @@ public class Engine { String path2 = "textures/awesomeface.png"; - ObjectGl zangief = new ObjectGl(0f,60f,80f,10f, path, null); - zangief.setTextureWrap(58,0,62,84, ObjectGl.STICK_TOP); + ObjectGl zangief = new ObjectGl(0f, 60f, 80f, 10f, path, null); + zangief.setTextureWrap(58, 0, 62, 84, ObjectGl.STICK_TOP); engine.add_objectGl(zangief); - zangief.translate(new Vector3f(-5000.0f,500.0f,10.0f)); + zangief.translate(new Vector3f(-5000.0f, 500.0f, 10.0f)); zangief.setColor(new Vector3f(1.0f, 1.0f, 1.0f)); zangief.useTime = true; - zangief.setShader("shaders/StylishShaders/BasicVert.glsl","shaders/StylishShaders/PerlinNoise.glsl"); + zangief.setShader("shaders/StylishShaders/BasicVert.glsl", "shaders/StylishShaders/PerlinNoise.glsl"); - ObjectGl smiley2 = new ObjectGl(0.0f,500.0f,500.0f, 1f, path2, null); + ObjectGl smiley2 = new ObjectGl(0.0f, 500.0f, 500.0f, 1f, path2, null); engine.add_objectGl(smiley2); - smiley2.translate(new Vector3f(0.0f,0.0f,5.0f)); + smiley2.translate(new Vector3f(0.0f, 0.0f, 5.0f)); long timer = System.currentTimeMillis(); long lastFrame; int frame = 0; boolean nextFrame = false; - while(engine.isRunning()){ + while (engine.isRunning()) { lastFrame = System.currentTimeMillis(); // Game logic should fit here - + if (present) { - gamepadInput(zangief, speed); - } - - keyboardInput(zangief, speed); + Input.gamepadInput(zangief, speed); + } + + Input.keyboardInput(zangief, speed); // input(smiley2, speed); /* @@ -214,96 +215,12 @@ public class Engine { frame = 0; } - while(!nextFrame){ + while (!nextFrame) { nextFrame = System.currentTimeMillis() - lastFrame >= 16.66f; } nextFrame = false; - if(engine.shouldClose()) engine.setRunning(false); + if (engine.shouldClose()) engine.setRunning(false); } } - - private static void gamepadInput(ObjectGl token, int speed) { - ByteBuffer gamepadButton = glfwGetJoystickButtons(GLFW_JOYSTICK_1); - FloatBuffer gamepadAxes = glfwGetJoystickAxes(GLFW_JOYSTICK_1); - - assert gamepadAxes != null; - assert gamepadButton != null; - - String name = GLFW.glfwGetJoystickName(GLFW_JOYSTICK_1); - System.out.println("GamePad Name :" + name); -// for (int i =0 ; i < gamepadAxes.capacity(); i++) { -// System.out.println(i + " :" + gamepadAxes.get(i)); -// } - - - if (gamepadButton.get(0) ==1 ) { // appuie sur croix(PlayStation) A (Xbox) - token.translate(new Vector3f ( 0.0f, speed * 5.0f, 0.0f)); - } - if ( (gamepadAxes.get(2) < -0.1 || gamepadAxes.get(2) > 0.1) ) { // de droite à gauche //joystick gauche - token.translate(new Vector3f (5*speed * gamepadAxes.get(2), 0.0f, 0.0f)); - if ( gamepadAxes.get(2) < -0.1 ){ - token.setTextureWrap(121,0,57,80, ObjectGl.DEFAULT); - }else if (gamepadAxes.get(2) > 0.1) { - token.setTextureWrap(178,0,62,82, ObjectGl.DEFAULT); - } - } - - if ( (gamepadAxes.get(3) < -0.1 || gamepadAxes.get(3) > 0.1) ) { // de haut en bas //joystick gauche - token.translate(new Vector3f (0.0f, -5* speed * gamepadAxes.get(3), 0.0f)); - - } - - /* Buttons - 0 : Croix / A - 1: rond /B - 2: carré / X - 3: triangle / Y - 4: L1 / LB - 5: R1 / RB - 6:select - 7:start - 8:L3 - 9:R3 - 10: haut - 11: droite - 12: bas - 13: gauche - */ - - /* Axes - 0 : left X axe ( right : 1 left -1) - 1: left Y axe ( down : 1 , Up -1) - 2: right X axe ( right : 1 left -1) - 3: right Y axe ( down : 1 , Up -1) - 4:L2 / LT : 1 active, -1 unactive - 5: R2 /RT : 1 active, -1 unactive - */ - - } - - public static void keyboardInput(ObjectGl token, int speed) { - boolean keyPressed = false; - if (Input.isKeyDown(GLFW.GLFW_KEY_S)) { - token.setTextureWrap(161,260,56,59, ObjectGl.STICK_BOTTOM); - keyPressed = true; - } else if (Input.isKeyDown(GLFW.GLFW_KEY_W)) { -// token.translate(new Vector3f (0.0f, speed * 5.0f, 0.0f)); - keyPressed = true; - } - if (Input.isKeyDown(GLFW.GLFW_KEY_A)) { - token.translate(new Vector3f (speed *-5.0f, 0.0f, 0.0f)); -// token.setTextureWrap(121,0,57,80, ObjectGl.STICK_TOP); - token.setTextureWrap(121,0,57,82, ObjectGl.STICK_TOP); - keyPressed = true; - } - else if (Input.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); - token.setTextureWrap(178,0,62,82, ObjectGl.STICK_TOP); - keyPressed = true; - } -// if (!keyPressed) token.setTextureWrap(58,0,62,84, ObjectGl.STICK_TOP); - if (!keyPressed) token.setTextureWrap(58,0,62,82, ObjectGl.STICK_TOP); - } } diff --git a/src/engine/Input.java b/src/engine/Input.java index 194335c..8d88645 100644 --- a/src/engine/Input.java +++ b/src/engine/Input.java @@ -1,8 +1,13 @@ package engine; +import engine.math.Vector3f; +import engine.object.ObjectGl; import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFWKeyCallback; +import java.nio.ByteBuffer; +import java.nio.FloatBuffer; + import static org.lwjgl.glfw.GLFW.*; import static org.lwjgl.opengl.GL11.*; @@ -19,8 +24,88 @@ public class Input extends GLFWKeyCallback { if (glGetInteger(GL_POLYGON_MODE) == GL_FILL) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); else glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } + public static boolean isKeyDown(int keyCode) { return glfwGetKey(Engine.getWindow(), keyCode) == 1; - } - + } + + public static void gamepadInput(ObjectGl token, int speed) { + ByteBuffer gamepadButton = glfwGetJoystickButtons(GLFW_JOYSTICK_1); + FloatBuffer gamepadAxes = glfwGetJoystickAxes(GLFW_JOYSTICK_1); + + assert gamepadAxes != null; + assert gamepadButton != null; + + String name = GLFW.glfwGetJoystickName(GLFW_JOYSTICK_1); + System.out.println("GamePad Name :" + name); +// for (int i =0 ; i < gamepadAxes.capacity(); i++) { +// System.out.println(i + " :" + gamepadAxes.get(i)); +// } + + + if (gamepadButton.get(0) ==1 ) { // appuie sur croix(PlayStation) A (Xbox) + token.translate(new Vector3f( 0.0f, speed * 5.0f, 0.0f)); + } + if ( (gamepadAxes.get(2) < -0.1 || gamepadAxes.get(2) > 0.1) ) { // de droite à gauche //joystick gauche + token.translate(new Vector3f (5 * speed * gamepadAxes.get(2), 0.0f, 0.0f)); + if ( gamepadAxes.get(2) < -0.1 ){ + token.setTextureWrap(121,0,57,80, ObjectGl.DEFAULT); + }else if (gamepadAxes.get(2) > 0.1) { + token.setTextureWrap(178,0,62,82, ObjectGl.DEFAULT); + } + } + + if ( (gamepadAxes.get(3) < -0.1 || gamepadAxes.get(3) > 0.1) ) { // de haut en bas //joystick gauche + token.translate(new Vector3f (0.0f, -5 * speed * gamepadAxes.get(3), 0.0f)); + + } + + /* Buttons + 0 : Croix / A + 1: rond /B + 2: carré / X + 3: triangle / Y + 4: L1 / LB + 5: R1 / RB + 6:select + 7:start + 8:L3 + 9:R3 + 10: haut + 11: droite + 12: bas + 13: gauche + */ + + /* Axes + 0 : left X axe ( right : 1 left -1) + 1: left Y axe ( down : 1 , Up -1) + 2: right X axe ( right : 1 left -1) + 3: right Y axe ( down : 1 , Up -1) + 4:L2 / LT : 1 active, -1 unactive + 5: R2 /RT : 1 active, -1 unactive + */ + + } + + public static void keyboardInput(ObjectGl token, int speed) { + boolean keyPressed = false; + if (Input.isKeyDown(GLFW.GLFW_KEY_S)) { + token.setTextureWrap(161,260,56,59, ObjectGl.STICK_BOTTOM); + keyPressed = true; + } else if (Input.isKeyDown(GLFW.GLFW_KEY_W)) { + keyPressed = true; + } + if (Input.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)) { + token.translate(new Vector3f (speed * 5.0f, 0.0f, 0.0f)); + token.setTextureWrap(178,0,62,82, ObjectGl.STICK_TOP); + keyPressed = true; + } + if (!keyPressed) token.setTextureWrap(58,0,62,82, ObjectGl.STICK_TOP); + } }