Search code examples
androidcameralibgdx

Rotate camera on device rotation


How do I rotate a camera on device rotation?

This is what I tried to do:

float[] f = new float[16];
Gdx.input.getRotationMatrix( f );
Matrix4 m = new Matrix4( f );
m = m.scl( 0.01f );
cam.rotate( m );
cam.update();

The camera rotates waaaay too fast, but probably also not correctly. Any ideas?


Solution

  • I would think that using the accelerometer to rotate the camera would be easier than the Rotation matrix.

    If this is 2D, you would use:

    cam.rotate(Gdx.input.getAccelerometerX()*SCALE);
    

    This rotates the camera when you tilt the device left or right.