bTa*_*ger 6 objective-c cocos2d-iphone
我想获得两条线之间的角度.所以我使用了这段代码.
int posX = (ScreenWidth) >> 1;
int posY = (ScreenHeight) >> 1;
double radians, degrees;
radians = atan2f( y - posY , x - posX);
degrees = -CC_RADIANS_TO_DEGREES(radians);
NSLog(@"%f %f",degrees,radians);
Run Code Online (Sandbox Code Playgroud)
但它不起作用.日志是:146.309935 -2.553590
怎么了?我不知道原因.请帮我.

如果你只是使用
radians = atan2f( y - posY , x - posX);
Run Code Online (Sandbox Code Playgroud)
你会得到水平线的角度y=posY(蓝色角度).

您需要添加M_PI_2弧度值才能获得正确的结果.
| 归档时间: |
|
| 查看次数: |
4427 次 |
| 最近记录: |