1

I have this mouse function in my OpenGL 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.

1 Answers1

0

If the camera is rotating even when you are not touching the mouse, you are probably applying the rotation over and over again. You could reset the camera view matrix first (glLoadIdentity() in OpenGL 2 fixed-functionality), every frame, and then apply the rotation. That way you will only rotate from a fixed reference point every frame, instead of the last reference point which was the result of a rotation from a previous frame.

Victor Zamanian
  • 3,100
  • 24
  • 31