Hallo!
Ich arbeite derzeit an einem 3D-Sonnensystem. Man soll als Beobachter (das Raumschiff) unser Sonnensystem erkunden können. Gesteuert wird per Maus und W (Schub nach vorne) und S (Umkehrschub). Mein "yaw" (Rotation um y-Achse) funktioniert ohne Probleme. Wenn ich aber einen Kreis um die x-Achse fliege gibt es irgendwann ein Problem: Irgendwann fliege ich einfach nachhinten.
Ich habe eine Vermutung dass es am tan(x) liegt. Kann das Problem aber leider nicht näher spezifizieren...
Hier mal der Source-Code der Maussteuerung:
Hier der Code der die eigentliche Position nachher berechnet:
position[0] = x-Achse
position[1] = y-Achse
position[2] = z-Achse
Sieht jemand einen Fehler? Eventuell fehlt mir ja einfach eine Einschränkung einer Funktion auf einen bestimmten Wertebereich.
Danke!
Ich arbeite derzeit an einem 3D-Sonnensystem. Man soll als Beobachter (das Raumschiff) unser Sonnensystem erkunden können. Gesteuert wird per Maus und W (Schub nach vorne) und S (Umkehrschub). Mein "yaw" (Rotation um y-Achse) funktioniert ohne Probleme. Wenn ich aber einen Kreis um die x-Achse fliege gibt es irgendwann ein Problem: Irgendwann fliege ich einfach nachhinten.
Ich habe eine Vermutung dass es am tan(x) liegt. Kann das Problem aber leider nicht näher spezifizieren...
Hier mal der Source-Code der Maussteuerung:
Java:
public class MouseMovingControl extends AMovingControl {
public MouseMovingControl(OrbitSimulator orbitSim) {
super(orbitSim);
}
public void mouseMoved(MouseEvent e) {
this.orbitSim.mouseMotionStartX = e.getX();
this.orbitSim.mouseMotionStartY = e.getY();
}
public void mouseDragged(MouseEvent e) {
int x = e.getX();
int y = e.getY();
this.calcYAngle( (float)((x -this.orbitSim.mouseMotionStartX)));
this.calcXAngle((float)(-(y - this.orbitSim.mouseMotionStartY)));
this.orbitSim.mouseMotionStartX = x;
this.orbitSim.mouseMotionStartY = y;
this.orbitSim.repaint();
System.out.println(this.orbitSim.yaw + "y-Achse");
System.out.println(this.orbitSim.pitch +"x-Achse");
}
//Berechne Winkel um y-Achse
private void calcYAngle(float amount) {
float yaw = this.orbitSim.yaw;
yaw += amount;
while(yaw > 360 ||yaw < 0) {
if(yaw > 360) {
yaw -= 360;
}
if(yaw < 0) {
yaw += 360;
}
}
this.orbitSim.yaw = yaw;
}
//Berechne Winkel um x-Achse
private void calcXAngle(float amount) {
float pitch = this.orbitSim.pitch;
pitch += amount;
while(pitch > 360 ||pitch < 0) {
if(pitch > 360) {
pitch -= 360;
}
if(pitch < 0) {
pitch += 360;
}
}
this.orbitSim.pitch = pitch;
}
}
Hier der Code der die eigentliche Position nachher berechnet:
Java:
//Bewegung nach vorne
private void walkForward() {
this.orbitSim.position[0] -= this.speed * (float)Math.sin(Math.toRadians(this.orbitSim.yaw));
this.orbitSim.position[1] += this.speed * (float)Math.tan(Math.toRadians(this.orbitSim.pitch));
this.orbitSim.position[2] += this.speed * (float)Math.cos(Math.toRadians(this.orbitSim.yaw));
}
position[0] = x-Achse
position[1] = y-Achse
position[2] = z-Achse
Sieht jemand einen Fehler? Eventuell fehlt mir ja einfach eine Einschränkung einer Funktion auf einen bestimmten Wertebereich.
Danke!
Zuletzt bearbeitet: