コード例 #1
0
Action::ResultE
SkeletonOgreJoint::jointUpdateEnter(JointTraverser *jt)
{
    Action::ResultE  res  = Action::Continue;
    Skeleton        *skel = getSkeleton();

#ifdef OSG_DEBUG
    if(_sfJointId.getValue() == INVALID_JOINT_ID)
    {
        SWARNING << "SkeletonOgreJoint::jointUpdateEnter: "
                 << "Joint has invalid jointId. Ignoring." << std::endl;
        return res;
    }
    
    if(skel == NULL)
    {
        SWARNING << "SkeletonOgreJoint::jointUpdateEnter: "
                 << "Joint has no skeleton. Ignoring." << std::endl;
        return res;
    }
#endif

    Int16                          jointId     = getJointId();
    Skeleton::MFJointMatricesType *jointMats   =
        skel->editMFJointMatrices();
    SkeletonOgreJoint             *parentJoint =
        dynamic_cast<SkeletonOgreJoint *>(skel->getParentJoints(jointId));

    if(parentJoint != NULL)
    {
        _accumRotate = parentJoint->_accumRotate;
        _accumRotate.mult(getRotate      ());
        _accumRotate.mult(getOffsetRotate());

        _accumScale = parentJoint->_accumScale;
        _accumScale[0] *= getScale()[0] * getOffsetScale()[0];
        _accumScale[1] *= getScale()[1] * getOffsetScale()[1];
        _accumScale[2] *= getScale()[2] * getOffsetScale()[2];

        _accumTranslate = getTranslate() + getOffsetTranslate();
        _accumTranslate[0] *= parentJoint->_accumScale[0];
        _accumTranslate[1] *= parentJoint->_accumScale[1];
        _accumTranslate[2] *= parentJoint->_accumScale[2];

        parentJoint->_accumRotate.multVec(_accumTranslate, _accumTranslate);
        _accumTranslate += parentJoint->_accumTranslate;   
    }
    else
    {
        _accumRotate    = getRotate();
        _accumRotate.mult(getOffsetRotate());

        _accumScale     = getScale();
        _accumScale[0] *= getOffsetScale()[0];
        _accumScale[1] *= getOffsetScale()[1];
        _accumScale[2] *= getOffsetScale()[2];

        _accumTranslate = getTranslate() + getOffsetTranslate();
    }

    Quaternion jointRotate   (_accumRotate   );
    Vec3f      jointTranslate(_accumTranslate);
    Vec3f      jointScale    (_accumScale    );

    if(skel->getUseInvBindMatrix() == true)
    {
        jointRotate.mult(getInvBindRotate());
        jointScale[0]  *= getInvBindScale()[0];
        jointScale[1]  *= getInvBindScale()[1];
        jointScale[2]  *= getInvBindScale()[2];

        jointTranslate[0] = jointScale[0] * getInvBindTranslate()[0];
        jointTranslate[1] = jointScale[1] * getInvBindTranslate()[1];
        jointTranslate[2] = jointScale[2] * getInvBindTranslate()[2];

        jointRotate.multVec(jointTranslate, jointTranslate);

        jointTranslate += _accumTranslate;
    }

    Matrix matJoint;
    matJoint.setTransform(jointTranslate, jointRotate, jointScale);

    (*jointMats)[jointId] = matJoint;

    return res;
}