mirror of https://github.com/axmolengine/axmol.git
issue #1686:synchronize CCPhysicsSprite.cpp
This commit is contained in:
parent
d4abc272c0
commit
510c54ffb0
|
@ -210,17 +210,22 @@ void CCPhysicsSprite::setRotation(float fRotation)
|
|||
// returns the transform matrix according the Chipmunk Body values
|
||||
CCAffineTransform CCPhysicsSprite::nodeToParentTransform()
|
||||
{
|
||||
cpVect rot = (m_bIgnoreBodyRotation ? cpvforangle(-CC_DEGREES_TO_RADIANS(m_fRotationX)) : m_pCPBody->rot);
|
||||
float x = m_pCPBody->p.x + rot.x*(-m_obAnchorPointInPoints.x) - rot.y*(-m_obAnchorPointInPoints.y);
|
||||
float y = m_pCPBody->p.y + rot.y*(-m_obAnchorPointInPoints.x) + rot.x*(-m_obAnchorPointInPoints.y);
|
||||
|
||||
if (m_bIgnoreAnchorPointForPosition)
|
||||
// Although scale is not used by physics engines, it is calculated just in case
|
||||
// the sprite is animated (scaled up/down) using actions.
|
||||
// For more info see: http://www.cocos2d-iphone.org/forum/topic/68990
|
||||
cpVect rot = (m_bIgnoreBodyRotation ? cpvforangle(-CC_DEGREES_TO_RADIANS(m_fRotationX)) : m_pCPBody->rot);
|
||||
float x = m_pCPBody->p.x + rot.x * -m_obAnchorPointInPoints.x * m_fScaleX - rot.y * -m_obAnchorPointInPoints.y * m_fScaleY;
|
||||
float y = m_pCPBody->p.y + rot.y * -m_obAnchorPointInPoints.x * m_fScaleX + rot.x * -m_obAnchorPointInPoints.y * m_fScaleY;
|
||||
|
||||
if (m_bIgnoreAnchorPointForPosition)
|
||||
{
|
||||
x += m_obAnchorPointInPoints.x;
|
||||
y += m_obAnchorPointInPoints.y;
|
||||
}
|
||||
|
||||
return (m_sTransform = CCAffineTransformMake(rot.x, rot.y, -rot.y, rot.x, x, y));
|
||||
x += m_obAnchorPointInPoints.x;
|
||||
y += m_obAnchorPointInPoints.y;
|
||||
}
|
||||
|
||||
return (m_sTransform = CCAffineTransformMake(rot.x * m_fScaleX, rot.y * m_fScaleX,
|
||||
-rot.y * m_fScaleY, rot.x * m_fScaleY,
|
||||
x, y));
|
||||
}
|
||||
|
||||
#elif CC_ENABLE_BOX2D_INTEGRATION
|
||||
|
@ -285,12 +290,10 @@ void CCPhysicsSprite::setRotation(float fRotation)
|
|||
// returns the transform matrix according the Box2D Body values
|
||||
CCAffineTransform CCPhysicsSprite::nodeToParentTransform()
|
||||
{
|
||||
// Although scale is not used by physics engines, it is calculated just in case
|
||||
// the sprite is animated (scaled up/down) using actions.
|
||||
// For more info see: http://www.cocos2d-iphone.org/forum/topic/68990
|
||||
cpVect rot = (m_bIgnoreBodyRotation ? cpvforangle(-CC_DEGREES_TO_RADIANS(m_fRotationX)) : m_pCPBody->rot);
|
||||
float x = m_pCPBody->p.x + rot.x * -m_obAnchorPointInPoints.x * m_fScaleX - rot.y * -m_obAnchorPointInPoints.y * m_fScaleY;
|
||||
float y = m_pCPBody->p.y + rot.y * -m_obAnchorPointInPoints.x * m_fScaleX + rot.x * -m_obAnchorPointInPoints.y * m_fScaleY;
|
||||
b2Vec2 pos = _b2Body->GetPosition();
|
||||
|
||||
float x = pos.x * m_fPTMRatio;
|
||||
float y = pos.y * m_fPTMRatio;
|
||||
|
||||
if (m_bIgnoreAnchorPointForPosition)
|
||||
{
|
||||
|
@ -298,9 +301,26 @@ CCAffineTransform CCPhysicsSprite::nodeToParentTransform()
|
|||
y += m_obAnchorPointInPoints.y;
|
||||
}
|
||||
|
||||
return (m_sTransform = CCAffineTransformMake(rot.x * m_fScaleX, rot.y * m_fScaleX,
|
||||
-rot.y * m_fScaleY, rot.x * m_fScaleY,
|
||||
x, y));
|
||||
// Make matrix
|
||||
float radians = m_pB2Body->GetAngle();
|
||||
float c = cosf(radians);
|
||||
float s = sinf(radians);
|
||||
|
||||
// Although scale is not used by physics engines, it is calculated just in case
|
||||
// the sprite is animated (scaled up/down) using actions.
|
||||
// For more info see: http://www.cocos2d-iphone.org/forum/topic/68990
|
||||
if (! (m_obAnchorPointInPoints.equals(CCPointZero))
|
||||
{
|
||||
x += ((c * -m_obAnchorPointInPoints.x * m_fScaleX) + (-s * -m_obAnchorPointInPoints.y * m_fScaleY));
|
||||
y += ((s * -m_obAnchorPointInPoints.x * m_fScaleX) + (c * -m_obAnchorPointInPoints.y * m_fScaleY));
|
||||
}
|
||||
|
||||
// Rot, Translate Matrix
|
||||
m_sTransform = CCAffineTransformMake( c * m_fScaleX, s * m_fScaleX,
|
||||
-s * m_fScaleY, c * m_fScaleY,
|
||||
x, y );
|
||||
|
||||
return m_sTransform;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue