views:

425

answers:

1

How is it possible to take the x,z values produced by the accelerometer and translate it as values that will represent a point in 360 degrees of the iphone rotation? (LANDSCAPED) it can be -2 to 2 (0 for the middle point) and it can be 0 to 360, as long as it represents a value for the whole iphone rotation.

I need it for a Landscape game im making what is the best solution in that case?

+1  A: 

Use the atan2() function. To get a value in degrees:

#include <math.h>

...

float degrees = atan2(x, y) * 180 / 3.14159;
Frank Schmitt
Its almost as perfect, i do:atan2(AccX,Accz) * 180 / 3.14159one problem: the max/min value is when the screen is aimed up how do i change it so that value is when the iphone's back is turned to me?
Alon Amir
changing it to atan2(-AccZ,-AccX) did that trick.
Alon Amir