How can I covert Accelerometer data to degrees?

bladeolsonbladeolson Member Posts: 295
edited November -1 in Working with GS (Mac)
I made an object that shows the degrees of the accelerometer. but the acceleromoter data is like 0.001 to 1.0 , is there a way to convert it to 0 to 360 derees? I tried to multiply by 100 and that got me half of it, but it does not work for the negative range of numbers.

I could use some help.

Thanks,

blade

Comments

  • bladeolsonbladeolson Member Posts: 295
    anyone have an idea on this one? I can't figure it out...
  • firemaplegamesfiremaplegames Member Posts: 3,211
    In the above example, simply multiply by 360 instead of 100.

    0 * 360 = 0
    0.5 * 360 = 180
    1 * 360 = 360

    Is that what you were looking for? I haven't messed with the accelerometers yet.
    Does it go from 0 to 1, or does it actually go from -1 to 1?

    Joe
  • firemaplegamesfiremaplegames Member Posts: 3,211
    If it does go from [-1,1] and you need to change the range to [0,360], you could multiply the original number by 180, then add 180 to that number.

    So:

    The accelerometer gives you a number in the range of [-1,1]
    Multiply that by 180 to get a number in the range of [-180,180]
    Add 180 to that to get a number in the range of [0,360]

    Thus:

    self.myAngle = ([AccelerometerValue] * 180) + 180

    There are other ways to do this I'm sure, but that should get you what you need.
  • netdzynrnetdzynr Member Posts: 296
    You might try combining FMG's info with the game.Screen.Device Orientation. When holding the device vertically and rotating it along its length, the Device Orientation will be an integer value from 0 to 3. The problem is, Device Orientation seems to return a value of 6 when the device is at a 45 degree angle. Not sure how to account for this, but essentially you might be able to tell what orientation the device is in, and multiply accordingly.
  • bladeolsonbladeolson Member Posts: 295
    SO if I hold in portrait, it is 0 . go to left on X axis it goes to negative 1 at 270 and positive 1 at 90 when going right.

    then it flips from 90+ again to go from .90 back to 0 again at 180 from the orginal position. So somehow I guess I need to determine if I am past 90 or 270 and adjust accordingly.
  • bladeolsonbladeolson Member Posts: 295
    thanks for the great ideas. I am still trying to figure it out. I can get it from 270 to 90 position just fine, but can't figure out how to do the other half.
  • bladeolsonbladeolson Member Posts: 295
    I have pulled half of the hair I have left out trying to figure this out. there has to be a simple solution, just can't seem to make it work. i would totally appreciate someone with some super brains to help me.

    blade
Sign In or Register to comment.