Ich arbeite an einem 3D-Spiel in LWJGL, und ich möchte eine First-Person-Stil-Kamera mit Mausunterstützung hinzufügen. Ich habe derzeit einen, aber es ist nicht glatt und funktioniert überhaupt nicht sehr gut. Ich würde auch gerne das Fenster fokussieren, also ist die Maus beschäftigt und nicht über dem Fenster. Wie kann ich das umsetzen?Eine First Person Style Kamera für LWJGL (Mausunterstützung)
Hier ist meine aktuelle Kamera Umsetzung:
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;
}
}