Keyboard input added In Engine.java
This commit is contained in:
parent
7a79c19c98
commit
59d822015a
@ -2,6 +2,8 @@ package engine;
|
|||||||
|
|
||||||
import engine.math.*;
|
import engine.math.*;
|
||||||
import engine.object.*;
|
import engine.object.*;
|
||||||
|
|
||||||
|
import org.lwjgl.glfw.GLFW;
|
||||||
import org.lwjgl.glfw.GLFWFramebufferSizeCallback;
|
import org.lwjgl.glfw.GLFWFramebufferSizeCallback;
|
||||||
import org.lwjgl.glfw.GLFWVidMode;
|
import org.lwjgl.glfw.GLFWVidMode;
|
||||||
import org.lwjgl.opengl.GL;
|
import org.lwjgl.opengl.GL;
|
||||||
@ -15,7 +17,7 @@ import static org.lwjgl.system.MemoryUtil.NULL;
|
|||||||
|
|
||||||
public class Engine {
|
public class Engine {
|
||||||
|
|
||||||
private long window;
|
private static long window;
|
||||||
|
|
||||||
private final List<ObjectGl> objectsGl;
|
private final List<ObjectGl> objectsGl;
|
||||||
|
|
||||||
@ -49,25 +51,28 @@ public class Engine {
|
|||||||
|
|
||||||
int width = 1280;
|
int width = 1280;
|
||||||
int height = 720;
|
int height = 720;
|
||||||
this.window = glfwCreateWindow(width, height, "Boulevard Combattant", NULL, NULL);
|
this.setWindow(glfwCreateWindow(width, height, "Boulevard Combattant", NULL, NULL));
|
||||||
assert this.window != NULL;
|
assert this.getWindow() != NULL;
|
||||||
|
|
||||||
|
boolean present = glfwJoystickPresent(GLFW_JOYSTICK_1);
|
||||||
|
System.out.println(present);
|
||||||
|
|
||||||
// On récupère les informations du moniteur principal
|
// On récupère les informations du moniteur principal
|
||||||
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
||||||
assert vidmode != null;
|
assert vidmode != null;
|
||||||
|
|
||||||
// On met la fenêtre au centre de l'écran principale
|
// On met la fenêtre au centre de l'écran principale
|
||||||
glfwSetWindowPos(this.window, (vidmode.width() - width)/2, (vidmode.height() - height)/2);
|
glfwSetWindowPos(this.getWindow(), (vidmode.width() - width)/2, (vidmode.height() - height)/2);
|
||||||
|
|
||||||
glfwSetKeyCallback(window, new Input());
|
glfwSetKeyCallback(getWindow(), new Input());
|
||||||
glfwSetInputMode(window, GLFW_STICKY_KEYS, GLFW_TRUE);
|
glfwSetInputMode(getWindow(), GLFW_STICKY_KEYS, GLFW_TRUE);
|
||||||
|
|
||||||
// Contexte = zone cible des rendus
|
// Contexte = zone cible des rendus
|
||||||
glfwMakeContextCurrent(this.window);
|
glfwMakeContextCurrent(this.getWindow());
|
||||||
glfwShowWindow(this.window);
|
glfwShowWindow(this.getWindow());
|
||||||
GL.createCapabilities();
|
GL.createCapabilities();
|
||||||
|
|
||||||
glfwSetFramebufferSizeCallback(window, resizeWindow);
|
glfwSetFramebufferSizeCallback(getWindow(), resizeWindow);
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST); // Z-Buffer plus z est grand plus l'objet est proche de la camera limite à 100.0f au dela l'objet disparait
|
glEnable(GL_DEPTH_TEST); // Z-Buffer plus z est grand plus l'objet est proche de la camera limite à 100.0f au dela l'objet disparait
|
||||||
|
|
||||||
@ -97,9 +102,12 @@ public class Engine {
|
|||||||
objectGl.render();
|
objectGl.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int error = glGetError();
|
int error = glGetError();
|
||||||
if (error != GL_NO_ERROR) System.out.println(error);
|
if (error != GL_NO_ERROR) System.out.println(error);
|
||||||
glfwSwapBuffers(window); //Envoie le buffer vers le moniteur
|
glfwSwapBuffers(getWindow()); //Envoie le buffer vers le moniteur
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add_objectGl(ObjectGl obj){
|
public void add_objectGl(ObjectGl obj){
|
||||||
@ -120,7 +128,7 @@ public class Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean shouldClose(){
|
public boolean shouldClose(){
|
||||||
return glfwWindowShouldClose(window);
|
return glfwWindowShouldClose(getWindow());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -136,6 +144,7 @@ public class Engine {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Engine engine = new Engine();
|
Engine engine = new Engine();
|
||||||
|
int speed = 2 ; //vitesse déplacement Object
|
||||||
engine.init();
|
engine.init();
|
||||||
|
|
||||||
// Add objects to render
|
// Add objects to render
|
||||||
@ -164,6 +173,11 @@ public class Engine {
|
|||||||
|
|
||||||
smiley2.rotateZ(0.8f);
|
smiley2.rotateZ(0.8f);
|
||||||
|
|
||||||
|
input(smiley, speed);
|
||||||
|
input(smiley2, speed);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//essential part v
|
//essential part v
|
||||||
engine.update();
|
engine.update();
|
||||||
engine.render();
|
engine.render();
|
||||||
@ -185,4 +199,19 @@ public class Engine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void input(ObjectGl token, int speed) {
|
||||||
|
if (Input.isKeyDown(GLFW.GLFW_KEY_W))token.translate(new Vector3f ( 0.0f, speed * 5.0f, 0.0f));
|
||||||
|
if (Input.isKeyDown(GLFW.GLFW_KEY_A))token.translate(new Vector3f (speed *-5.0f, 0.0f, 0.0f));
|
||||||
|
if (Input.isKeyDown(GLFW.GLFW_KEY_S))token.translate(new Vector3f ( 0.0f,speed * -5.0f, 0.0f));
|
||||||
|
if (Input.isKeyDown(GLFW.GLFW_KEY_D))token.translate(new Vector3f (speed * 5.0f, 0.0f, 0.0f));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long getWindow() {
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWindow(long window) {
|
||||||
|
this.window = window;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user