From 748226f4edc3ea3eb186511a1f83328b0f6cd0fc Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Sat, 23 Nov 2024 19:27:04 +0100 Subject: [PATCH] added Move Camera based on player position --- .../monopoly/client/gui/CameraController.java | 31 ++++++++++--------- .../pp/monopoly/client/gui/TestWorld.java | 13 ++++++-- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/CameraController.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/CameraController.java index 314ebb6..4c0a3d5 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/CameraController.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/CameraController.java @@ -39,21 +39,22 @@ public class CameraController { * @param tpf Zeit pro Frame */ public void update(float tpf) { - // Aktualisiere den Winkel basierend auf der Geschwindigkeit - angle += speed * tpf; - if (angle >= FastMath.TWO_PI) { - angle -= FastMath.TWO_PI; // Winkel zurücksetzen, um Überläufe zu vermeiden - } - - // Berechne die neue Position der Kamera - float x = center.x + radius * FastMath.cos(angle); - float z = center.z + radius * FastMath.sin(angle); - float y = center.y + height; - - // Setze die Kameraposition - camera.setLocation(new Vector3f(x, y, z)); - - // Lasse die Kamera auf den Fokuspunkt blicken camera.lookAt(center, Vector3f.UNIT_Y); } + + public void setPosition(int fieldID) { + camera.setLocation(fieldIdToVector(fieldID)); + } + + public void setPosition(float x, float y) { + camera.setLocation(new Vector3f(x,height,y)); + } + + private Vector3f fieldIdToVector(int fieldID) { + if (fieldID <= 10) return new Vector3f(4,height,0); + if (fieldID <= 20) return new Vector3f(0, height, 4); + if (fieldID <= 30) return new Vector3f(-4, height, 0); + if (fieldID <= 40) return new Vector3f(0, height, -4); + else throw new IllegalArgumentException(); + } } diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TestWorld.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TestWorld.java index 6341ff3..2a5e4e0 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TestWorld.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TestWorld.java @@ -1,5 +1,9 @@ package pp.monopoly.client.gui; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + import com.jme3.material.Material; import com.jme3.math.ColorRGBA; import com.jme3.math.Vector3f; @@ -43,15 +47,18 @@ public class TestWorld { cameraController = new CameraController( app.getCamera(), // Die Kamera der App Vector3f.ZERO, // Fokus auf die Mitte des Spielfelds - 5, // Radius des Kreises - 3, // Höhe der Kamera - 0.5f // Geschwindigkeit der Bewegung + 4, // Radius des Kreises + 2, // Höhe der Kamera + 0 // Geschwindigkeit der Bewegung ); // Füge die Toolbar hinzu new Toolbar(app, cube); + + cameraController.setPosition(0); } + /** * Aktualisiert die Kameraposition. *