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);
|
UIElement fpsCounter = new UIElement(texTest.getObj(), engine);
|
||||||
|
|
||||||
|
texTest.linkToUIElement(fpsCounter);
|
||||||
|
|
||||||
long timer = System.currentTimeMillis();
|
long timer = System.currentTimeMillis();
|
||||||
long lastFrame;
|
long lastFrame;
|
||||||
int frame = 0;
|
int frame = 0;
|
||||||
|
@ -22,6 +22,10 @@ public class Vector3f {
|
|||||||
this.z = z;
|
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){
|
public Vector3f divXY(float div){
|
||||||
return new Vector3f(this.x / div, this.y / div, this.z);
|
return new Vector3f(this.x / div, this.y / div, this.z);
|
||||||
}
|
}
|
||||||
|
@ -12,12 +12,16 @@ public class Text {
|
|||||||
private final float size;
|
private final float size;
|
||||||
private final Engine engine;
|
private final Engine engine;
|
||||||
private final float zPos;
|
private final float zPos;
|
||||||
|
private UIElement linkedUIElement;
|
||||||
|
|
||||||
|
private Vector3f transformation;
|
||||||
|
|
||||||
public Text(String text, float z, float size, Engine engine){
|
public Text(String text, float z, float size, Engine engine){
|
||||||
this.charList = new ArrayList<>();
|
this.charList = new ArrayList<>();
|
||||||
this.zPos = z;
|
this.zPos = z;
|
||||||
this.size = size;
|
this.size = size;
|
||||||
this.engine = engine;
|
this.engine = engine;
|
||||||
|
this.transformation = new Vector3f();
|
||||||
this.textToArrayObjectGl(text);
|
this.textToArrayObjectGl(text);
|
||||||
this.addCharListInEngine();
|
this.addCharListInEngine();
|
||||||
}
|
}
|
||||||
@ -38,9 +42,17 @@ public class Text {
|
|||||||
|
|
||||||
private void addCharInEngine(int i, ObjectGl obj){
|
private void addCharInEngine(int i, ObjectGl obj){
|
||||||
obj.translate(new Vector3f(i * 10.0f * this.size, 0.0f, 0.0f));
|
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);
|
this.engine.add_objectGl(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void linkToUIElement(UIElement ui){
|
||||||
|
this.linkedUIElement = ui;
|
||||||
|
}
|
||||||
|
|
||||||
public void setNewText(String text){
|
public void setNewText(String text){
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (ObjectGl obj : this.charList) {
|
for (ObjectGl obj : this.charList) {
|
||||||
@ -59,7 +71,7 @@ public class Text {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void translate(Vector3f vec){
|
public void translate(Vector3f vec){
|
||||||
// TODO ET LA TRANSLATION DES NOUVEAUX ELEMENTS ?????????????????
|
transformation = transformation.addXYZ(vec);
|
||||||
for (ObjectGl obj : this.charList){
|
for (ObjectGl obj : this.charList){
|
||||||
obj.translate(vec);
|
obj.translate(vec);
|
||||||
}
|
}
|
||||||
@ -68,6 +80,7 @@ public class Text {
|
|||||||
public void remove(){
|
public void remove(){
|
||||||
for (ObjectGl obj : this.charList){
|
for (ObjectGl obj : this.charList){
|
||||||
this.engine.remove_objectGl(obj);
|
this.engine.remove_objectGl(obj);
|
||||||
|
if (linkedUIElement != null) linkedUIElement.removeObj(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,6 +92,7 @@ public class Text {
|
|||||||
int j = 0;
|
int j = 0;
|
||||||
for (ObjectGl objectGl : this.charList){
|
for (ObjectGl objectGl : this.charList){
|
||||||
if (j >= i) this.engine.remove_objectGl(objectGl);
|
if (j >= i) this.engine.remove_objectGl(objectGl);
|
||||||
|
if (linkedUIElement != null) linkedUIElement.removeObj(objectGl);
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
this.charList = this.charList.subList(0, i);
|
this.charList = this.charList.subList(0, i);
|
||||||
|
@ -11,24 +11,36 @@ public class UIElement {
|
|||||||
|
|
||||||
private List<ObjectGl> objs;
|
private List<ObjectGl> objs;
|
||||||
private Engine engine;
|
private Engine engine;
|
||||||
|
private Vector3f transformation;
|
||||||
|
|
||||||
public UIElement(List<ObjectGl> objs, Engine engine){
|
public UIElement(List<ObjectGl> objs, Engine engine){
|
||||||
this.objs = new ArrayList<>();
|
this.objs = new ArrayList<>();
|
||||||
this.objs.addAll(objs);
|
this.objs.addAll(objs);
|
||||||
this.engine = engine;
|
this.engine = engine;
|
||||||
|
this.transformation = new Vector3f();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addObj(ObjectGl obj){
|
public void addObj(ObjectGl obj){
|
||||||
|
obj.translate(this.transformation);
|
||||||
this.objs.add(obj);
|
this.objs.add(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addObj(List<ObjectGl> objs){
|
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(){
|
public void update(){
|
||||||
|
Vector3f translationViewPoint = new Vector3f(-engine.transformationView.x, engine.transformationView.y);
|
||||||
|
this.transformation = this.transformation.addXYZ(translationViewPoint);
|
||||||
for (ObjectGl obj : this.objs){
|
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