Ejemplo n.º 1
0
void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
    bool gotLock = false;
    glm::quat rotation;
    glm::vec3 position;
    std::shared_ptr<Avatar> holdingAvatar = nullptr;

    gotLock = withTryReadLock([&] {
        QSharedPointer<AvatarManager> avatarManager = DependencyManager::get<AvatarManager>();
        AvatarSharedPointer holdingAvatarData = avatarManager->getAvatarBySessionID(_holderID);
        holdingAvatar = std::static_pointer_cast<Avatar>(holdingAvatarData);

        if (holdingAvatar) {
            glm::vec3 offset;
            glm::vec3 palmPosition;
            glm::quat palmRotation;
            if (_hand == "right") {
                palmPosition = holdingAvatar->getRightPalmPosition();
                palmRotation = holdingAvatar->getRightPalmRotation();
            } else {
                palmPosition = holdingAvatar->getLeftPalmPosition();
                palmRotation = holdingAvatar->getLeftPalmRotation();
            }

            rotation = palmRotation * _relativeRotation;
            offset = rotation * _relativePosition;
            position = palmPosition + offset;
        }
    });

    if (holdingAvatar) {
        if (gotLock) {
            gotLock = withTryWriteLock([&] {
                _positionalTarget = position;
                _rotationalTarget = rotation;
                _positionalTargetSet = true;
                _rotationalTargetSet = true;
                _active = true;
            });
            if (gotLock) {
                if (_kinematic) {
                    doKinematicUpdate(deltaTimeStep);
                } else {
                    activateBody();
                    ObjectActionSpring::updateActionWorker(deltaTimeStep);
                }
            }
        }
    }
}
Ejemplo n.º 2
0
void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
    if (!_mine) {
        // if a local script isn't updating this, then we are just getting spring-action data over the wire.
        // let the super-class handle it.
        ObjectActionSpring::updateActionWorker(deltaTimeStep);
        return;
    }

    glm::quat rotation;
    glm::vec3 position;
    glm::vec3 offset;
    bool gotLock = withTryReadLock([&]{
        auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
        glm::vec3 palmPosition;
        glm::quat palmRotation;
        if (_hand == "right") {
            palmPosition = myAvatar->getRightPalmPosition();
            palmRotation = myAvatar->getRightPalmRotation();
        } else {
            palmPosition = myAvatar->getLeftPalmPosition();
            palmRotation = myAvatar->getLeftPalmRotation();
        }

        rotation = palmRotation * _relativeRotation;
        offset = rotation * _relativePosition;
        position = palmPosition + offset;
    });

    if (gotLock) {
        gotLock = withTryWriteLock([&]{
            if (_positionalTarget != position || _rotationalTarget != rotation) {
                auto ownerEntity = _ownerEntity.lock();
                if (ownerEntity) {
                    ownerEntity->setActionDataDirty(true);
                }
                _positionalTarget = position;
                _rotationalTarget = rotation;
            }
        });
    }

    if (gotLock) {
        ObjectActionSpring::updateActionWorker(deltaTimeStep);
    }
}
Ejemplo n.º 3
0
void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
    bool gotLock = false;
    glm::quat rotation;
    glm::vec3 position;
    glm::vec3 offset;

    gotLock = withTryReadLock([&]{
        auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
        glm::vec3 palmPosition;
        glm::quat palmRotation;
        if (_hand == "right") {
            palmPosition = myAvatar->getRightPalmPosition();
            palmRotation = myAvatar->getRightPalmRotation();
        } else {
            palmPosition = myAvatar->getLeftPalmPosition();
            palmRotation = myAvatar->getLeftPalmRotation();
        }

        rotation = palmRotation * _relativeRotation;
        offset = rotation * _relativePosition;
        position = palmPosition + offset;
    });

    if (gotLock) {
        gotLock = withTryWriteLock([&]{
            _positionalTarget = position;
            _rotationalTarget = rotation;
            _positionalTargetSet = true;
            _rotationalTargetSet = true;
            auto ownerEntity = _ownerEntity.lock();
            if (ownerEntity) {
                ownerEntity->setActionDataDirty(true);
            }
        });
    }
    if (gotLock) {
        ObjectActionSpring::updateActionWorker(deltaTimeStep);
    }
}