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