Search code examples
javamouselwjgl

java lwjgl setting the mouses position without changing dx or dy


Hello I am making a 3D game and now that I've started making something that lets the user interact with a mouse I have been a little stuck (well really stuck). What I'm trying to do is when the user moves the mouse it gets moved back to the centre (or were the coordinates I entered are) without effecting the Mouse.getDX() and Mouse.getDY(). Here is my code for the part were I test for moving the mouse.

    public void onMouser(){
    yaw+=Mouse.getDX();
    pitch-=Mouse.getDY();

    Mouse.setCursorPosition(750, 500);
}

Thanks in Advance


Solution

  • public void calculatePitchAndYaw() {
        pitch += Mouse.getY() - HEIGHT /2;
        yaw += Mouse.getX - WIDTH / 2;
        Mouse.setCursorPosition(WIDTH / 2, HEIGHT /2);
    }
    

    Try something like this. So you wont turn back to your initial position.