Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have this mouse function in my LWJGL program:

public void mouseInput(){
    int mouseX = Mouse.getX();
    int mouseY = 600 - Mouse.getY();
    int mouseDX = 0, mouseDY = 0;
    int lastX = 0, lastY = 0;

    mouseDX = mouseX - lastX;
    mouseDY = mouseY - lastY;

    lastX = mouseX;
    lastY = mouseY;

    xrot += (float) mouseDX;
    yrot += (float) mouseDY;

}

I rotate the "camera" using this code:

glRotatef(xrot, 1.0f, 0.0f, 0.0f);
    glRotatef(yrot, 0.f, 1.0f, 0.0f);

And I call the mouseInput() function in the !DisplayIsClosedRequested loop. Currently this causes my game to freak out and my camera rotates all over the place even without me touching the mouse. The cubes I have rendered out also move around the screen randomely. I am using LWJGL, so I cant use any glut functions like glutPassiveMotionFunc(). Can anyone offer help? Basically in summary, my camera is very jerky and rotates the camera in random patterns very fast.

share|improve this question
How/when do you call this function? It should be called using a callback function. Also, lastX and lastY values is always 0, shouldn't they contain the X and Y values read in the previous iteration? – Dan Jan 5 at 0:35
Log / print Mouse.getX(), .getY() and. getDx(), .getDy(). Then you will know if it's what Mouse is returning or what your render code is doing that's causing the problem. Voting to close, as the focus of this question is too localized. – Nick Wiggill Jan 5 at 0:37
You need to define lastX and lastY outside the function. – eBusiness Jan 5 at 0:41
What should I define them as? – opiop65 Jan 5 at 0:43
Why do you dont use the getDX and getDY Methods of the Mouse class in LWJGL? lwjgl.org/javadoc/org/lwjgl/input/Mouse.html#getDX() – Aron_dc Feb 3 at 14:02

closed as too localized by Nick Wiggill, eBusiness, Josh Petrie, Trevor Powell, Sean Middleditch Jan 5 at 21:48

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

Browse other questions tagged or ask your own question.