如何在cocos2dx中找到两个圆点之间的角度

时间:2014-03-26 18:03:35

标签: cocos2d-x

我正在开发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

}

1 个答案:

答案 0 :(得分:3)

您需要包含数学标题,您可以使用公式计算角度:

angle = atan2 (deltay, deltax) * (180 / PI);