0

Say I have a character walking around in 2d space. Lets say my phone is flat on a table in landscape orientation.

If I tilt the phone away from me, the character should start moving up. If I tilt it towards me she should start moving down. Same goes for right and left.

The reason I ask here is because I found Google's explanation rather confusing. http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix%28float%5b%5d,%20float%5b%5d,%20float%5b%5d,%20float%5b%5d%29

This link implies the x and y are relative to compass coordinates? I can't imagine that's how the accelerometer works. I just want to do this relative to the phone being tilted on a certain axis.

For example, should the phone tilt away from me, I feel it should be easy to say "the phone is tilting ___ radians positively on the y axis." Then I should just be able to use trig to calculate the acceleration on my character.

I guess my real question is how do I read from the accelerometer and determine to what angle the phone is tilting on a given axis. This image details how I currently think the axis are laid out on the phone.This image details how I currently think the axis are laid out on the phone.

I'm sure this has been asked before, so a link to a good source of question solving is awesome as well.

DeepDeadpool
  • 1,441
  • 12
  • 36
  • The accelerometer measures movement, not absolute (static) orientation. I suppose that is why it makes use of the compass to get the orientation. I think you should look at the gyroscope sensor to get absolute orientation and information like the one you seek. – Zoltán Mar 24 '15 at 08:58
  • The accelerometer gives you a vector. It measures the acceleration currently experienced by the device, so if your device is just lying on a table it would measure -9,81 m/sˆ2 on the z axis, which is just the force of gravity. You can use that to calculate the current angle of the device with some [**trigonometry**](http://stackoverflow.com/questions/3755059/3d-accelerometer-calculate-the-orientation). – Xaver Kapeller Mar 24 '15 at 08:59
  • 1
    But the accelerometer doesn't just measure gravity, in fact it measures any acceleration. If you wave your device around than the measurements from the accelerometer are going to be all over the place. The Gyroscope is better in that regard as it will really just measure changes in the orientation. But there are two down sides to the Gyroscope: There is a constant drift and there is no way to find out what the initial orientation of the device is. A Gyroscope only measures changes in the orientation. – Xaver Kapeller Mar 24 '15 at 09:02

0 Answers0