mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2024-11-24 20:29:44 +01:00
added Move Camera based on player position
This commit is contained in:
parent
f658f53ba9
commit
748226f4ed
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user