Added UIElementText

This commit is contained in:
Antoine
2021-06-04 22:35:31 +02:00
parent 12b89079ce
commit eaeb8ccee7
5 changed files with 109 additions and 19 deletions

View File

@ -48,7 +48,6 @@ public class UIElement extends UIDummy{
float x = dimension * 2 * this.xPos - dimension;
float y = dimension * ar * 2 * this.yPos - dimension * ar;
obj.translate(new Vector3f(x, y, this.zPos));
System.out.println(x);
// Camera position
obj.translate(new Vector3f(- engine.transformationView.x, engine.transformationView.y));
}

View File

@ -1,6 +1,77 @@
package engine.gui;
import engine.Engine;
import engine.math.Vector3f;
import engine.object.Camera;
import engine.object.ObjectGl;
import engine.object.Text;
import java.util.ArrayList;
import java.util.List;
public class UIElementText extends UIDummy{
private final List<ObjectGl> objs;
private final Engine engine;
private final Camera camera;
private final Text txt;
private float scalingFactor;
private float xPos;
private float yPos;
private float zPos;
/**
* Crée du texte qui suit la caméra
* @param texte le texte à afficher initialement
* @param posX la position relative à la camera souhaité sur l'axe X, 0.0 à l'extreme gauche, 1.0 à l'extreme droite
* @param posY la position relative à la camera souhaité sur l'axe Y, 0.0 à l'extreme bas, 1.0 à l'extreme haut
* @param engine le moteur de rendu depuis lequel UIElement va determiner la camera à tracker
*/
public UIElementText(String texte, float size, float posX, float posY, float posZ, Engine engine){
this.txt = new Text(texte, posZ, size, engine);
this.objs = this.txt.getCharList();
this.engine = engine;
this.camera = engine.getCamera();
this.scalingFactor = size;
this.xPos = posX;
this.yPos = posY;
this.zPos = posZ;
this.getObjInPosition();
}
public void init(){
this.engine.add_objectsGl(objs);
}
public void setText(String txt){
this.txt.setNewText(txt);
}
private void getObjInPosition(){
int i = 0;
for (ObjectGl obj : this.txt.getCharList()){
obj.resetTransform();
obj.scale(new Vector3f(this.scalingFactor, this.scalingFactor, 1.0f));
// Position in the camera space
float dimension = this.camera.getDimension();
float ar = this.camera.getAspectRatio().y / this.camera.getAspectRatio().x;
float x = dimension * 2 * this.xPos - dimension;
float y = dimension * ar * 2 * this.yPos - dimension * ar;
obj.translate(new Vector3f(x, y, this.zPos));
obj.translate(new Vector3f(10.0f * i * this.scalingFactor)); // 10.0f est dependant de la taille de la police à changer si besoin rendre dynamique si plusieurs police
// Camera position
obj.translate(new Vector3f(- engine.transformationView.x, engine.transformationView.y));
i++;
}
}
public void updateScalingFactor(float scaleFactor){
this.scalingFactor *= scaleFactor;
}
public void update(){
this.getObjInPosition();
}
}