智慧 + 毅力 = 无所不能

正确性、健壮性、可靠性、效率、易用性、可读性、可复用性、兼容性、可移植性...

导航

cocos2d-x 屏幕坐标系和OPenGL坐标系转换

Posted on 2013-07-11 09:28  Bill Yuan  阅读(4637)  评论(0编辑  收藏  举报

转自:http://home.cnblogs.com/group/topic/57609.html

cocos2d坐标系(OPenGL坐标系):以左下角为原点,x向右,y向上

屏幕坐标系(android,ios,win32系统的坐标系):以左上角为原点,X轴向右为正,y轴向下为正

 

在cocos2dx的test例子中:

void TestController::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
    CCSetIterator it = pTouches->begin();
    CCTouch* touch = (CCTouch*)(*it);


    CCPoint  m_tBeginPos = touch->locationInView();    
    m_tBeginPos = CCDirector::sharedDirector()->convertToGL( m_tBeginPos );
}

 

CCTouch中触摸点的位置是使用屏幕坐标系的,

convertToGL把屏幕坐标系的点的位置转成OPengl坐标系的位置

 

OPenGL坐标系和屏幕坐标系都是x最大值不超过窗口的宽,y最大值不超过窗口的高,也就是屏幕向上或向下滚动后,坐原点是固定的,不会随屏幕滚动