From 0dc5081bff57c5e1e0e5628b56235da2599ea6a0 Mon Sep 17 00:00:00 2001 From: Antoine Date: Fri, 4 Jun 2021 00:16:03 +0200 Subject: [PATCH] =?UTF-8?q?Premier=20jet=20pour=20les=20=C3=A9lements=20d'?= =?UTF-8?q?interface=20encore=20pas=20mal=20de=20truc=20=C3=A0=20regler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/engine/Engine.java | 12 +++++++++-- src/engine/math/Vector3f.java | 9 +++++--- src/engine/object/ObjectGl.java | 4 ++-- src/engine/object/Text.java | 11 ++++++++++ src/engine/object/UIElement.java | 35 ++++++++++++++++++++++++++++++++ 5 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 src/engine/object/UIElement.java diff --git a/src/engine/Engine.java b/src/engine/Engine.java index 4acb645..1280760 100644 --- a/src/engine/Engine.java +++ b/src/engine/Engine.java @@ -8,6 +8,7 @@ import engine.sound.*; import org.lwjgl.glfw.GLFWFramebufferSizeCallback; import org.lwjgl.glfw.GLFWVidMode; import org.lwjgl.opengl.GL; +import org.lwjgl.system.CallbackI; import java.util.ArrayList; import java.util.List; @@ -28,6 +29,7 @@ public class Engine { private final int height; private float viewXPos; + public Vector3f transformationView; /** * Create the engine and initial attributes use .init() to start the engine @@ -40,6 +42,7 @@ public class Engine { 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)); this.viewXPos = 0.0f; + this.transformationView = new Vector3f(); } /** @@ -231,6 +234,9 @@ public class Engine { engine.add_objectGl(background); Text texTest = new Text("ABCDEFGHIJKLMNOPQRSTUVWYZ",20.0f, 10, engine); + texTest.translate(new Vector3f(-1000.0f, (float) (-1000.0f * (3.0 / 4.0f) + 100.0f))); + + UIElement fpsCounter = new UIElement(texTest.getObj(), engine); long timer = System.currentTimeMillis(); long lastFrame; @@ -270,8 +276,10 @@ public class Engine { KeyboardInput.keyboardInput(zangief, speed); - Vector3f vecTransView = new Vector3f((-zangief.getXPos() - engine.viewXPos) - 250.0f,0.0f,0.0f); - engine.translateView(vecTransView); + engine.transformationView = new Vector3f((- zangief.getXPos() - engine.viewXPos) - 250.0f,0.0f,0.0f); + engine.translateView(engine.transformationView); + + fpsCounter.update(); /* ******************** diff --git a/src/engine/math/Vector3f.java b/src/engine/math/Vector3f.java index 37cf4de..15fc396 100644 --- a/src/engine/math/Vector3f.java +++ b/src/engine/math/Vector3f.java @@ -22,9 +22,12 @@ public class Vector3f { this.z = z; } - public void divXY(float div){ - this.x /= div; - this.y /= div; + public Vector3f divXY(float div){ + return new Vector3f(this.x / div, this.y / div, this.z); + } + + public Vector3f divXYZ(float div){ + return new Vector3f(this.x / div, this.y / div, this.z / div); } } diff --git a/src/engine/object/ObjectGl.java b/src/engine/object/ObjectGl.java index 1abcef6..91f9e5e 100644 --- a/src/engine/object/ObjectGl.java +++ b/src/engine/object/ObjectGl.java @@ -117,8 +117,8 @@ public class ObjectGl { this.xPos += vec.x; this.yPos += vec.y; this.zPos += vec.z; - vec.divXY(this.scalingFactor); - this.transform = this.transform.multiply(Matrix4f.translate(vec)); + Vector3f vecTemp = vec.divXYZ(this.scalingFactor); + this.transform = this.transform.multiply(Matrix4f.translate(vecTemp)); } /** diff --git a/src/engine/object/Text.java b/src/engine/object/Text.java index 894be31..9dea0b2 100644 --- a/src/engine/object/Text.java +++ b/src/engine/object/Text.java @@ -58,12 +58,23 @@ public class Text { } + public void translate(Vector3f vec){ + // TODO ET LA TRANSLATION DES NOUVEAUX ELEMENTS ????????????????? + for (ObjectGl obj : this.charList){ + obj.translate(vec); + } + } + public void remove(){ for (ObjectGl obj : this.charList){ this.engine.remove_objectGl(obj); } } + public List getObj(){ + return new ArrayList<>(this.charList); + } + private void removeFromIndexToEnd(int i){ int j = 0; for (ObjectGl objectGl : this.charList){ diff --git a/src/engine/object/UIElement.java b/src/engine/object/UIElement.java new file mode 100644 index 0000000..c318c40 --- /dev/null +++ b/src/engine/object/UIElement.java @@ -0,0 +1,35 @@ +package engine.object; + +import engine.Engine; +import engine.math.Vector3f; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public class UIElement { + + private List objs; + private Engine engine; + + public UIElement(List objs, Engine engine){ + this.objs = new ArrayList<>(); + this.objs.addAll(objs); + this.engine = engine; + } + + public void addObj(ObjectGl obj){ + this.objs.add(obj); + } + + public void addObj(List objs){ + this.objs.addAll(objs); + } + + public void update(){ + for (ObjectGl obj : this.objs){ + obj.translate(new Vector3f(-engine.transformationView.x, engine.transformationView.y)); // Tous les elmts font le même déplacement que la caméra + } + } + +}