0

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!

knarf2011
  • 53
  • 1
  • 7
  • Please don't mix up answers and questions - even if you answer them yourself. It would be nice if you could correct that. – Jost Sep 25 '13 at 11:50

1 Answers1

0

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);
}
knarf2011
  • 53
  • 1
  • 7