OpenGL first person jumping code I'm making a game in Java with LWJGL and I just implemented jumping. I don't really think the code is particularly well written or very efficient. Here is the code of my Camera class:

public void startJump(float height, float land){
    jumpHeight = height;
    jumpLand = land;
    if(!falling &amp;&amp; !jumping)
        jumping = true;
}

private void jump(){ // called every frame
    if(jumping){
        if(y &gt;= -jumpHeight){
            y -= jumpSpeed;
        }else{
            jumping = false;
            falling = true;
        }
    }

    if(falling){
        if(y &lt;= -jumpLand){
            y += jumpSpeed;
        }else{
            jumping = false;
            falling = false;
        }
    }
}


If someone knows a cleaner or more efficient method please tell me!

EDIT:

I was thinking of using jumping and !jumping but this introduces a bug where if the jump key is held down then the player hovers in the air so unless your making a jet-pack use jumping and falling.
After your comment, the only change i could say is to change

private void jump(){ // called every frame
    if(jumping){
        if(y &gt;= -jumpHeight){
            y -= jumpSpeed;
        }else{
            jumping = false;
            falling = true;
        }
    }

    if(falling){


to

private void jump(){ // called every frame
    if(jumping){
        if(y &gt;= -jumpHeight){
            y -= jumpSpeed;
        }else{
            jumping = false;
            falling = true;
        }
    }

    else if(falling){


To avoid to check falling too if it's jumping. But its a macro optimization (useless too maybe in this case.)
But really, this code is perfect how it is. So go ahead!

Just got this idea in my mind: you could define a "PlayerStatus" enum with: Falling, Jumping but it will affect the logic of your game, change it only if you think you will need more status and maintain two boolean variables (or more if you add more conditions) will be hard. If you need only one turned on and others off.. it's a great way to do it:

enum PlayerStatus
{
    FALLING,
    JUMPING
}


and use the enum to change the status..

PlayerStatus status;
status = PlayerStatus.FALLING;