CCAffineTransform CPhysicsObject::nodeToParentTransform() { CCSprite::nodeToParentTransform(); b2Vec2 pos = m_pB2body->GetPosition(); float x = pos.x * PTM_RATIO; float y = pos.y * PTM_RATIO; if ( isIgnoreAnchorPointForPosition() ) { x += m_obAnchorPointInPoints.x; y += m_obAnchorPointInPoints.y; } // Make matrix float radians = m_pB2body->GetAngle(); float c = cosf(radians); float s = sinf(radians); bool needsSkewMatrix = ( m_fSkewX || m_fSkewY ); if(!m_obAnchorPointInPoints.equals(CCPointZero) ){ x += c*-m_obAnchorPointInPoints.x * m_fScaleX + -s*-m_obAnchorPointInPoints.y*m_fScaleX; y += s*-m_obAnchorPointInPoints.x * m_fScaleY + 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 ); if (needsSkewMatrix) { CCAffineTransform skewMatrix = CCAffineTransformMake(1.0f, tanf(CC_DEGREES_TO_RADIANS(m_fSkewY)), tanf(CC_DEGREES_TO_RADIANS(m_fSkewX)), 1.0f, 0.0f, 0.0f ); m_sTransform = CCAffineTransformConcat(skewMatrix, m_sTransform); // adjust anchor point if (!m_obAnchorPointInPoints.equals(CCPointZero)) { m_sTransform = CCAffineTransformTranslate(m_sTransform, -m_obAnchorPointInPoints.x, -m_obAnchorPointInPoints.y); } } if (m_bAdditionalTransformDirty) { m_sTransform = CCAffineTransformConcat(m_sTransform, m_sAdditionalTransform); m_bAdditionalTransformDirty = false; } return m_sTransform; }
// returns the transform matrix according the Box2D Body values CCAffineTransform B2Sprite::nodeToParentTransform() { b2Vec2 pos = m_pB2Body->GetPosition(); float x = pos.x * m_fPTMRatio; float y = pos.y * m_fPTMRatio; if (m_bIgnoreAnchorPointForPosition) { x += m_obAnchorPointInPoints.x; y += m_obAnchorPointInPoints.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; }
// returns the transform matrix according the Chipmunk Body values CCAffineTransform PhysicsSprite::nodeToParentTransform(void) { b2Vec2 pos = m_pBody->GetPosition(); float x = pos.x * PTM_RATIO; float y = pos.y * PTM_RATIO; if ( isIgnoreAnchorPointForPosition() ) { x += m_tAnchorPointInPoints.x; y += m_tAnchorPointInPoints.y; } // Make matrix float radians = m_pBody->GetAngle(); float c = cosf(radians); float s = sinf(radians); if( ! m_tAnchorPointInPoints.equals(CCPointZero) ){ x += c*-m_tAnchorPointInPoints.x + -s*-m_tAnchorPointInPoints.y; y += s*-m_tAnchorPointInPoints.x + c*-m_tAnchorPointInPoints.y; } // Rot, Translate Matrix m_tTransform = CCAffineTransformMake( c, s, -s, c, x, y ); return m_tTransform; }
CCAffineTransform HSBalloonSprite::nodeToParentTransform() { b2Vec2 pos = m_pB2Body->GetPosition(); float x = pos.x * m_fPTMRatio; float y = pos.y * m_fPTMRatio; if (m_bIgnoreAnchorPointForPosition) { x += m_obAnchorPointInPoints.x; y += m_obAnchorPointInPoints.y; } // Make matrix float radians = m_pB2Body->GetAngle(); float c = cosf(radians); float s = sinf(radians); if (! m_obAnchorPointInPoints.equals(CCPointZero)) { x += c*(-m_obAnchorPointInPoints.x) + -s*(-m_obAnchorPointInPoints.y); y += s*(-m_obAnchorPointInPoints.x) + c*(-m_obAnchorPointInPoints.y); } // Rot, Transition Matrix m_sTransform = CCAffineTransformMake(c * m_fScale, s * m_fScale, -s * m_fScale, c * m_fScale, x, y); //return CCPhysicsSprite::nodeToParentTransform(); return m_sTransform; }
CCAffineTransform StaticBody::nodeToParentTransform(void) { b2Vec2 pos = m_pBody->GetPosition(); float x = pos.x * PTM_RATIO; float y = pos.y * PTM_RATIO; if (m_bIgnoreAnchorPointForPosition) { x += m_obAnchorPointInPoints.x; y += m_obAnchorPointInPoints.y; } // Make matrix float radians = m_pBody->GetAngle(); float c = cosf(radians); float s = sinf(radians); if (! m_obAnchorPointInPoints.equals(CCPointZero)) { x += c*(-m_obAnchorPointInPoints.x) + -s*(-m_obAnchorPointInPoints.y); y += s*(-m_obAnchorPointInPoints.x) + c*(-m_obAnchorPointInPoints.y); } // Rot, Transition Matrix m_sTransform = CCAffineTransformMake(c, s, -s, c, x, y); return m_sTransform; }
CCAffineTransform Skeleton2D_BoneDisplay::nodeToParentTransform(void){ m_sTransform=CCAffineTransformMake(m_mat.a,m_mat.b,m_mat.c,m_mat.d,m_mat.tx,m_mat.ty); if (!m_obAnchorPointInPoints.equals(CCPointZero)) { m_sTransform.tx -= m_sTransform.a * m_obAnchorPointInPoints.x + m_sTransform.c * m_obAnchorPointInPoints.y; m_sTransform.ty -= m_sTransform.b * m_obAnchorPointInPoints.x + m_sTransform.d * m_obAnchorPointInPoints.y; } return m_sTransform; }
// 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) { x += m_obAnchorPointInPoints.x; y += m_obAnchorPointInPoints.y; } return (m_sTransform = CCAffineTransformMake(rot.x, rot.y, -rot.y, rot.x, x, y)); }
CCBone::CCBone() { m_pTweenData = NULL; m_pParentBone = NULL; m_pArmature = NULL; m_pChildArmature = NULL; m_pBoneData = NULL; m_pTween = NULL; m_pTween = NULL; m_pChildren = NULL; m_pDisplayManager = NULL; m_bIgnoreMovementBoneData = false; m_tWorldTransform = CCAffineTransformMake(1, 0, 0, 1, 0, 0); m_bBoneTransformDirty = true; m_eBlendType = BLEND_NORMAL; }
CCAffineTransform cpCCNode::nodeToParentTransform ( KDvoid ) { cpBody* pBody = m_pImplementation->getBody ( ); cpVect tRot = m_pImplementation->isIgnoreRotation ( ) ? cpvforangle ( -CC_DEGREES_TO_RADIANS ( m_tRotation.x ) ) : pBody->rot; KDfloat x = pBody->p.x + tRot.x * -m_tAnchorPointInPoints.x - tRot.y * - m_tAnchorPointInPoints.y; KDfloat y = pBody->p.y + tRot.y * -m_tAnchorPointInPoints.x + tRot.x * - m_tAnchorPointInPoints.y; if ( m_pImplementation->isIgnoreRotation ( ) ) { x += m_tAnchorPointInPoints.x; y += m_tAnchorPointInPoints.y; } m_tTransform = CCAffineTransformMake ( tRot.x, tRot.y, -tRot.y, tRot.x, x, y ); return m_tTransform; }
Bone::Bone() { // CREATE_JS_OBJECT(Bone) m_pUserData = NULL; m_pTweenData = NULL; m_pCombinedData = NULL; m_pParent = NULL; m_pArmature = NULL; m_pChildArmature = NULL; m_pBoneData = NULL; m_pTween = NULL; m_pTween = NULL; m_pChildren = NULL; m_pDisplayManager = NULL; m_iZOrder = 0; m_bIgnoreMovementBoneData = false; m_pGlobalTransformMatrix = CCAffineTransformMake(1, 0, 0, 1, 0, 0); }
// returns the transform matrix according the Chipmunk 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; if (m_bIgnoreAnchorPointForPosition) { 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)); }
CCBone::CCBone() { m_pTweenData = NULL; m_pParentBone = NULL; m_pArmature = NULL; m_pChildArmature = NULL; m_pBoneData = NULL; m_pTween = NULL; m_pTween = NULL; m_pChildren = NULL; m_pDisplayManager = NULL; m_bIgnoreMovementBoneData = false; m_tWorldTransform = CCAffineTransformMake(1, 0, 0, 1, 0, 0); m_bBoneTransformDirty = true; m_tWorldInfo = NULL; m_pArmatureParentBone = NULL; m_fDataVersion = 0; m_sBlendFunc.src = CC_BLEND_SRC; m_sBlendFunc.dst = CC_BLEND_DST; m_bBlendDirty = false; }
CCAffineTransform GameObject::nodeToParentTransform(){ if (_isBox2DBody) { b2Vec2 pos = _pB2Body->GetPosition(); float x = pos.x * _ptmRadio; float y = pos.y * _ptmRadio; if (m_bIgnoreAnchorPointForPosition) { x += m_obAnchorPointInPoints.x; y += m_obAnchorPointInPoints.y; } float radians = _pB2Body->GetAngle(); float c = cosf(radians); float s = sinf(radians); 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)); } m_sTransform = CCAffineTransformMake( c * m_fScaleX, s * m_fScaleX, -s * m_fScaleY, c * m_fScaleY, x, y ); }else{ if (m_bTransformDirty) { // Translate values float x = m_obPosition.x; float y = m_obPosition.y; if (m_bIgnoreAnchorPointForPosition) { x += m_obAnchorPointInPoints.x; y += m_obAnchorPointInPoints.y; } // Rotation values // Change rotation code to handle X and Y // If we skew with the exact same value for both x and y then we're simply just rotating float cx = 1, sx = 0, cy = 1, sy = 0; if (m_fRotationX || m_fRotationY) { 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); } bool needsSkewMatrix = ( m_fSkewX || m_fSkewY ); // optimization: // inline anchor point calculation if skew is not needed // Adjusted transform calculation for rotational skew if (! needsSkewMatrix && !m_obAnchorPointInPoints.equals(CCPointZero)) { x += cy * -m_obAnchorPointInPoints.x * m_fScaleX + -sx * -m_obAnchorPointInPoints.y * m_fScaleY; y += sy * -m_obAnchorPointInPoints.x * m_fScaleX + cx * -m_obAnchorPointInPoints.y * m_fScaleY; } // Build Transform Matrix // Adjusted transform calculation for rotational skew m_sTransform = CCAffineTransformMake( cy * m_fScaleX, sy * m_fScaleX, -sx * m_fScaleY, cx * m_fScaleY, x, y ); // XXX: Try to inline skew // If skew is needed, apply skew and then anchor point if (needsSkewMatrix) { CCAffineTransform skewMatrix = CCAffineTransformMake(1.0f, tanf(CC_DEGREES_TO_RADIANS(m_fSkewY)), tanf(CC_DEGREES_TO_RADIANS(m_fSkewX)), 1.0f, 0.0f, 0.0f ); m_sTransform = CCAffineTransformConcat(skewMatrix, m_sTransform); // adjust anchor point if (!m_obAnchorPointInPoints.equals(CCPointZero)) { m_sTransform = CCAffineTransformTranslate(m_sTransform, -m_obAnchorPointInPoints.x, -m_obAnchorPointInPoints.y); } } if (m_bAdditionalTransformDirty) { m_sTransform = CCAffineTransformConcat(m_sTransform, m_sAdditionalTransform); m_bAdditionalTransformDirty = false; } m_bTransformDirty = false; } } return m_sTransform; }