1

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?

Z0q
  • 1,689
  • 3
  • 28
  • 57
  • 2
    Have you read the full documentation on how to read and use accelerometer input? https://github.com/libgdx/libgdx/wiki/Accelerometer – nhydock Nov 19 '15 at 21:19
  • I assume that your activity has full-sensor orientation defined in the app manifest. You can use the solution at http://stackoverflow.com/questions/19532599/rotating-phone-quickly-180-degrees-camera-preview-turns-upside-down/19599599#19599599 – Alex Cohn Nov 22 '15 at 07:59

1 Answers1

1

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.

Ttocsneb
  • 70
  • 11