lwjgl FPS spectator mode

198 Views Asked by At

I'm trying to write a program that uses lwjgl, and it involves flying around in first person, sort of like spectator mode in an FPS game - you fly in whatever direction you're looking. I know how to do an FPS camera walking on the ground, but this is supposed to go up and down as well. I've tried to do something, but it's atrociously inaccurate.

The following code is in the class responsible for camera angle (positive y is up):

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

Thanks!

1

There are 1 best solutions below

0
On

Nvm, I figured it 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);
}