Improved UIElement and Text
This commit is contained in:
parent
0dc5081bff
commit
0a8b5e7e7c
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -11,24 +11,36 @@ public class UIElement {
|
||||
|
||||
private List<ObjectGl> objs;
|
||||
private Engine engine;
|
||||
private Vector3f transformation;
|
||||
|
||||
public UIElement(List<ObjectGl> 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<ObjectGl> 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
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user