【问题标题】:lwjgl FPS spectator modelwjgl FPS观众模式
【发布时间】:2013-09-25 01:56:59
【问题描述】:

我正在尝试编写一个使用 lwjgl 的程序,它涉及以第一人称飞行,有点像 FPS 游戏中的旁观者模式——你可以向任何你看的方向飞行。我知道如何让 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 );
}

谢谢!

【问题讨论】:

  • 请不要混淆答案和问题 - 即使您自己回答。如果你能改正就好了。

标签: camera lwjgl trigonometry frame-rate clay


【解决方案1】:

Nvm,我想通了-

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);
}

【讨论】:

    猜你喜欢
    • 2011-03-22
    • 2012-06-25
    • 1970-01-01
    • 1970-01-01
    • 2020-02-29
    • 2020-04-22
    • 1970-01-01
    • 2012-09-06
    • 1970-01-01
    相关资源
    最近更新 更多