diff --git a/src/engine/Engine.java b/src/engine/Engine.java index 1280760..d22967b 100644 --- a/src/engine/Engine.java +++ b/src/engine/Engine.java @@ -238,6 +238,8 @@ public class Engine { UIElement fpsCounter = new UIElement(texTest.getObj(), engine); + texTest.linkToUIElement(fpsCounter); + long timer = System.currentTimeMillis(); long lastFrame; int frame = 0; diff --git a/src/engine/math/Vector3f.java b/src/engine/math/Vector3f.java index 15fc396..3104762 100644 --- a/src/engine/math/Vector3f.java +++ b/src/engine/math/Vector3f.java @@ -22,6 +22,10 @@ public class Vector3f { this.z = z; } + public Vector3f addXYZ(Vector3f vec){ + return new Vector3f(this.x + vec.x, this.y + vec.y, this.z += vec.z); + } + public Vector3f divXY(float div){ return new Vector3f(this.x / div, this.y / div, this.z); } diff --git a/src/engine/object/Text.java b/src/engine/object/Text.java index 9dea0b2..748e36a 100644 --- a/src/engine/object/Text.java +++ b/src/engine/object/Text.java @@ -12,12 +12,16 @@ public class Text { private final float size; private final Engine engine; private final float zPos; + private UIElement linkedUIElement; + + private Vector3f transformation; public Text(String text, float z, float size, Engine engine){ this.charList = new ArrayList<>(); this.zPos = z; this.size = size; this.engine = engine; + this.transformation = new Vector3f(); this.textToArrayObjectGl(text); this.addCharListInEngine(); } @@ -38,9 +42,17 @@ public class Text { private void addCharInEngine(int i, ObjectGl obj){ obj.translate(new Vector3f(i * 10.0f * this.size, 0.0f, 0.0f)); + obj.translate(transformation); + if (linkedUIElement != null){ + linkedUIElement.addObj(obj); + } this.engine.add_objectGl(obj); } + public void linkToUIElement(UIElement ui){ + this.linkedUIElement = ui; + } + public void setNewText(String text){ int i = 0; for (ObjectGl obj : this.charList) { @@ -59,7 +71,7 @@ public class Text { } public void translate(Vector3f vec){ - // TODO ET LA TRANSLATION DES NOUVEAUX ELEMENTS ????????????????? + transformation = transformation.addXYZ(vec); for (ObjectGl obj : this.charList){ obj.translate(vec); } @@ -68,6 +80,7 @@ public class Text { public void remove(){ for (ObjectGl obj : this.charList){ this.engine.remove_objectGl(obj); + if (linkedUIElement != null) linkedUIElement.removeObj(obj); } } @@ -79,6 +92,7 @@ public class Text { int j = 0; for (ObjectGl objectGl : this.charList){ if (j >= i) this.engine.remove_objectGl(objectGl); + if (linkedUIElement != null) linkedUIElement.removeObj(objectGl); j++; } this.charList = this.charList.subList(0, i); diff --git a/src/engine/object/UIElement.java b/src/engine/object/UIElement.java index c318c40..bc6d20e 100644 --- a/src/engine/object/UIElement.java +++ b/src/engine/object/UIElement.java @@ -11,24 +11,36 @@ public class UIElement { private List objs; private Engine engine; + private Vector3f transformation; public UIElement(List objs, Engine engine){ this.objs = new ArrayList<>(); this.objs.addAll(objs); this.engine = engine; + this.transformation = new Vector3f(); } public void addObj(ObjectGl obj){ + obj.translate(this.transformation); this.objs.add(obj); } public void addObj(List objs){ - this.objs.addAll(objs); + for (ObjectGl obj : objs){ + obj.translate(this.transformation); + this.objs.add(obj); + } + } + + public void removeObj(ObjectGl obj){ + } public void update(){ + Vector3f translationViewPoint = new Vector3f(-engine.transformationView.x, engine.transformationView.y); + this.transformation = this.transformation.addXYZ(translationViewPoint); 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 + obj.translate(translationViewPoint); // Tous les elmts font le même déplacement que la caméra } }