diff --git a/src/engine/Engine.java b/src/engine/Engine.java index d22967b..591ca16 100644 --- a/src/engine/Engine.java +++ b/src/engine/Engine.java @@ -1,5 +1,7 @@ package engine; +import engine.gui.UIDummy; +import engine.gui.UIElementText; import engine.input.*; import engine.math.*; import engine.object.*; @@ -8,7 +10,6 @@ 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; @@ -22,24 +23,29 @@ public class Engine { private static long window; private final List objectsGl; + public final List uiElements; private boolean running; private final int width; private final int height; - private float viewXPos; + public float viewXPos; + public float viewYPos; + public float viewZPos; public Vector3f transformationView; + public final Camera camera; /** * Create the engine and initial attributes use .init() to start the engine */ - public Engine(int width, int height, float aspectRatio) { + public Engine(int width, int height, Vector3f aspectRatio) { this.running = false; this.objectsGl = new ArrayList<>(); + this.uiElements = new ArrayList<>(); this.width = width; this.height = height; - ObjectGl.projection = Matrix4f.orthographic(-1000, 1000, -1000 * aspectRatio, 1000 * aspectRatio, 0.1f, 100.0f); + this.camera = new Camera(1000, aspectRatio, this); ObjectGl.view = Matrix4f.translate(new Vector3f(0.0f, 0.0f, 1.0f)); this.viewXPos = 0.0f; this.transformationView = new Vector3f(); @@ -102,6 +108,10 @@ public class Engine { */ public void update() { glfwPollEvents(); + // METS A JOUR LA POSITION DES ELEMENTS D'INTERFACE + for (UIDummy uiElement : this.uiElements){ + uiElement.update(); + } } /** @@ -128,16 +138,37 @@ public class Engine { * @param obj ObjectGl to render */ public void add_objectGl(ObjectGl obj) { - objectsGl.add(obj); + this.objectsGl.add(obj); + } + + public void add_objectsGl(List objs) { + this.objectsGl.addAll(objs); } public void remove_objectGl(ObjectGl obj) { - objectsGl.remove(obj); + this.objectsGl.remove(obj); + } + + public void add_uiElement(UIDummy uiElement) { + uiElement.init(); + this.uiElements.add(uiElement); + } + + public void setUIElementZoomFactor(float scaleFactor){ + for (UIDummy uiElement : this.uiElements){ + uiElement.updateScalingFactor(scaleFactor); + } + } + + public void cameraTrackingObjectGl(ObjectGl obj, float xOffset){ + Vector3f zangiefTracking = new Vector3f((- obj.getXPos() - this.viewXPos) + xOffset,0.0f ,0.0f); + this.translateView(zangiefTracking); } public void translateView(Vector3f vec){ ObjectGl.view = ObjectGl.view.multiply(Matrix4f.translate(vec)); viewXPos += vec.x; + this.transformationView = this.transformationView.addXYZ(vec); } public static void correctViewport(int width, int height){ @@ -173,6 +204,10 @@ public class Engine { return window; } + public Camera getCamera(){ + return this.camera; + } + public void setWindow(long window) { Engine.window = window; } @@ -188,127 +223,4 @@ public class Engine { } }; - public static void main(String[] args) throws Exception { - /* - OpenAl TEST - */ - SoundManager soundManager = new SoundManager(); - soundManager.init(); - - SoundListener soundListener = new SoundListener(); - - soundManager.setListener(soundListener); - - SoundBuffer jumpSoundBuffer = new SoundBuffer("sound/jump.ogg"); - SoundSource soundSource = new SoundSource(false, false); - soundSource.setBuffer(jumpSoundBuffer.getBufferId()); - - soundManager.addSoundSource("jump", soundSource); -// soundManager.playSoundSource("jump");q - - /* - Engine Init - */ - Engine engine = new Engine(1280, 720, 3.0f / 4.0f); - int speed = 10; //vitesse d�placement Object - engine.init(); - - // Add objects to render - String path = "textures/zangief_sprite.png"; - String path2 = "textures/awesomeface.png"; - String pathToBG = "textures/background_beach.png"; - String pathToText = "textures/dejavu10x10_gs_tc.png"; - - ObjectGl zangief = new ObjectGl(10.0f, 1f, 1f, 10f, path, null); - zangief.setTextureWrap(58, 0, 62, 84, ObjectGl.DEFAULT); - engine.add_objectGl(zangief); - zangief.translate(new Vector3f(-1000.0f, 200.0f, 0.0f)); - zangief.setColor(new Vector3f(1.0f, 1.0f, 1.0f)); - zangief.setShader("shaders/StylishShaders/BasicVert.glsl", "shaders/StylishShaders/FlashFrag.glsl"); - zangief.useTime = true; - - //Create background - ObjectGl background = new ObjectGl(0f,1f,1f,10f, pathToBG, null); - background.setTextureWrap(0,0,621, 224, ObjectGl.DEFAULT); - background.translate(new Vector3f(-3011.0f, 1400.0f, 1.0f)); - 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); - - texTest.linkToUIElement(fpsCounter); - - long timer = System.currentTimeMillis(); - long lastFrame; - int frame = 0; - boolean nextFrame = false; - boolean Joystick1Present = glfwJoystickPresent(GLFW_JOYSTICK_1); - - /* - * Cr�ation des manettes / action - */ - - GamepadInput gamepad1 = null; - Button jump = null; - - if (Joystick1Present){ - gamepad1 = new GamepadInput(GLFW_JOYSTICK_1); - gamepad1.inputRefresh(); - List listJump = new ArrayList<>(); - listJump.add(InputConst.buttonA); - jump = new Button("jump", listJump, gamepad1); - } - - - - while (engine.isRunning()) { - lastFrame = System.currentTimeMillis(); - // Game logic should fit here - - if (Joystick1Present) { - gamepad1.inputRefresh(); - // Check si le personnage a sauté - if (jump.isButtonPressed()){ - // Le personnage saute - System.out.println(" JE SAUTE "); - } - } - - KeyboardInput.keyboardInput(zangief, speed); - - engine.transformationView = new Vector3f((- zangief.getXPos() - engine.viewXPos) - 250.0f,0.0f,0.0f); - engine.translateView(engine.transformationView); - - fpsCounter.update(); - - /* - ******************** - * essential part v * - ******************** - */ - engine.update(); - engine.render(); - - frame++; - - if (System.currentTimeMillis() - timer > 1000) { - timer += 1000; - System.out.println("FPS: " + frame); - texTest.setNewText("FPS " + frame); - frame = 0; - } - -// while (!nextFrame) { -// nextFrame = System.currentTimeMillis() - lastFrame >= 16.66f; -// } - - nextFrame = false; - if (engine.shouldClose()) engine.setRunning(false); - } - - soundManager.cleanup(); - - } } diff --git a/src/engine/TestEngine.java b/src/engine/TestEngine.java new file mode 100644 index 0000000..49a7a8a --- /dev/null +++ b/src/engine/TestEngine.java @@ -0,0 +1,155 @@ +package engine; + +import engine.gui.UIElementText; +import engine.input.Button; +import engine.input.GamepadInput; +import engine.input.InputConst; +import engine.input.KeyboardInput; +import engine.math.Vector3f; +import engine.object.ObjectGl; +import engine.object.Sprite; +import engine.sound.SoundBuffer; +import engine.sound.SoundListener; +import engine.sound.SoundManager; +import engine.sound.SoundSource; + +import java.util.ArrayList; +import java.util.List; + +import static org.lwjgl.glfw.GLFW.GLFW_JOYSTICK_1; +import static org.lwjgl.glfw.GLFW.glfwJoystickPresent; + +public class TestEngine { + + public static void main(String[] args) throws Exception { + /* + OpenAl TEST + */ + SoundManager soundManager = new SoundManager(); + soundManager.init(); + + SoundListener soundListener = new SoundListener(); + + soundManager.setListener(soundListener); + + SoundBuffer jumpSoundBuffer = new SoundBuffer("sound/jump.ogg"); + SoundSource soundSource = new SoundSource(false, false); + soundSource.setBuffer(jumpSoundBuffer.getBufferId()); + + soundManager.addSoundSource("jump", soundSource); +// soundManager.playSoundSource("jump"); + + /* + Engine Init + */ + Engine engine = new Engine(1280, 720, new Vector3f(4.0f, 3.0f)); + int speed = 10; //vitesse d�placement Object + engine.init(); + + // Add objects to render + String path = "textures/zangief_sprite.png"; + String path2 = "textures/awesomeface.png"; + String pathToBG = "textures/background_beach.png"; + String pathToText = "textures/dejavu10x10_gs_tc.png"; + + ObjectGl zangief = new Sprite(10.0f, 10f, path, null); + zangief.setTextureWrap(58, 0, 62, 84, ObjectGl.DEFAULT); + engine.add_objectGl(zangief); + zangief.translate(new Vector3f(-1000.0f, 200.0f, 0.0f)); + zangief.setColor(new Vector3f(1.0f, 1.0f, 1.0f)); + zangief.setShader("shaders/StylishShaders/BasicVert.glsl", "shaders/StylishShaders/FlashFrag.glsl"); + zangief.useTime = true; + + //Create background + ObjectGl background = new ObjectGl(0f,1f,1f,10f, pathToBG, null); + background.setTextureWrap(0,0,621, 224, ObjectGl.DEFAULT); + background.translate(new Vector3f(-3011.0f, 1400.0f, 1.0f)); + engine.add_objectGl(background); + +// ObjectGl smiley = new Sprite(15.0f, 500.0f, path2, null); +// UIElement uiElement = new UIElement(smiley, 0.0f, 1.0f, engine); +// engine.add_uiElement(uiElement); + + UIElementText uiTextTest = new UIElementText("Boulevard Combattant", 5.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 lastFrame; + int frame = 0; + boolean nextFrame = false; + boolean Joystick1Present = glfwJoystickPresent(GLFW_JOYSTICK_1); + + /* + * Cr�ation des manettes / action + */ + + GamepadInput gamepad1 = null; + Button zoom = null; + Button dezoom = null; + + if (Joystick1Present){ + gamepad1 = new GamepadInput(GLFW_JOYSTICK_1); + gamepad1.inputRefresh(); + List listZoomPlus = new ArrayList<>(); + listZoomPlus.add(InputConst.buttonA); + List listZoomMinus = new ArrayList<>(); + listZoomMinus.add(InputConst.buttonB); + zoom = new Button("zoom", listZoomPlus, new ArrayList<>(), gamepad1); + dezoom = new Button("dezoom", listZoomMinus, new ArrayList<>(), gamepad1); + } + + engine.translateView(new Vector3f(0.0f, -125.0f, 0.0f)); + + while (engine.isRunning()) { + lastFrame = System.currentTimeMillis(); + // Game logic should fit here + + if (Joystick1Present) { + gamepad1.inputRefresh(); + // Check si le personnage a sauté + if (zoom.isButtonPressed()){ + // Le personnage saute + engine.camera.zoom(1.001f); + }if(dezoom.isButtonPressed()){ + engine.camera.zoom(0.999f); + } + } + + engine.cameraTrackingObjectGl(zangief, -250.0f); + + KeyboardInput.keyboardInput(zangief, speed); + + /* + ******************** + * essential part v * + ******************** + */ + engine.update(); + engine.render(); + + frame++; + + if (System.currentTimeMillis() - timer > 1000) { + timer += 1000; + System.out.println("FPS: " + frame); + uiTextTest.setText("FPS: " + frame); + frame = 0; + } + +// while (!nextFrame) { +// nextFrame = System.currentTimeMillis() - lastFrame >= 16.66f; +// } + + nextFrame = false; + if (engine.shouldClose()) engine.setRunning(false); + } + + soundManager.cleanup(); + + } + +} diff --git a/src/engine/gui/UIDummy.java b/src/engine/gui/UIDummy.java new file mode 100644 index 0000000..eb7186e --- /dev/null +++ b/src/engine/gui/UIDummy.java @@ -0,0 +1,39 @@ +package engine.gui; + +import engine.Engine; +import engine.object.Camera; + +/** + * Classe dont hérite tous les autres élements d'interface + */ +public abstract class UIDummy { + + protected Engine engine; + protected Camera camera; + protected float xPos; + protected float yPos; + protected float zPos; + protected float scalingFactor; + + public void init(){ + } + + protected void getObjInPosition(){ + } + + /** + * Method pour le moteur ne pas utiliser + * @param scaleFactor tqt fréro + */ + public void updateScalingFactor(float scaleFactor){ + this.scalingFactor *= scaleFactor; + } + + /** + * Recalcule la position de l'objet pour qu'il soit adapté au changement dans la projection ou de la position de la camera + * Si l'objet est correctement initialisé par un moteur ne pas utiliser ! + */ + public void update(){ + this.getObjInPosition(); + } +} diff --git a/src/engine/gui/UIElement.java b/src/engine/gui/UIElement.java new file mode 100644 index 0000000..26f21fb --- /dev/null +++ b/src/engine/gui/UIElement.java @@ -0,0 +1,52 @@ +package engine.gui; + +import engine.Engine; +import engine.math.Vector3f; +import engine.object.ObjectGl; + +/** + * Affiche un seul ObjectGl le lie à une position dans la zone de projection + */ +public class UIElement extends UIDummy{ + + private final ObjectGl obj; + + /** + * 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.camera = engine.getCamera(); + this.scalingFactor = obj.getScalingFactor(); + this.xPos = posX; + this.yPos = posY; + this.zPos = obj.getZPos(); + this.getObjInPosition(); + } + + /** + * Ajoute l'ObjectGl lié à la liste de rendu du moteur lié + */ + public void init(){ + this.engine.add_objectGl(obj); + } + + protected 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)); + // Camera position + obj.translate(new Vector3f(- engine.transformationView.x, -engine.transformationView.y)); + } +} diff --git a/src/engine/gui/UIElementText.java b/src/engine/gui/UIElementText.java new file mode 100644 index 0000000..bb144cc --- /dev/null +++ b/src/engine/gui/UIElementText.java @@ -0,0 +1,70 @@ +package engine.gui; + +import engine.Engine; +import engine.math.Vector3f; +import engine.object.ObjectGl; +import engine.object.Text; + +import java.util.List; + +/** + * Affiche du texte le lie à une position dans la zone de projection + */ +public class UIElementText extends UIDummy{ + + private final List objs; + private final Text txt; + + /** + * 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(); + } + + /** + * Ajouter l'element à la liste de rendu du moteur dont il est lié. + */ + public void init(){ + this.engine.add_objectsGl(objs); + } + + /** + * Modifier le texte + * @param txt le nouveau texte + */ + public void setText(String txt){ + this.txt.setNewText(txt); + } + + protected 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++; + } + } + +} \ No newline at end of file diff --git a/src/engine/input/Button.java b/src/engine/input/Button.java index 942b13f..dd63e34 100644 --- a/src/engine/input/Button.java +++ b/src/engine/input/Button.java @@ -1,22 +1,30 @@ package engine.input; +import engine.Engine; + import java.util.List; +import static org.lwjgl.glfw.GLFW.glfwGetKey; + public class Button { public String name; - private final List buttons; + private final List buttonsGamepad; + private final List buttonsKeyboard; private final GamepadInput controller; - public Button(String name, List buttons, GamepadInput controller){ + public Button(String name, List buttonsGamepad, List buttonsKeyboard, GamepadInput controller){ this.name = name; - this.buttons = buttons; + this.buttonsGamepad = buttonsGamepad; + this.buttonsKeyboard = buttonsKeyboard; this.controller = controller; } public boolean isButtonPressed(){ - for (int i : buttons){ + for (int i : buttonsGamepad){ if (controller.checkPressed(i)) return true; + } for (int i : buttonsKeyboard){ + if (glfwGetKey(Engine.getWindow(), i) == 1) return true; } return false; } diff --git a/src/engine/input/KeyboardInput.java b/src/engine/input/KeyboardInput.java index 77167ca..b68fa44 100644 --- a/src/engine/input/KeyboardInput.java +++ b/src/engine/input/KeyboardInput.java @@ -30,63 +30,6 @@ public class KeyboardInput extends GLFWKeyCallback { return glfwGetKey(Engine.getWindow(), keyCode) == 1; } - public static void gamepadInput(ObjectGl token, int speed) { - ByteBuffer gamepadButton = glfwGetJoystickButtons(GLFW_JOYSTICK_1); - FloatBuffer gamepadAxes = glfwGetJoystickAxes(GLFW_JOYSTICK_1); - - assert gamepadAxes != null; - assert gamepadButton != null; - - String name = GLFW.glfwGetJoystickName(GLFW_JOYSTICK_1); - System.out.println("GamePad Name :" + name); - - - - if (gamepadButton.get(0) ==1 ) { // appuie sur croix(PlayStation) A (Xbox) - token.translate(new Vector3f( 0.0f, speed * 5.0f, 0.0f)); - } - if ( (gamepadAxes.get(2) < -0.1 || gamepadAxes.get(2) > 0.1) ) { // de droite à gauche //joystick gauche - token.translate(new Vector3f (5 * speed * gamepadAxes.get(2), 0.0f, 0.0f)); - if ( gamepadAxes.get(2) < -0.1 ){ - token.setTextureWrap(121,0,57,80, ObjectGl.DEFAULT); - }else if (gamepadAxes.get(2) > 0.1) { - token.setTextureWrap(178,0,62,82, ObjectGl.DEFAULT); - } - } - - if ( (gamepadAxes.get(3) < -0.1 || gamepadAxes.get(3) > 0.1) ) { // de haut en bas //joystick gauche - token.translate(new Vector3f (0.0f, -5 * speed * gamepadAxes.get(3), 0.0f)); - - } - - /* Buttons - 0 : Croix / A - 1: rond /B - 2: carré / X - 3: triangle / Y - 4: L1 / LB - 5: R1 / RB - 6:select - 7:start - 8:L3 - 9:R3 - 10: haut - 11: droite - 12: bas - 13: gauche - */ - - /* Axes - 0 : left X axe ( right : 1 left -1) - 1: left Y axe ( down : 1 , Up -1) - 2: right X axe ( right : 1 left -1) - 3: right Y axe ( down : 1 , Up -1) - 4:L2 / LT : 1 active, -1 unactive - 5: R2 /RT : 1 active, -1 unactive - */ - - } - public static void keyboardInput(ObjectGl token, int speed) { boolean keyPressed = false; if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_S)) { @@ -94,7 +37,6 @@ public class KeyboardInput extends GLFWKeyCallback { keyPressed = true; } else if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_W)) { keyPressed = true; -// token.scale(new Vector3f(1.001f,1.001f,1.0f)); } if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_A)) { token.translate(new Vector3f (speed * -1.0f, 0.0f, 0.0f)); @@ -107,7 +49,5 @@ public class KeyboardInput extends GLFWKeyCallback { keyPressed = true; } if (!keyPressed) token.setTextureWrap(58,0,62,82, ObjectGl.STICK_TOP); - -// token.flipTextureWrapH(); } } diff --git a/src/engine/math/Vector3f.java b/src/engine/math/Vector3f.java index 3104762..2b0fc61 100644 --- a/src/engine/math/Vector3f.java +++ b/src/engine/math/Vector3f.java @@ -10,6 +10,12 @@ public class Vector3f { z = 0.0f; } + public Vector3f(float x){ + this.x = x; + this.y = 0.0f; + this.z = 0.0f; + } + public Vector3f(float x, float y){ this.x = x; this.y = y; diff --git a/src/engine/object/Camera.java b/src/engine/object/Camera.java new file mode 100644 index 0000000..3ce67b2 --- /dev/null +++ b/src/engine/object/Camera.java @@ -0,0 +1,36 @@ +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){ + 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; + } +} diff --git a/src/engine/object/ObjectGl.java b/src/engine/object/ObjectGl.java index 91f9e5e..4824095 100644 --- a/src/engine/object/ObjectGl.java +++ b/src/engine/object/ObjectGl.java @@ -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 */ diff --git a/src/engine/object/Sprite.java b/src/engine/object/Sprite.java new file mode 100644 index 0000000..d5ba390 --- /dev/null +++ b/src/engine/object/Sprite.java @@ -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); + } + +} diff --git a/src/engine/object/Text.java b/src/engine/object/Text.java index abf9c2a..a97a2ed 100644 --- a/src/engine/object/Text.java +++ b/src/engine/object/Text.java @@ -1,18 +1,21 @@ package engine.object; import engine.Engine; +import engine.gui.UIElement; 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 charList; private final float size; private final Engine engine; private final float zPos; - private UIElement linkedUIElement; private Vector3f transformation; @@ -23,6 +26,9 @@ public class Text { this.engine = engine; this.transformation = new Vector3f(); this.textToArrayObjectGl(text); + } + + public void show(){ this.addCharListInEngine(); } @@ -43,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){ @@ -80,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); } } @@ -93,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++; } @@ -119,4 +119,8 @@ public class Text { } } + public List getCharList(){ + return this.charList; + } + } diff --git a/src/engine/object/UIElement.java b/src/engine/object/UIElement.java deleted file mode 100644 index 6077b32..0000000 --- a/src/engine/object/UIElement.java +++ /dev/null @@ -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 objs; - private Engine engine; - private Vector3f transformation; - - public UIElement(List 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 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 - } - } - -} diff --git a/src/launcher/Launcher.java b/src/launcher/Launcher.java index 6899a35..eba028b 100644 --- a/src/launcher/Launcher.java +++ b/src/launcher/Launcher.java @@ -9,6 +9,7 @@ package launcher; +import engine.TestEngine; import javafx.application.Application; import javafx.scene.Parent; import javafx.scene.Scene; @@ -52,7 +53,7 @@ public class Launcher extends Application { public static void runGame() { try { setter.setSettings(); - Engine.main(null); + TestEngine.main(null); } catch (Exception e) { e.printStackTrace(); System.exit(1);