Hi, I have accelerometer values for the 3 axis(usually when there is only gravity contains data between -1.0 and 1.0 ):
float Rx;
float Ry;
float Rz;
I make soma calculations, then I get the angles for each axis.
float R = sqrt(pow(Rx,2)+pow(Ry,2)+pow(Rz,2));
float Arx = acos(Rx/R)*180/M_PI;
float Ary = acos(Ry/R)*180/M_PI;
float Arz = acos(Rz/R)*180/M_PI;
Then I set the values for the box angles in opengl
rquad = Arx;
yquad = Ary;
Which rotates my box:
glRotatef(yquad,1.0f,0.0f,0.0f);
glRotatef(rquad,0.0f,1.0f,0.0f);
It work on hemisphere. I would like to use the full sphere and I know that I have to use the Arz value to make it work, but I don't know how can I use that for this rotation. Could you help me?
Update: The final answer is in my case:
rquad = -atan2(Rx/R, Rz/R)*180/M_PI;
yquad = -atan2(Ry/R, Rz/R)*180/M_PI;