Пример #1
0
void DisplayFactory::updateDisplay(Bone *bone, DecorativeDisplay *decoDisplay, float dt, bool dirty)
{
    CS_RETURN_IF(!decoDisplay);

#if ENABLE_PHYSICS_DETECT
    if (dirty)
    {
        ColliderDetector *detector = decoDisplay->getColliderDetector();
        if (detector)
        {
            AffineTransform t = AffineTransformConcat(bone->nodeToArmatureTransform(), bone->getArmature()->getNodeToWorldTransform());
            detector->updateTransform(t);
        }
    }
#endif


    switch(decoDisplay->getDisplayData()->displayType)
    {
    case CS_DISPLAY_SPRITE:
        updateSpriteDisplay(bone, decoDisplay, dt, dirty);
        break;
    case CS_DISPLAY_PARTICLE:
        updateParticleDisplay(bone, decoDisplay, dt, dirty);
        break;
    case CS_DISPLAY_ARMATURE:
        updateArmatureDisplay(bone, decoDisplay, dt, dirty);
        break;
    default:
        break;
    }
}
Пример #2
0
AffineTransform Node::getNodeToWorldAffineTransform() const
{
    AffineTransform t = this->getNodeToParentAffineTransform();

    for (Node *p = _parent; p != nullptr; p = p->getParent())
        t = AffineTransformConcat(t, p->getNodeToParentAffineTransform());

    return t;
}
Пример #3
0
AffineTransform Node::getNodeToParentAffineTransform(Node* ancestor) const
{
    AffineTransform t(this->getNodeToParentAffineTransform());

    for (Node *p = _parent; p != nullptr && p != ancestor; p = p->getParent())
        t = AffineTransformConcat(t, p->getNodeToParentAffineTransform());

    return t;
}
void TransformHelp::transformToParent(BaseData &node, const BaseData &parentNode)
{

    nodeToMatrix(node, m_tHelpMatrix1);
    nodeToMatrix(parentNode, m_tHelpMatrix2);

    m_tHelpMatrix1 = AffineTransformConcat(m_tHelpMatrix1, m_tHelpMatrix2);

    matrixToNode(m_tHelpMatrix1, node);
}
Пример #5
0
void TransformHelp::transformFromParent(BaseData &node, const BaseData &parentNode)
{
    nodeToMatrix(node, helpMatrix1);
    nodeToMatrix(parentNode, helpMatrix2);

    helpMatrix2 = AffineTransformInvert(helpMatrix2);
    helpMatrix1 = AffineTransformConcat(helpMatrix1, helpMatrix2);

    matrixToNode(helpMatrix1, node);
}
Пример #6
0
AffineTransform Skin::getNodeToWorldTransformAR() const
{
    AffineTransform displayTransform = _transform;
    Point anchorPoint =  _anchorPointInPoints;

    anchorPoint = PointApplyAffineTransform(anchorPoint, displayTransform);

    displayTransform.tx = anchorPoint.x;
    displayTransform.ty = anchorPoint.y;

    return AffineTransformConcat(displayTransform, _bone->getArmature()->getNodeToWorldTransform());
}
void TransformHelp::transformToParentWithoutScale(BaseData &node, const BaseData &parentNode)
{

    helpParentNode.copy(&parentNode);
    helpParentNode.m_fScaleX = 1;
    helpParentNode.m_fScaleY = 1;

    nodeToMatrix(node, m_tHelpMatrix1);
    nodeToMatrix(helpParentNode, m_tHelpMatrix2);

    m_tHelpMatrix1 = AffineTransformConcat(m_tHelpMatrix1, m_tHelpMatrix2);

    matrixToNode(m_tHelpMatrix1, node);
}
Пример #8
0
void TransformHelp::transformFromParentWithoutScale(BaseData &node, const BaseData &parentNode)
{

    helpParentNode.copy(&parentNode);
    helpParentNode.scaleX = 1;
    helpParentNode.scaleY = 1;

    nodeToMatrix(node, helpMatrix1);
    nodeToMatrix(helpParentNode, helpMatrix2);

    helpMatrix2 = AffineTransformInvert(helpMatrix2);
    helpMatrix1 = AffineTransformConcat(helpMatrix1, helpMatrix2);

    matrixToNode(helpMatrix1, node);
}
Пример #9
0
void Skin::updateTransform()
{
    _transform = AffineTransformConcat(_skinTransform, _bone->nodeToArmatureTransform());
}
Пример #10
0
void GAFObject::realizeFrame(cocos2d::Node* out, uint32_t frameIndex)
{
    const AnimationFrames_t& animationFrames = m_timeline->getAnimationFrames();

    if (animationFrames.size() <= frameIndex)
    {
        return;
    }

    GAFAnimationFrame *currentFrame = animationFrames[frameIndex];

    const GAFAnimationFrame::SubobjectStates_t& states = currentFrame->getObjectStates();

    for (const GAFSubobjectState* state : states)
    {
        GAFObject* subObject = m_displayList[state->objectIdRef];

        CCASSERT(subObject, "Error. SubObject with current ID not found");
        if (!subObject)
            continue;

        if (state->colorMults()[GAFColorTransformIndex::GAFCTI_A] >= 0.f && subObject->m_isInResetState)
        {
            subObject->m_currentFrame = subObject->m_currentSequenceStart;
        }
        subObject->m_isInResetState = state->colorMults()[GAFColorTransformIndex::GAFCTI_A] < 0.f;

        if (!state->isVisible())
            continue;

        if (subObject->m_charType == GAFCharacterType::Timeline)
        {
            if (!subObject->m_isInResetState)
            {
                cocos2d::AffineTransform stateTransform = state->affineTransform;
                float csf = m_timeline->usedAtlasScale();
                stateTransform.tx *= csf;
                stateTransform.ty *= csf;
                cocos2d::AffineTransform t = GAF_CGAffineTransformCocosFormatFromFlashFormat(state->affineTransform);
                subObject->setAdditionalTransform(t);
                subObject->m_parentFilters.clear();
                const Filters_t& filters = state->getFilters();
                subObject->m_parentFilters.insert(subObject->m_parentFilters.end(), filters.begin(), filters.end());

                const float* cm = state->colorMults();
                subObject->m_parentColorTransforms[0] = cocos2d::Vec4(
                    m_parentColorTransforms[0].x * cm[0],
                    m_parentColorTransforms[0].y * cm[1],
                    m_parentColorTransforms[0].z * cm[2],
                    m_parentColorTransforms[0].w * cm[3]);
                subObject->m_parentColorTransforms[1] = cocos2d::Vec4(state->colorOffsets()) + m_parentColorTransforms[1];

                if (m_masks[state->objectIdRef])
                {
                    rearrangeSubobject(out, m_masks[state->objectIdRef], state->zIndex);
                }
                else
                {
                    //subObject->removeFromParentAndCleanup(false);
                    if (state->maskObjectIdRef == IDNONE)
                    {
                        rearrangeSubobject(out, subObject, state->zIndex);
                    }
                    else
                    {
                        // If the state has a mask, then attach it 
                        // to the clipping node. Clipping node will be attached on its state
                        auto mask = m_masks[state->maskObjectIdRef];
                        CCASSERT(mask, "Error. No mask found for this ID");
                        if (mask)
                            rearrangeSubobject(mask, subObject, state->zIndex);
                    }
                }

                subObject->step();
            }
        }
        else if (subObject->m_charType == GAFCharacterType::Texture)
        {
            cocos2d::Vect prevAP = subObject->getAnchorPoint();
            cocos2d::Size  prevCS = subObject->getContentSize();

#if ENABLE_RUNTIME_FILTERS
            if (subObject->m_objectType == GAFObjectType::MovieClip)
            {
                // Validate sprite type (w/ or w/o filter)
                const Filters_t& filters = state->getFilters();
                GAFFilterData* filter = NULL;

                GAFMovieClip* mc = static_cast<GAFMovieClip*>(subObject);

                if (m_parentFilters.size() > 0)
                {
                    filter = *m_parentFilters.begin();
                }
                else if (filters.size() > 0)
                {
                    filter = *filters.begin();
                }

                if (filter)
                {
                    filter->apply(mc);
                }

                if (!filter || filter->getType() != GAFFilterType::GFT_Blur)
                {
                    mc->setBlurFilterData(nullptr);
                }

                if (!filter || filter->getType() != GAFFilterType::GFT_ColorMatrix)
                {
                    mc->setColorMarixFilterData(nullptr);
                }

                if (!filter || filter->getType() != GAFFilterType::GFT_Glow)
                {
                    mc->setGlowFilterData(nullptr);
                }

                if (!filter || filter->getType() != GAFFilterType::GFT_DropShadow)
                {
                    GAFDropShadowFilterData::reset(mc);
                }
            }
#endif

            cocos2d::Size newCS = subObject->getContentSize();
            cocos2d::Vect newAP = cocos2d::Vect(((prevAP.x - 0.5f) * prevCS.width) / newCS.width + 0.5f,
                ((prevAP.y - 0.5f) * prevCS.height) / newCS.height + 0.5f);
            subObject->setAnchorPoint(newAP);


            if (m_masks[state->objectIdRef])
            {
                rearrangeSubobject(out, m_masks[state->objectIdRef], state->zIndex);
            }
            else
            {
                //subObject->removeFromParentAndCleanup(false);
                if (state->maskObjectIdRef == IDNONE)
                {
                    rearrangeSubobject(out, subObject, state->zIndex);
                }
                else
                {
                    // If the state has a mask, then attach it 
                    // to the clipping node. Clipping node will be attached on its state
                    auto mask = m_masks[state->maskObjectIdRef];
                    CCASSERT(mask, "Error. No mask found for this ID");
                    if (mask)
                        rearrangeSubobject(mask, subObject, state->zIndex);
                }
            }

            cocos2d::AffineTransform stateTransform = state->affineTransform;
            float csf = m_timeline->usedAtlasScale();
            stateTransform.tx *= csf;
            stateTransform.ty *= csf;
            cocos2d::AffineTransform t = GAF_CGAffineTransformCocosFormatFromFlashFormat(state->affineTransform);
            
            if (isFlippedX() || isFlippedY())
            {
                float flipMulX = isFlippedX() ? -1 : 1;
                float flipOffsetX = isFlippedX() ? getContentSize().width - m_asset->getHeader().frameSize.getMinX() : 0;
                float flipMulY = isFlippedY() ? -1 : 1;
                float flipOffsetY = isFlippedY() ? -getContentSize().height + m_asset->getHeader().frameSize.getMinY() : 0;

                cocos2d::AffineTransform flipCenterTransform = cocos2d::AffineTransformMake(flipMulX, 0, 0, flipMulY, flipOffsetX, flipOffsetY);
                t = AffineTransformConcat(t, flipCenterTransform);
            }

            subObject->setExternalTransform(t);

            if (subObject->m_objectType == GAFObjectType::MovieClip)
            {
                GAFMovieClip* mc = static_cast<GAFMovieClip*>(subObject);
                float colorMults[4] = {
                    state->colorMults()[0] * m_parentColorTransforms[0].x,
                    state->colorMults()[1] * m_parentColorTransforms[0].y,
                    state->colorMults()[2] * m_parentColorTransforms[0].z,
                    state->colorMults()[3] * m_parentColorTransforms[0].w
                };
                float colorOffsets[4] = {
                    state->colorOffsets()[0] + m_parentColorTransforms[1].x,
                    state->colorOffsets()[1] + m_parentColorTransforms[1].y,
                    state->colorOffsets()[2] + m_parentColorTransforms[1].z,
                    state->colorOffsets()[3] + m_parentColorTransforms[1].w
                };

                mc->setColorTransform(colorMults, colorOffsets);
            }
        }
        else if (subObject->m_charType == GAFCharacterType::TextField)
        {
            GAFTextField *tf = static_cast<GAFTextField*>(subObject);
            rearrangeSubobject(out, subObject, state->zIndex);

            cocos2d::AffineTransform stateTransform = state->affineTransform;
            float csf = m_timeline->usedAtlasScale();
            stateTransform.tx *= csf;
            stateTransform.ty *= csf;
            cocos2d::AffineTransform t = GAF_CGAffineTransformCocosFormatFromFlashFormat(state->affineTransform);

            if (isFlippedX() || isFlippedY())
            {
                float flipMulX = isFlippedX() ? -1 : 1;
                float flipOffsetX = isFlippedX() ? getContentSize().width - m_asset->getHeader().frameSize.getMinX() : 0;
                float flipMulY = isFlippedY() ? -1 : 1;
                float flipOffsetY = isFlippedY() ? -getContentSize().height + m_asset->getHeader().frameSize.getMinY() : 0;

                cocos2d::AffineTransform flipCenterTransform = cocos2d::AffineTransformMake(flipMulX, 0, 0, flipMulY, flipOffsetX, flipOffsetY);
                t = AffineTransformConcat(t, flipCenterTransform);
            }

            subObject->setExternalTransform(t);
        }

        if (state->isVisible())
        {
            subObject->m_lastVisibleInFrame = frameIndex + 1;
        }
    }

    GAFAnimationFrame::TimelineActions_t timelineActions = currentFrame->getTimelineActions();
    for (GAFTimelineAction action : timelineActions)
    {
        switch (action.getType())
        {
        case GAFActionType::Stop:
            pauseAnimation();
            break;
        case GAFActionType::Play:
            resumeAnimation();
            break;
        case GAFActionType::GotoAndStop:
            gotoAndStop(action.getParam(GAFTimelineAction::PI_FRAME));
            break;
        case GAFActionType::GotoAndPlay:
            gotoAndPlay(action.getParam(GAFTimelineAction::PI_FRAME));
            break;
        case GAFActionType::DispatchEvent:
            _eventDispatcher->dispatchCustomEvent(action.getParam(GAFTimelineAction::PI_EVENT_TYPE), &action);
            break;

        case GAFActionType::None:
        default:
            break;
        }
    }
}
Пример #11
0
AffineTransform Skin::getNodeToWorldTransform() const
{
    return AffineTransformConcat(_transform, _bone->getArmature()->getNodeToWorldTransform());
}