cocos2dx2.2中CCNode::nodeToParentTransform存在的疑问
在函数CCNode::nodeToParentTransform中存在一下代码片段:
CCAffineTransform CCNode::nodeToParentTransform(void){ ............................ float radiansX = -CC_DEGREES_TO_RADIANS(m_fRotationX); float radiansY = -CC_DEGREES_TO_RADIANS(m_fRotationY); cx = cosf(radiansX); sx = sinf(radiansX); cy = cosf(radiansY); sy = sinf(radiansY); .............................. m_sTransform = CCAffineTransformMake( cy * m_fScaleX, sy * m_fScaleX, -sx * m_fScaleY, cx * m_fScaleY, x, y ); }
假设m_fScaleX, m_fScaleY为1,x, y为0,则旋转矩阵为:
貌似这个矩阵是存在问题的,当我们只对X轴进行旋转时得到的效果如下:
旋转代码片段如下:
CCSprite* pSprite = CCSprite::create("HelloWorld.png"); pSprite->setPosition(ccp(0,0)); pSprite->setAnchorPoint(ccp(0,0)); pSprite->setRotationX(45); this->addChild(pSprite, 0);
个人觉得,既然是对X方向进行旋转,Y坐标不应该改变,而从图片上看Y坐标已经变了。
现在对源代码进行更改,如下:
m_sTransform = CCAffineTransformMake( cx * m_fScaleX, sy * m_fScaleX, -sx * m_fScaleY, cy * m_fScaleY, x, y );
即将cx和cy的位置换一下,转换矩阵如下:
然后重新运行代码得到的结果如下:
这样与我预期的结果是一样的~~。
求大神指正!