Added UIElementText
This commit is contained in:
parent
12b89079ce
commit
eaeb8ccee7
@ -2,6 +2,7 @@ package engine;
|
|||||||
|
|
||||||
import engine.gui.UIDummy;
|
import engine.gui.UIDummy;
|
||||||
import engine.gui.UIElement;
|
import engine.gui.UIElement;
|
||||||
|
import engine.gui.UIElementText;
|
||||||
import engine.input.*;
|
import engine.input.*;
|
||||||
import engine.math.*;
|
import engine.math.*;
|
||||||
import engine.object.*;
|
import engine.object.*;
|
||||||
@ -139,11 +140,15 @@ public class Engine {
|
|||||||
this.objectsGl.add(obj);
|
this.objectsGl.add(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void add_objectsGl(List<ObjectGl> objs) {
|
||||||
|
this.objectsGl.addAll(objs);
|
||||||
|
}
|
||||||
|
|
||||||
public void remove_objectGl(ObjectGl obj) {
|
public void remove_objectGl(ObjectGl obj) {
|
||||||
this.objectsGl.remove(obj);
|
this.objectsGl.remove(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add_uiElement(UIElement uiElement) {
|
public void add_uiElement(UIDummy uiElement) {
|
||||||
uiElement.init();
|
uiElement.init();
|
||||||
this.uiElements.add(uiElement);
|
this.uiElements.add(uiElement);
|
||||||
}
|
}
|
||||||
@ -256,19 +261,17 @@ public class Engine {
|
|||||||
background.translate(new Vector3f(-3011.0f, 1400.0f, 1.0f));
|
background.translate(new Vector3f(-3011.0f, 1400.0f, 1.0f));
|
||||||
engine.add_objectGl(background);
|
engine.add_objectGl(background);
|
||||||
|
|
||||||
ObjectGl smiley = new Sprite(15.0f, 500.0f, path2, null);
|
// ObjectGl smiley = new Sprite(15.0f, 500.0f, path2, null);
|
||||||
|
|
||||||
UIElement uiElement = new UIElement(smiley, 0.0f, 1.0f, engine);
|
|
||||||
engine.add_uiElement(uiElement);
|
|
||||||
|
|
||||||
Text texTest = new Text("ABCDEFGHIJKLMNOPQRSTUVWYZ",20.0f, 10, engine);
|
|
||||||
texTest.show();
|
|
||||||
texTest.translate(new Vector3f(-1000.0f, (float) (-1000.0f * (3.0 / 4.0f) + 100.0f)));
|
|
||||||
|
|
||||||
// UIElement fpsCounter = new UIElement(texTest.getObj(), engine);
|
|
||||||
// engine.add_uiElement(fpsCounter); // Pour être atteint par les modification du frustum
|
|
||||||
//
|
//
|
||||||
// texTest.linkToUIElement(fpsCounter);
|
// UIElement uiElement = new UIElement(smiley, 0.0f, 1.0f, engine);
|
||||||
|
// engine.add_uiElement(uiElement);
|
||||||
|
|
||||||
|
UIElementText uiTextTest = new UIElementText("Boulevard Combattant", 10.0f, 0.0f,1.0f, 25.0f, engine);
|
||||||
|
engine.add_uiElement(uiTextTest);
|
||||||
|
|
||||||
|
// Text texTest = new Text("ABCDEFGHIJKLMNOPQRSTUVWYZ",20.0f, 10, engine);
|
||||||
|
// texTest.show();
|
||||||
|
// texTest.translate(new Vector3f(-1000.0f, (float) (-1000.0f * (3.0 / 4.0f) + 100.0f)));
|
||||||
|
|
||||||
long timer = System.currentTimeMillis();
|
long timer = System.currentTimeMillis();
|
||||||
long lastFrame;
|
long lastFrame;
|
||||||
@ -281,14 +284,18 @@ public class Engine {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
GamepadInput gamepad1 = null;
|
GamepadInput gamepad1 = null;
|
||||||
Button jump = null;
|
Button zoom = null;
|
||||||
|
Button dezoom = null;
|
||||||
|
|
||||||
if (Joystick1Present){
|
if (Joystick1Present){
|
||||||
gamepad1 = new GamepadInput(GLFW_JOYSTICK_1);
|
gamepad1 = new GamepadInput(GLFW_JOYSTICK_1);
|
||||||
gamepad1.inputRefresh();
|
gamepad1.inputRefresh();
|
||||||
List<Integer> listJump = new ArrayList<>();
|
List<Integer> listZoomPlus = new ArrayList<>();
|
||||||
listJump.add(InputConst.buttonA);
|
listZoomPlus.add(InputConst.buttonA);
|
||||||
jump = new Button("jump", listJump, gamepad1);
|
List<Integer> listZoomMinus = new ArrayList<>();
|
||||||
|
listZoomMinus.add(InputConst.buttonB);
|
||||||
|
zoom = new Button("zoom", listZoomPlus, gamepad1);
|
||||||
|
dezoom = new Button("dezoom", listZoomMinus, gamepad1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -300,9 +307,11 @@ public class Engine {
|
|||||||
if (Joystick1Present) {
|
if (Joystick1Present) {
|
||||||
gamepad1.inputRefresh();
|
gamepad1.inputRefresh();
|
||||||
// Check si le personnage a sauté
|
// Check si le personnage a sauté
|
||||||
if (jump.isButtonPressed()){
|
if (zoom.isButtonPressed()){
|
||||||
// Le personnage saute
|
// Le personnage saute
|
||||||
engine.camera.zoom(1.001f);
|
engine.camera.zoom(1.001f);
|
||||||
|
}if(dezoom.isButtonPressed()){
|
||||||
|
engine.camera.zoom(0.999f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,6 +336,7 @@ public class Engine {
|
|||||||
if (System.currentTimeMillis() - timer > 1000) {
|
if (System.currentTimeMillis() - timer > 1000) {
|
||||||
timer += 1000;
|
timer += 1000;
|
||||||
System.out.println("FPS: " + frame);
|
System.out.println("FPS: " + frame);
|
||||||
|
uiTextTest.setText("FPS: " + frame);
|
||||||
frame = 0;
|
frame = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,6 @@ public class UIElement extends UIDummy{
|
|||||||
float x = dimension * 2 * this.xPos - dimension;
|
float x = dimension * 2 * this.xPos - dimension;
|
||||||
float y = dimension * ar * 2 * this.yPos - dimension * ar;
|
float y = dimension * ar * 2 * this.yPos - dimension * ar;
|
||||||
obj.translate(new Vector3f(x, y, this.zPos));
|
obj.translate(new Vector3f(x, y, this.zPos));
|
||||||
System.out.println(x);
|
|
||||||
// Camera position
|
// Camera position
|
||||||
obj.translate(new Vector3f(- engine.transformationView.x, engine.transformationView.y));
|
obj.translate(new Vector3f(- engine.transformationView.x, engine.transformationView.y));
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,77 @@
|
|||||||
package engine.gui;
|
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{
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -10,6 +10,12 @@ public class Vector3f {
|
|||||||
z = 0.0f;
|
z = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vector3f(float x){
|
||||||
|
this.x = x;
|
||||||
|
this.y = 0.0f;
|
||||||
|
this.z = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
public Vector3f(float x, float y){
|
public Vector3f(float x, float y){
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
|
@ -119,4 +119,8 @@ public class Text {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ObjectGl> getCharList(){
|
||||||
|
return this.charList;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user