我正在开发cocos2dx游戏并开展圆形手势检测。我想问一下如何找到两点之间的角度。如何找到两点A和B.my ccTouchesMoved事件之间的角度如下。
void HelloWorld::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
{
CCLog("Touches moved");
CCTouch *touch = (CCTouch*)pTouches->anyObject();
location = touch->getLocation();
location=CCDirector::sharedDirector()->convertToGL(location);
prevLocation=CCDirector::sharedDirector()->convertToGL(touch->getPreviousLocationInView());
deltax=prevLocation.x-location.x;//difference of x
deltay=prevLocation.y-location.x;//difference of y
angle=??// i want this angle using deltax and deltay
}
答案 0 :(得分:3)
您需要包含数学标题,您可以使用公式计算角度:
angle = atan2 (deltay, deltax) * (180 / PI);