Exemplo n.º 1
0
void OverlayPanel::applyTransformTo(Transform& transform, bool force) {
    if (force || usecTimestampNow() > _transformExpiry) {
        PanelAttachable::applyTransformTo(transform, true);
        if (!getParentPanel()) {
            if (_anchorPositionBindMyAvatar) {
                transform.setTranslation(DependencyManager::get<AvatarManager>()->getMyAvatar()
                                         ->getPosition());
            } else if (!_anchorPositionBindEntity.isNull()) {
                EntityTreePointer entityTree = DependencyManager::get<EntityScriptingInterface>()->getEntityTree();
                entityTree->withReadLock([&] {
                    EntityItemPointer foundEntity = entityTree->findEntityByID(_anchorPositionBindEntity);
                    if (foundEntity) {
                        transform.setTranslation(foundEntity->getPosition());
                    }
                });
            } else {
                transform.setTranslation(getAnchorPosition());
            }

            if (_anchorRotationBindMyAvatar) {
                transform.setRotation(DependencyManager::get<AvatarManager>()->getMyAvatar()
                                      ->getOrientation());
            } else if (!_anchorRotationBindEntity.isNull()) {
                EntityTreePointer entityTree = DependencyManager::get<EntityScriptingInterface>()->getEntityTree();
                entityTree->withReadLock([&] {
                    EntityItemPointer foundEntity = entityTree->findEntityByID(_anchorRotationBindEntity);
                    if (foundEntity) {
                        transform.setRotation(foundEntity->getRotation());
                    }
                });
            } else {
                transform.setRotation(getAnchorRotation());
            }

            transform.setScale(getAnchorScale());

            transform.postTranslate(getOffsetPosition());
            transform.postRotate(getOffsetRotation());
            transform.postScale(getOffsetScale());
        }
        pointTransformAtCamera(transform, getOffsetRotation());
    }
}
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;
}