UIElement scale with zoom level of the projection
This commit is contained in:
16
src/engine/gui/UIDummy.java
Normal file
16
src/engine/gui/UIDummy.java
Normal file
@ -0,0 +1,16 @@
|
||||
package engine.gui;
|
||||
|
||||
public class UIDummy {
|
||||
|
||||
public void init(){
|
||||
}
|
||||
|
||||
private void getObjInPosition(){
|
||||
}
|
||||
|
||||
public void updateScalingFactor(float scaleFactor){
|
||||
}
|
||||
|
||||
public void update(){
|
||||
}
|
||||
}
|
@ -1,47 +1,64 @@
|
||||
package engine.gui;
|
||||
|
||||
|
||||
import engine.Engine;
|
||||
import engine.math.Vector3f;
|
||||
import engine.object.Camera;
|
||||
import engine.object.ObjectGl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
public class UIElement extends UIDummy{
|
||||
|
||||
public class UIElement {
|
||||
private final ObjectGl obj;
|
||||
private final Engine engine;
|
||||
private final Camera camera;
|
||||
private float scalingFactor;
|
||||
private float xPos;
|
||||
private float yPos;
|
||||
private float zPos;
|
||||
|
||||
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);
|
||||
/**
|
||||
* Crée un elements d'interface càd un sprite qui suis les mouvements de la camera, pas besoin d'ajouter l'ObjectGl
|
||||
* dans la liste de rendu cette classe s'en occupe lors de l'initialisation
|
||||
* @param obj l'objet à mettre dans le conteneur
|
||||
* @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 UIElement(ObjectGl obj, float posX, float posY, Engine engine){
|
||||
this.obj = obj;
|
||||
this.engine = engine;
|
||||
this.transformation = new Vector3f();
|
||||
this.camera = engine.getCamera();
|
||||
this.scalingFactor = obj.getScalingFactor();
|
||||
this.xPos = posX;
|
||||
this.yPos = posY;
|
||||
this.zPos = obj.getZPos();
|
||||
this.getObjInPosition();
|
||||
}
|
||||
|
||||
public void addObj(ObjectGl obj){
|
||||
obj.translate(this.transformation);
|
||||
this.objs.add(obj);
|
||||
public void init(){
|
||||
this.engine.add_objectGl(obj);
|
||||
}
|
||||
|
||||
public void addObj(List<ObjectGl> objs){
|
||||
for (ObjectGl obj : objs){
|
||||
obj.translate(this.transformation);
|
||||
this.objs.add(obj);
|
||||
}
|
||||
private void getObjInPosition(){
|
||||
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));
|
||||
System.out.println(x);
|
||||
// Camera position
|
||||
obj.translate(new Vector3f(- engine.transformationView.x, engine.transformationView.y));
|
||||
}
|
||||
|
||||
public void removeObj(ObjectGl obj){
|
||||
this.objs.remove(obj);
|
||||
public void updateScalingFactor(float scaleFactor){
|
||||
this.scalingFactor *= scaleFactor;
|
||||
}
|
||||
|
||||
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(translationViewPoint); // Tous les elmts font le même déplacement que la caméra
|
||||
}
|
||||
this.getObjInPosition();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,13 +1,6 @@
|
||||
package engine.gui;
|
||||
|
||||
import engine.Engine;
|
||||
import engine.gui.UIElement;
|
||||
import engine.object.ObjectGl;
|
||||
|
||||
import java.util.List;
|
||||
public class UIElementText extends UIDummy{
|
||||
|
||||
public class UIElementText extends UIElement {
|
||||
public UIElementText(List<ObjectGl> objs, Engine engine) {
|
||||
super(objs, engine);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user