Camera zoom + package gui

This commit is contained in:
Antoine
2021-06-04 17:29:17 +02:00
parent ab6939466d
commit db073106cd
5 changed files with 74 additions and 20 deletions

View File

@ -0,0 +1,27 @@
package engine.object;
import engine.Engine;
import engine.math.Matrix4f;
import engine.math.Vector3f;
public class Camera {
private float dimension;
private final Vector3f aspectRatio;
private final Engine engine;
public Camera(float dimension, Vector3f aspectRatio, Engine engine){
this.dimension = dimension;
this.aspectRatio = aspectRatio;
this.engine = engine;
float ar = aspectRatio.y / aspectRatio.x;
ObjectGl.projection = Matrix4f.orthographic(-dimension, dimension, -dimension * ar, dimension * ar, 0.1f, 100.0f);
}
public void zoom(float zoomFactor){
this.dimension *= zoomFactor;
float ar = aspectRatio.y / aspectRatio.x;
ObjectGl.projection = Matrix4f.orthographic(-dimension, dimension, -dimension * ar, dimension * ar, 0.1f, 100.0f);
}
}

View File

@ -1,6 +1,7 @@
package engine.object;
import engine.Engine;
import engine.gui.UIElement;
import engine.math.Vector3f;
import java.util.ArrayList;

View File

@ -1,47 +0,0 @@
package engine.object;
import engine.Engine;
import engine.math.Vector3f;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
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){
for (ObjectGl obj : objs){
obj.translate(this.transformation);
this.objs.add(obj);
}
}
public void removeObj(ObjectGl obj){
this.objs.remove(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(translationViewPoint); // Tous les elmts font le même déplacement que la caméra
}
}
}