I've just started writing a 3D First Person Shooter in Java, and I'm having a bit of trouble with tracking the mouse movements and moving the camera accordingly. I'm implementing typical FPS movement, in that the mouse stays at the center of the screen.
Moving the mouse left and right (horizontal movement) is fine - each time the mouse is moved, I get it's position on the screen. I then use atan2
to get the angle I need to rotate around the y axis to get to this position, and apply the rotation accordingly.
My problem is when I try to change the pitch of the view (i.e. rotating around the x axis - essentially looking up and down). I can get the y coordinate of the mouse, and the y coordinate of the center of the screen, but how do I calculate how much I need to rotate around the x axis to get to that point?
Thanks in advance!
double yRad = Math.atan2(mouseX, centerX);
, so theoretically to get the x rotation, I should usedouble xRad = Math.atan2(mouseX, centerX)
, correct? This is giving me some very weird/erratic behaviour (and thus I thought I must have been doing something wrong). \$\endgroup\$mouseY
andcenterY
. \$\endgroup\$Math.atan2(mouseY, centerY);
* \$\endgroup\$