UIElement scale with zoom level of the projection

This commit is contained in:
Antoine
2021-06-04 20:14:10 +02:00
parent db073106cd
commit 12b89079ce
8 changed files with 123 additions and 57 deletions

View File

@ -20,8 +20,17 @@ public class Camera {
}
public void zoom(float zoomFactor){
engine.setUIElementZoomFactor(zoomFactor);
this.dimension *= zoomFactor;
float ar = aspectRatio.y / aspectRatio.x;
ObjectGl.projection = Matrix4f.orthographic(-dimension, dimension, -dimension * ar, dimension * ar, 0.1f, 100.0f);
}
public float getDimension(){
return this.dimension;
}
public Vector3f getAspectRatio(){
return this.aspectRatio;
}
}

View File

@ -98,7 +98,7 @@ public class ObjectGl {
}
/**
* Reset the transform matrix, the model will appear at the 0.0.0 coordinate, his scaleFactor will be set to zero
* Reset the transform matrix, the model will appear at the 0.0.0 coordinate, his scaleFactor will be set to one
* Because the model is at position 0 on the z axis he will not show up on screen
*/
public void resetTransform(){
@ -236,7 +236,7 @@ public class ObjectGl {
this.vertexArray = new VertexArray(Primitive.createRectangle(this.zPos, this.width, this.height), Primitive.rectangle_indices, colorBuffer, Primitive.stdTexWrap);
}
private void setTextureWrap(float[] texture){
public void setTextureWrap(float[] texture){
this.textureWrap = texture;
this.vertexArray.swapTextureBufferObject(texture);
}
@ -253,6 +253,10 @@ public class ObjectGl {
return zPos;
}
public float getScalingFactor(){
return scalingFactor;
}
/**
* Do shader binding, texture binding and vertexArray drawing
*/

View File

@ -0,0 +1,11 @@
package engine.object;
import engine.math.Vector3f;
public class Sprite extends ObjectGl {
public Sprite(float z, float size, String tex, Vector3f color) {
super(z, 1f, 1f, size, tex, color);
}
}

View File

@ -7,13 +7,15 @@ import engine.math.Vector3f;
import java.util.ArrayList;
import java.util.List;
/**
* Un texte construit selon la même logique qu'une sprite pour faire un element d'interface utilisez UIElementText
*/
public class Text {
private List<ObjectGl> charList;
private final float size;
private final Engine engine;
private final float zPos;
private UIElement linkedUIElement;
private Vector3f transformation;
@ -24,6 +26,9 @@ public class Text {
this.engine = engine;
this.transformation = new Vector3f();
this.textToArrayObjectGl(text);
}
public void show(){
this.addCharListInEngine();
}
@ -44,14 +49,10 @@ 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){
@ -81,7 +82,6 @@ public class Text {
public void remove(){
for (ObjectGl obj : this.charList){
this.engine.remove_objectGl(obj);
if (linkedUIElement != null) linkedUIElement.removeObj(obj);
}
}
@ -94,7 +94,6 @@ public class Text {
for (ObjectGl objectGl : this.charList){
if (j >= i) {
this.engine.remove_objectGl(objectGl);
if (linkedUIElement != null) linkedUIElement.removeObj(objectGl);
}
j++;
}