void CCBone::update(float delta) { if (m_pParentBone) m_bBoneTransformDirty = m_bBoneTransformDirty || m_pParentBone->isTransformDirty(); if (m_bBoneTransformDirty) { if (m_pArmature->getArmatureData()->dataVersion >= VERSION_COMBINED) { CCTransformHelp::nodeConcat(*m_pTweenData, *m_pBoneData); m_pTweenData->scaleX -= 1; m_pTweenData->scaleY -= 1; } CCTransformHelp::nodeToMatrix(*m_pTweenData, m_tWorldTransform); m_tWorldTransform = CCAffineTransformConcat(nodeToParentTransform(), m_tWorldTransform); if(m_pParentBone) { m_tWorldTransform = CCAffineTransformConcat(m_tWorldTransform, m_pParentBone->m_tWorldTransform); } } CCDisplayFactory::updateDisplay(this, m_pDisplayManager->getCurrentDecorativeDisplay(), delta, m_bBoneTransformDirty || m_pArmature->getArmatureTransformDirty()); CCObject *object = NULL; CCARRAY_FOREACH(m_pChildren, object) { CCBone *childBone = (CCBone *)object; childBone->update(delta); }
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; }
void CS_DISPLAY_UPDATE(Bone *bone, DecorativeDisplay *decoDisplay, float dt, bool dirty) { CS_RETURN_IF(!decoDisplay); #if ENABLE_PHYSICS_DETECT if (dirty) { ColliderDetector *detector = decoDisplay->getColliderDetector(); if (detector) { CCAffineTransform t = CCAffineTransformConcat(bone->nodeToArmatureTransform(), bone->getArmature()->nodeToWorldTransform()); detector->updateTransform(t); } } #endif switch(decoDisplay->getDisplayData()->displayType) { case CS_DISPLAY_SPRITE: CS_DISPLAY_SPRITE_UPDATE(bone, decoDisplay, dt, dirty); break; case CS_DISPLAY_PARTICLE: CS_DISPLAY_PARTICLE_UPDATE(bone, decoDisplay, dt, dirty); break; case CS_DISPLAY_ARMATURE: CS_DISPLAY_ARMATURE_UPDATE(bone, decoDisplay, dt, dirty); break; case CS_DISPLAY_NODE: CS_DISPLAY_NODE_UPDATE(bone, decoDisplay, dt, dirty); break; default: break; } }
CCAffineTransform CCNode::nodeToWorldTransform() { CCAffineTransform t = this->nodeToParentTransform(); for (CCNode *p = m_pParent; p != NULL; p = p->getParent()) t = CCAffineTransformConcat(t, p->nodeToParentTransform()); return t; }
void TransformHelp::transformToParent(Node &node, const Node &parentNode) { nodeToMatrix(node, helpMatrix1); nodeToMatrix(parentNode, helpMatrix2); helpMatrix1 = CCAffineTransformConcat(helpMatrix1, helpMatrix2); matrixToNode(helpMatrix1, node); }
void CCTransformHelp::transformFromParent(CCBaseData &node, const CCBaseData &parentNode) { nodeToMatrix(node, helpMatrix1); nodeToMatrix(parentNode, helpMatrix2); helpMatrix2 = CCAffineTransformInvert(helpMatrix2); helpMatrix1 = CCAffineTransformConcat(helpMatrix1, helpMatrix2); matrixToNode(helpMatrix1, node); }
void CCBone::update(float delta) { if (m_pParentBone) m_bBoneTransformDirty = m_bBoneTransformDirty || m_pParentBone->isTransformDirty(); if (m_pArmatureParentBone && !m_bBoneTransformDirty) { m_bBoneTransformDirty = m_pArmatureParentBone->isTransformDirty(); } if (m_bBoneTransformDirty) { if (m_fDataVersion >= VERSION_COMBINED) { CCTransformHelp::nodeConcat(*m_pTweenData, *m_pBoneData); m_pTweenData->scaleX -= 1; m_pTweenData->scaleY -= 1; } m_tWorldInfo->x = m_pTweenData->x + m_obPosition.x; m_tWorldInfo->y = m_pTweenData->y + m_obPosition.y; m_tWorldInfo->scaleX = m_pTweenData->scaleX * m_fScaleX; m_tWorldInfo->scaleY = m_pTweenData->scaleY * m_fScaleY; m_tWorldInfo->skewX = m_pTweenData->skewX + m_fSkewX + m_fRotationX; m_tWorldInfo->skewY = m_pTweenData->skewY + m_fSkewY - m_fRotationY; if(m_pParentBone) { applyParentTransform(m_pParentBone); } else { if (m_pArmatureParentBone) { applyParentTransform(m_pArmatureParentBone); } } CCTransformHelp::nodeToMatrix(*m_tWorldInfo, m_tWorldTransform); if (m_pArmatureParentBone) { m_tWorldTransform = CCAffineTransformConcat(m_tWorldTransform, m_pArmature->nodeToParentTransform()); } } CCDisplayFactory::updateDisplay(this, delta, m_bBoneTransformDirty || m_pArmature->getArmatureTransformDirty()); CCObject *object = NULL; CCARRAY_FOREACH(m_pChildren, object) { CCBone *childBone = (CCBone *)object; childBone->update(delta); }
CCAffineTransform CCSkin::nodeToWorldTransformAR() { CCAffineTransform displayTransform = m_sTransform; CCPoint anchorPoint = m_obAnchorPointInPoints; anchorPoint = CCPointApplyAffineTransform(anchorPoint, displayTransform); displayTransform.tx = anchorPoint.x; displayTransform.ty = anchorPoint.y; return CCAffineTransformConcat(displayTransform, m_pBone->getArmature()->nodeToWorldTransform()); }
void CCDisplayFactory::updateDisplay(CCBone *bone, float dt, bool dirty) { CCNode *display = bone->getDisplayRenderNode(); CS_RETURN_IF(!display); switch(bone->getDisplayRenderNodeType()) { case CS_DISPLAY_SPRITE: if (dirty) { (static_cast<CCSkin*>(display))->updateArmatureTransform(); } break; case CS_DISPLAY_PARTICLE: updateParticleDisplay(bone, display, dt); break; case CS_DISPLAY_ARMATURE: updateArmatureDisplay(bone, display, dt); break; default: display->setAdditionalTransform(bone->nodeToArmatureTransform()); break; } #if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT || ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX if (dirty) { CCDecorativeDisplay *decoDisplay = bone->getDisplayManager()->getCurrentDecorativeDisplay(); CCColliderDetector *detector = decoDisplay->getColliderDetector(); if (detector) { do { #if ENABLE_PHYSICS_BOX2D_DETECT CC_BREAK_IF(!detector->getBody()); #elif ENABLE_PHYSICS_CHIPMUNK_DETECT CC_BREAK_IF(!detector->getBody()); #endif CCAffineTransform displayTransform = display->nodeToParentTransform(); CCPoint anchorPoint = display->getAnchorPointInPoints(); anchorPoint = CCPointApplyAffineTransform(anchorPoint, displayTransform); displayTransform.tx = anchorPoint.x; displayTransform.ty = anchorPoint.y; CCAffineTransform t = CCAffineTransformConcat(displayTransform, bone->getArmature()->nodeToParentTransform()); detector->updateTransform(t); } while (0); } } #endif }
void CCDisplayFactory::updateDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay, float dt, bool dirty) { CS_RETURN_IF(!decoDisplay); #if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT if (dirty) { CCColliderDetector *detector = decoDisplay->getColliderDetector(); if (detector) { do { #if ENABLE_PHYSICS_BOX2D_DETECT CC_BREAK_IF(!detector->getBody()); #elif ENABLE_PHYSICS_CHIPMUNK_DETECT CC_BREAK_IF(!detector->getBody()); #endif CCNode *node = decoDisplay->getDisplay(); CCAffineTransform displayTransform = node->nodeToParentTransform(); CCPoint anchorPoint = node->getAnchorPointInPoints(); anchorPoint = CCPointApplyAffineTransform(anchorPoint, displayTransform); displayTransform.tx = anchorPoint.x; displayTransform.ty = anchorPoint.y; CCAffineTransform t = CCAffineTransformConcat(displayTransform, bone->getArmature()->nodeToParentTransform()); detector->updateTransform(t); } while (0); } } #endif CCNode *display = decoDisplay->getDisplay(); switch(decoDisplay->getDisplayData()->displayType) { case CS_DISPLAY_SPRITE: updateSpriteDisplay(bone, display, dt, dirty); break; case CS_DISPLAY_PARTICLE: updateParticleDisplay(bone, display, dt, dirty); break; case CS_DISPLAY_ARMATURE: updateArmatureDisplay(bone, display, dt, dirty); break; default: { display->setAdditionalTransform(bone->nodeToArmatureTransform()); } break; } }
void TransformHelp::transformToParentWithoutScale(Node &node, const Node &parentNode) { helpParentNode.copy(&parentNode); helpParentNode.scaleX = 1; helpParentNode.scaleY = 1; nodeToMatrix(node, helpMatrix1); nodeToMatrix(helpParentNode, helpMatrix2); helpMatrix1 = CCAffineTransformConcat(helpMatrix1, helpMatrix2); matrixToNode(helpMatrix1, node); }
void CCTransformHelp::transformFromParentWithoutScale(CCBaseData &node, const CCBaseData &parentNode) { helpParentNode.copy(&parentNode); helpParentNode.scaleX = 1; helpParentNode.scaleY = 1; nodeToMatrix(node, helpMatrix1); nodeToMatrix(helpParentNode, helpMatrix2); helpMatrix2 = CCAffineTransformInvert(helpMatrix2); helpMatrix1 = CCAffineTransformConcat(helpMatrix1, helpMatrix2); matrixToNode(helpMatrix1, node); }
//------------------------------------------------------------------------------ void QLabel::CalculateSize( void) { CCPoint bottom_left( 0.0f, 0.0f); CCSize content_size = m_CCFontNode->getContentSize(); CCPoint top_right( content_size.width, content_size.height); CCAffineTransform to_parent = CCAffineTransformConcat(m_CCFontNode->nodeToParentTransform(), m_CCNode->nodeToParentTransform()); bottom_left = CCPointApplyAffineTransform( bottom_left, to_parent); top_right = CCPointApplyAffineTransform( top_right, to_parent); xText = bottom_left.x; yText = bottom_left.y; wText = top_right.x - bottom_left.x; hText = top_right.y - bottom_left.y; }
CCAffineTransform GAFSprite::nodeToParentTransform(void) { if (_useExternalTransform) { if (m_bTransformDirty) { m_sTransform = CCAffineTransformTranslate(_externalTransform, -m_obAnchorPointInPoints.x, -m_obAnchorPointInPoints.y); m_bTransformDirty = false; GAFSprite * parent = dynamic_cast<GAFSprite*>(m_pParent); if (parent && parent->isUseChildTransform()) { m_sTransform = CCAffineTransformConcat(m_sTransform, parent->childTransform()); } m_bTransformDirty = false; } return m_sTransform; } else { return CCSprite::nodeToParentTransform(); } }
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; }
CCAffineTransform HTransformNode::nodeToParentTransform(void) { return CCAffineTransformConcat(CCNode::nodeToParentTransform(), m_tTransform); }
void Skin::updateTransform() { m_sTransform = CCAffineTransformConcat(m_tSkinTransform, m_pBone->nodeToArmatureTransform()); }
void GAFSprite::updateTransform(void) { CCAssert( m_pobBatchNode, "updateTransform is only valid when CCSprite is being rendered using an CCSpriteBatchNode"); // recalculate matrix only if it is dirty if( isDirty() ) { // If it is not visible, or one of its ancestors is not visible, then do nothing: if( !m_bVisible || ( m_pParent && m_pParent != (CCSprite*)m_pobBatchNode && ((CCSprite*)m_pParent)->m_bShouldBeHidden) ) { m_sQuad.br.vertices = m_sQuad.tl.vertices = m_sQuad.tr.vertices = m_sQuad.bl.vertices = vertex3(0,0,0); m_bShouldBeHidden = true; } else { m_bShouldBeHidden = false; if( ! m_pParent || m_pParent == (CCSprite*)m_pobBatchNode ) { m_transformToBatch = nodeToParentTransform(); } else { CCAssert( dynamic_cast<CCSprite*>(m_pParent), "Logic error in CCSprite. Parent must be a CCSprite"); m_transformToBatch = CCAffineTransformConcat( nodeToParentTransform() , ((CCSprite*)m_pParent)->m_transformToBatch ); } // // calculate the Quad based on the Affine Matrix // CCSize size = m_obRect.size; // x1, x2, y1, y2 are changed (comapring to CCSprite) to place Sprite at center float x1 = m_obOffsetPosition.x - size.width / 2; float y1 = m_obOffsetPosition.y - size.height / 2; float x2 = x1 + size.width; float y2 = y1 + size.height; float x = m_transformToBatch.tx; float y = m_transformToBatch.ty; float cr = m_transformToBatch.a; float sr = m_transformToBatch.b; float cr2 = m_transformToBatch.d; float sr2 = -m_transformToBatch.c; float ax = x1 * cr - y1 * sr2 + x; float ay = x1 * sr + y1 * cr2 + y; float bx = x2 * cr - y1 * sr2 + x; float by = x2 * sr + y1 * cr2 + y; float cx = x2 * cr - y2 * sr2 + x; float cy = x2 * sr + y2 * cr2 + y; float dx = x1 * cr - y2 * sr2 + x; float dy = x1 * sr + y2 * cr2 + y; m_sQuad.bl.vertices = vertex3( RENDER_IN_SUBPIXEL(ax), RENDER_IN_SUBPIXEL(ay), m_fVertexZ ); m_sQuad.br.vertices = vertex3( RENDER_IN_SUBPIXEL(bx), RENDER_IN_SUBPIXEL(by), m_fVertexZ ); m_sQuad.tl.vertices = vertex3( RENDER_IN_SUBPIXEL(dx), RENDER_IN_SUBPIXEL(dy), m_fVertexZ ); m_sQuad.tr.vertices = vertex3( RENDER_IN_SUBPIXEL(cx), RENDER_IN_SUBPIXEL(cy), m_fVertexZ ); } // MARMALADE CHANGE: ADDED CHECK FOR NULL, TO PERMIT SPRITES WITH NO BATCH NODE / TEXTURE ATLAS if (m_pobTextureAtlas) { m_pobTextureAtlas->updateQuad(&m_sQuad, m_uAtlasIndex); } m_bRecursiveDirty = false; setDirty(false); } // MARMALADE CHANGED // recursively iterate over children /* if( m_bHasChildren ) { // MARMALADE: CHANGED TO USE CCNode* // NOTE THAT WE HAVE ALSO DEFINED virtual CCNode::updateTransform() arrayMakeObjectsPerformSelector(m_pChildren, updateTransform, CCSprite*); }*/ CCNode::updateTransform(); #if CC_SPRITE_DEBUG_DRAW // draw bounding box CCPoint vertices[4] = { ccp( m_sQuad.bl.vertices.x, m_sQuad.bl.vertices.y ), ccp( m_sQuad.br.vertices.x, m_sQuad.br.vertices.y ), ccp( m_sQuad.tr.vertices.x, m_sQuad.tr.vertices.y ), ccp( m_sQuad.tl.vertices.x, m_sQuad.tl.vertices.y ), }; ccDrawPoly(vertices, 4, true); #endif // CC_SPRITE_DEBUG_DRAW }
CCAffineTransform CCSkin::nodeToWorldTransform() { return CCAffineTransformConcat(m_sTransform, m_pBone->getArmature()->nodeToWorldTransform()); }