2013-09-25 28 views
0

我試圖編寫一個使用lwjgl的程序,它涉及在第一人稱飛行,有點像FPS遊戲中的觀衆模式 - 您可以在任何方向飛行。我知道如何做一個FPS相機在地面上行走,但這也應該上下。我嘗試過做一些事情,但這種做法非常不準確。lwjgl FPS觀衆模式

下面的代碼是負責相機角度類(正y是向上):

public void move(double mx, double my, double mz) 
{ 
    this.x += mx; 
    this.y += my; 
    this.z += mz; 
} 


public void moveForward() 
{ 
    rx = toDeg(rx); 
    float speed = 0.25f; 
    double xsin = Math.sin(Math.toRadians(rx)); 
    double ysin = Math.sin(Math.toRadians(
     (ry + Math.signum(toDeg(rx + 90.00001f) - 180) * -90) 
    )); 
    double ycos = Math.cos(Math.toRadians(
     (ry + Math.signum(toDeg(rx + 90.00001f) - 180) * -90) 
    )); 
    this.move(speed * ycos, speed * xsin, speed * ysin); 
} 

謝謝!

+0

請不要混淆了答案和問題 - 即使你自己回答這些問題。如果你能糾正這種情況,那將會很好。 – Jost

回答

0

NVM,我想這OUT-

public void moveForward() 
{ 
    rx = toDeg(rx); 
    float speed = 0.25f; 
    double xsin = Math.sin(Math.toRadians(rx)); 
    double xcos = Math.cos(Math.toRadians(rx)); 
    double flatLen = xcos * speed; 
    double ysin = Math.sin(Math.toRadians((ry + 90))); 
    double ycos = Math.cos(Math.toRadians((ry + 90))); 
    this.move(
      flatLen * ycos, 
      speed * xsin, 
      flatLen * ysin); 
}