So, I have lately gotten into 3D game development with libGDX and I managed to get models into the game. Now I am trying to create a camera for the game, an FPS camera to be exact. When I rotate just the pitch it works perfectly, I can look up and down. And when I rotate just the rotation it works fine too, I can look left and right. But when I combine the two and start rotating the camera in both the x and y axis i start getting weird effects:
It seems that the z axis starts getting messed up. What am I doing wrong? My code is below.
@Override
public boolean mouseMoved(int screenX, int screenY) {
calculateRotation(screenX - oldX);
oldX = screenX;
calculatePitch(screenY - oldY);
oldY = screenY;
camera.rotateAround(camera.position, Vector3.Y, -rotation);
camera.rotateAround(camera.position, Vector3.X, pitch);
return true;
}
private void calculatePitch(int y) {
float pitchChange = y * 0.4f;
pitch = (int) -pitchChange;
}
private void calculateRotation(int x) {
float rotationChange = x * 0.4f;
rotation = (int) rotationChange;
}