Je travaille sur un jeu en 3D dans LWJGL, et je voudrais ajouter une première caméra de style personne avec l'aide de la souris. J'en ai un actuellement, mais ce n'est pas lisse et ne fonctionne pas très bien du tout. J'aimerais vraiment que la fenêtre soit aussi focalisée, donc la souris est engagée et ne plane pas sur la fenêtre. Comment puis-je l'implémenter?Une caméra à la première personne Style pour LWJGL (souris Support)
Voici mon implémentation actuelle de la caméra:
public class Camera {
private Vector3f position = new Vector3f(0,5,0);
private float pitch = 10;
private float yaw;
private float roll;
private float speed = 0.2f;
public Camera() {
}
public void move() {
yaw = - (Display.getWidth() - Mouse.getX()/4);
pitch = (Display.getHeight()/1000) - Mouse.getY();
if (pitch >= 90) {
pitch = 90;
}
else if (pitch <= -90) {
pitch = -90;
}
if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
position.z += -(float)Math.cos(Math.toRadians(yaw)) * speed;
position.x += (float)Math.sin(Math.toRadians(yaw)) * speed;
}
else if (Keyboard.isKeyDown(Keyboard.KEY_S)) {
position.z -= -(float)Math.cos(Math.toRadians(yaw)) * speed;
position.x -= (float)Math.sin(Math.toRadians(yaw)) * speed;
}
if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
position.z += (float)Math.sin(Math.toRadians(yaw)) * speed;
position.x += (float)Math.cos(Math.toRadians(yaw)) * speed;
}
else if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
position.z -= (float)Math.sin(Math.toRadians(yaw)) * speed;
position.x -= (float)Math.cos(Math.toRadians(yaw)) * speed;
}
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
position.y -= speed;
}
if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
position.y += speed;
}
if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
System.exit(0);
}
}
public Vector3f getPosition() {
return position;
}
public float getPitch() {
return pitch;
}
public float getYaw() {
return yaw;
}
public float getRoll() {
return roll;
}
}