Пример #1
0
void Bone::update(float delta)
{
    if (_parentBone)
        _boneTransformDirty = _boneTransformDirty || _parentBone->isTransformDirty();

    if (_armatureParentBone && !_boneTransformDirty)
    {
        _boneTransformDirty = _armatureParentBone->isTransformDirty();
    }

    if (_boneTransformDirty)
    {
        _worldInfo->copy(_tweenData);
        if (_dataVersion >= VERSION_COMBINED)
        {
            TransformHelp::nodeConcat(*_worldInfo, *_boneData);
            _worldInfo->scaleX -= 1;
            _worldInfo->scaleY -= 1;
        }

        _worldInfo->x = _worldInfo->x + _position.x;
        _worldInfo->y = _worldInfo->y + _position.y;
        _worldInfo->scaleX = _worldInfo->scaleX * _scaleX;
        _worldInfo->scaleY = _worldInfo->scaleY * _scaleY;
        _worldInfo->skewX = _worldInfo->skewX + _skewX + CC_DEGREES_TO_RADIANS(_rotationZ_X);
        _worldInfo->skewY = _worldInfo->skewY + _skewY - CC_DEGREES_TO_RADIANS(_rotationZ_Y);

        if(_parentBone)
        {
            applyParentTransform(_parentBone);
        }
        else
        {
            if (_armatureParentBone)
            {
                applyParentTransform(_armatureParentBone);
            }
        }

        TransformHelp::nodeToMatrix(*_worldInfo, _worldTransform);

        if (_armatureParentBone)
        {
            _worldTransform = TransformConcat(_worldTransform, _armature->getNodeToParentTransform());
        }
    }

    DisplayFactory::updateDisplay(this, delta, _boneTransformDirty || _armature->getArmatureTransformDirty());

    for(const auto &obj: _children) {
        Bone *childBone = static_cast<Bone*>(obj);
        childBone->update(delta);
    }

    _boneTransformDirty = false;
}
void DisplayFactory::updateDisplay(Bone *bone, float dt, bool dirty)
{
    Node *display = bone->getDisplayRenderNode();
    CS_RETURN_IF(!display);

    switch(bone->getDisplayRenderNodeType())
    {
    case CS_DISPLAY_SPRITE:
        if (dirty)
        {
            static_cast<Skin*>(display)->updateArmatureTransform();
        }
        break;
    case CS_DISPLAY_PARTICLE:
        updateParticleDisplay(bone, display, dt);
        break;
    case CS_DISPLAY_ARMATURE:
        updateArmatureDisplay(bone, display, dt);
        break;
    default:
    {
        Mat4 transform = bone->getNodeToArmatureTransform();
        display->setAdditionalTransform(&transform);
    }
    break;
    }


#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT || ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
    if (dirty)
    {
        DecorativeDisplay *decoDisplay = bone->getDisplayManager()->getCurrentDecorativeDisplay();
        ColliderDetector *detector = decoDisplay->getColliderDetector();
        if (detector)
        {
            do
            {
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
                CC_BREAK_IF(!detector->getBody());
#endif

                Mat4 displayTransform = display->getNodeToParentTransform();
                Vec2 anchorPoint =  display->getAnchorPointInPoints();
                anchorPoint = PointApplyTransform(anchorPoint, displayTransform);
                displayTransform.m[12] = anchorPoint.x;
                displayTransform.m[13] = anchorPoint.y;
                Mat4 t = TransformConcat( bone->getArmature()->getNodeToParentTransform(),displayTransform);
                detector->updateTransform(t);
            }
            while (0);
        }
    }
#endif
}
Пример #3
0
Mat4 Skin::getNodeToWorldTransformAR() const
{
    Mat4 displayTransform = _transform;
    Vec2 anchorPoint =  _anchorPointInPoints;

    anchorPoint = PointApplyTransform(anchorPoint, displayTransform);

    displayTransform.m[12] = anchorPoint.x;
    displayTransform.m[13] = anchorPoint.y;

    return TransformConcat( _bone->getArmature()->getNodeToWorldTransform(),displayTransform);
}
Пример #4
0
Mat4 Skin::getNodeToWorldTransform() const
{
    return TransformConcat( _bone->getArmature()->getNodeToWorldTransform(), _transform);
}
Пример #5
0
kmMat4 Bone::getNodeToWorldTransform() const
{
    return TransformConcat(_worldTransform, _armature->getNodeToWorldTransform());
}
Пример #6
0
 Mat4 Bone::_getNodeToParentTransform()
 {
     return TransformConcat(_armature->getNodeToParentTransform(),_worldTransform);
 }