Premier jet pour les élements d'interface encore pas mal de truc à regler
This commit is contained in:
parent
d037826a3f
commit
0dc5081bff
@ -8,6 +8,7 @@ import engine.sound.*;
|
||||
import org.lwjgl.glfw.GLFWFramebufferSizeCallback;
|
||||
import org.lwjgl.glfw.GLFWVidMode;
|
||||
import org.lwjgl.opengl.GL;
|
||||
import org.lwjgl.system.CallbackI;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -28,6 +29,7 @@ public class Engine {
|
||||
private final int height;
|
||||
|
||||
private float viewXPos;
|
||||
public Vector3f transformationView;
|
||||
|
||||
/**
|
||||
* Create the engine and initial attributes use .init() to start the engine
|
||||
@ -40,6 +42,7 @@ public class Engine {
|
||||
ObjectGl.projection = Matrix4f.orthographic(-1000, 1000, -1000 * aspectRatio, 1000 * aspectRatio, 0.1f, 100.0f);
|
||||
ObjectGl.view = Matrix4f.translate(new Vector3f(0.0f, 0.0f, 1.0f));
|
||||
this.viewXPos = 0.0f;
|
||||
this.transformationView = new Vector3f();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -231,6 +234,9 @@ public class Engine {
|
||||
engine.add_objectGl(background);
|
||||
|
||||
Text texTest = new Text("ABCDEFGHIJKLMNOPQRSTUVWYZ",20.0f, 10, engine);
|
||||
texTest.translate(new Vector3f(-1000.0f, (float) (-1000.0f * (3.0 / 4.0f) + 100.0f)));
|
||||
|
||||
UIElement fpsCounter = new UIElement(texTest.getObj(), engine);
|
||||
|
||||
long timer = System.currentTimeMillis();
|
||||
long lastFrame;
|
||||
@ -270,8 +276,10 @@ public class Engine {
|
||||
|
||||
KeyboardInput.keyboardInput(zangief, speed);
|
||||
|
||||
Vector3f vecTransView = new Vector3f((-zangief.getXPos() - engine.viewXPos) - 250.0f,0.0f,0.0f);
|
||||
engine.translateView(vecTransView);
|
||||
engine.transformationView = new Vector3f((- zangief.getXPos() - engine.viewXPos) - 250.0f,0.0f,0.0f);
|
||||
engine.translateView(engine.transformationView);
|
||||
|
||||
fpsCounter.update();
|
||||
|
||||
/*
|
||||
********************
|
||||
|
@ -22,9 +22,12 @@ public class Vector3f {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public void divXY(float div){
|
||||
this.x /= div;
|
||||
this.y /= div;
|
||||
public Vector3f divXY(float div){
|
||||
return new Vector3f(this.x / div, this.y / div, this.z);
|
||||
}
|
||||
|
||||
public Vector3f divXYZ(float div){
|
||||
return new Vector3f(this.x / div, this.y / div, this.z / div);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -117,8 +117,8 @@ public class ObjectGl {
|
||||
this.xPos += vec.x;
|
||||
this.yPos += vec.y;
|
||||
this.zPos += vec.z;
|
||||
vec.divXY(this.scalingFactor);
|
||||
this.transform = this.transform.multiply(Matrix4f.translate(vec));
|
||||
Vector3f vecTemp = vec.divXYZ(this.scalingFactor);
|
||||
this.transform = this.transform.multiply(Matrix4f.translate(vecTemp));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,12 +58,23 @@ public class Text {
|
||||
|
||||
}
|
||||
|
||||
public void translate(Vector3f vec){
|
||||
// TODO ET LA TRANSLATION DES NOUVEAUX ELEMENTS ?????????????????
|
||||
for (ObjectGl obj : this.charList){
|
||||
obj.translate(vec);
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(){
|
||||
for (ObjectGl obj : this.charList){
|
||||
this.engine.remove_objectGl(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ObjectGl> getObj(){
|
||||
return new ArrayList<>(this.charList);
|
||||
}
|
||||
|
||||
private void removeFromIndexToEnd(int i){
|
||||
int j = 0;
|
||||
for (ObjectGl objectGl : this.charList){
|
||||
|
35
src/engine/object/UIElement.java
Normal file
35
src/engine/object/UIElement.java
Normal file
@ -0,0 +1,35 @@
|
||||
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;
|
||||
|
||||
public UIElement(List<ObjectGl> objs, Engine engine){
|
||||
this.objs = new ArrayList<>();
|
||||
this.objs.addAll(objs);
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
public void addObj(ObjectGl obj){
|
||||
this.objs.add(obj);
|
||||
}
|
||||
|
||||
public void addObj(List<ObjectGl> objs){
|
||||
this.objs.addAll(objs);
|
||||
}
|
||||
|
||||
public void update(){
|
||||
for (ObjectGl obj : this.objs){
|
||||
obj.translate(new Vector3f(-engine.transformationView.x, engine.transformationView.y)); // Tous les elmts font le même déplacement que la caméra
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user