开发者

Iphone-SDK: accelerometer x,z to 360 degrees?

开发者 https://www.devze.com 2022-12-16 05:44 出处:网络
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)

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 (开发者_StackOverflow社区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?


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

#include <math.h>

...

float degrees = atan2(x, y) * 180 / 3.14159;
0

精彩评论

暂无评论...
验证码 换一张
取 消