Exemplo n.º 1
0
    void Manager::saveAll() {
        bool forceSync = false;
        withWriteLock([&] {
            for (auto key : _pendingChanges.keys()) {
                auto newValue = _pendingChanges[key];
                auto savedValue = value(key, UNSET_VALUE);
                if (newValue == savedValue) {
                    continue;
                }
                if (newValue == UNSET_VALUE || !newValue.isValid()) {
                    forceSync = true;
                    remove(key);
                } else {
                    forceSync = true;
                    setValue(key, newValue);
                }
            }
            _pendingChanges.clear();
        });

        if (forceSync) {
            sync();
        }

        // Restart timer
        if (_saveTimer) {
            _saveTimer->start();
        }
    }
Exemplo n.º 2
0
void PolyVoxEntityItem::setVoxelVolumeSize(const vec3& voxelVolumeSize) {
    withWriteLock([&] {
        assert(!glm::any(glm::isnan(voxelVolumeSize)));

        _voxelVolumeSize = glm::vec3(roundf(voxelVolumeSize.x), roundf(voxelVolumeSize.y), roundf(voxelVolumeSize.z));
        if (_voxelVolumeSize.x < 1) {
            qCDebug(entities) << "PolyVoxEntityItem::setVoxelVolumeSize clamping x of" << _voxelVolumeSize.x << "to 1";
            _voxelVolumeSize.x = 1;
        }
        if (_voxelVolumeSize.x > MAX_VOXEL_DIMENSION) {
            qCDebug(entities) << "PolyVoxEntityItem::setVoxelVolumeSize clamping x of" << _voxelVolumeSize.x << "to max";
            _voxelVolumeSize.x = MAX_VOXEL_DIMENSION;
        }

        if (_voxelVolumeSize.y < 1) {
            qCDebug(entities) << "PolyVoxEntityItem::setVoxelVolumeSize clamping y of" << _voxelVolumeSize.y << "to 1";
            _voxelVolumeSize.y = 1;
        }
        if (_voxelVolumeSize.y > MAX_VOXEL_DIMENSION) {
            qCDebug(entities) << "PolyVoxEntityItem::setVoxelVolumeSize clamping y of" << _voxelVolumeSize.y << "to max";
            _voxelVolumeSize.y = MAX_VOXEL_DIMENSION;
        }

        if (_voxelVolumeSize.z < 1) {
            qCDebug(entities) << "PolyVoxEntityItem::setVoxelVolumeSize clamping z of" << _voxelVolumeSize.z << "to 1";
            _voxelVolumeSize.z = 1;
        }
        if (_voxelVolumeSize.z > MAX_VOXEL_DIMENSION) {
            qCDebug(entities) << "PolyVoxEntityItem::setVoxelVolumeSize clamping z of" << _voxelVolumeSize.z << "to max";
            _voxelVolumeSize.z = MAX_VOXEL_DIMENSION;
        }
    });
}
Exemplo n.º 3
0
bool PolyLineEntityItem::setStrokeColors(const QVector<glm::vec3>& strokeColors) {
    withWriteLock([&] {
        _strokeColors = strokeColors;
        _strokeColorsChanged = true;
    });
    return true;
}
Exemplo n.º 4
0
bool PolyLineEntityItem::setNormals(const QVector<glm::vec3>& normals) {
    withWriteLock([&] {
        _normals = normals;
        _normalsChanged = true;
    });
    return true;
}
Exemplo n.º 5
0
bool PolyLineEntityItem::setLinePoints(const QVector<glm::vec3>& points) {
    if (points.size() > MAX_POINTS_PER_LINE) {
        return false;
    }
    bool result = false;
    withWriteLock([&] {
        //Check to see if points actually changed. If they haven't, return before doing anything else
        if (points.size() != _points.size()) {
            _pointsChanged = true;
        } else if (points.size() == _points.size()) {
            //same number of points, so now compare every point
            for (int i = 0; i < points.size(); i++) {
                if (points.at(i) != _points.at(i)) {
                    _pointsChanged = true;
                    break;
                }
            }
        }
        if (!_pointsChanged) {
            return;
        }

        _points = points;

        result = true;
    });

    if (result) {
        calculateScaleAndRegistrationPoint();
    }

    return result;
}
Exemplo n.º 6
0
bool PolyLineEntityItem::setStrokeWidths(const QVector<float>& strokeWidths) {
    withWriteLock([&] {
        _strokeWidths = strokeWidths;
        _strokeWidthsChanged = true;
    });
    return true;
}
Exemplo n.º 7
0
int WebEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
                                                ReadBitstreamToTreeParams& args,
                                                EntityPropertyFlags& propertyFlags, bool overwriteLocalData,
                                                bool& somethingChanged) {

    int bytesRead = 0;
    const unsigned char* dataAt = data;

    READ_ENTITY_PROPERTY(PROP_COLOR, glm::u8vec3, setColor);
    READ_ENTITY_PROPERTY(PROP_ALPHA, float, setAlpha);
    withWriteLock([&] {
        int bytesFromPulse = _pulseProperties.readEntitySubclassDataFromBuffer(dataAt, (bytesLeftToRead - bytesRead), args,
            propertyFlags, overwriteLocalData,
            somethingChanged);
        bytesRead += bytesFromPulse;
        dataAt += bytesFromPulse;
    });
    READ_ENTITY_PROPERTY(PROP_BILLBOARD_MODE, BillboardMode, setBillboardMode);

    READ_ENTITY_PROPERTY(PROP_SOURCE_URL, QString, setSourceUrl);
    READ_ENTITY_PROPERTY(PROP_DPI, uint16_t, setDPI);
    READ_ENTITY_PROPERTY(PROP_SCRIPT_URL, QString, setScriptURL);
    READ_ENTITY_PROPERTY(PROP_MAX_FPS, uint8_t, setMaxFPS);
    READ_ENTITY_PROPERTY(PROP_INPUT_MODE, WebInputMode, setInputMode);
    READ_ENTITY_PROPERTY(PROP_SHOW_KEYBOARD_FOCUS_HIGHLIGHT, bool, setShowKeyboardFocusHighlight);

    return bytesRead;
}
Exemplo n.º 8
0
void Pointer::disable() {
    // Disable the pointer first, then the pick, so someone can't try to use it while it's in a bad state
    withWriteLock([&] {
        _enabled = false;
    });
    DependencyManager::get<PickManager>()->disablePick(_pickUID);
}
Exemplo n.º 9
0
void LineEntityItem::setColor(const xColor& value) {
    withWriteLock([&] {
        _color[RED_INDEX] = value.red;
        _color[GREEN_INDEX] = value.green;
        _color[BLUE_INDEX] = value.blue;
    });
}
Exemplo n.º 10
0
void PolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) {
    withWriteLock([&] {
        assert((int)_voxelVolumeSize.x == _voxelVolumeSize.x);
        assert((int)_voxelVolumeSize.y == _voxelVolumeSize.y);
        assert((int)_voxelVolumeSize.z == _voxelVolumeSize.z);

        _voxelVolumeSize = glm::vec3(roundf(voxelVolumeSize.x), roundf(voxelVolumeSize.y), roundf(voxelVolumeSize.z));
        if (_voxelVolumeSize.x < 1) {
            qDebug() << "PolyVoxEntityItem::setVoxelVolumeSize clamping x of" << _voxelVolumeSize.x << "to 1";
            _voxelVolumeSize.x = 1;
        }
        if (_voxelVolumeSize.x > MAX_VOXEL_DIMENSION) {
            qDebug() << "PolyVoxEntityItem::setVoxelVolumeSize clamping x of" << _voxelVolumeSize.x << "to max";
            _voxelVolumeSize.x = MAX_VOXEL_DIMENSION;
        }

        if (_voxelVolumeSize.y < 1) {
            qDebug() << "PolyVoxEntityItem::setVoxelVolumeSize clamping y of" << _voxelVolumeSize.y << "to 1";
            _voxelVolumeSize.y = 1;
        }
        if (_voxelVolumeSize.y > MAX_VOXEL_DIMENSION) {
            qDebug() << "PolyVoxEntityItem::setVoxelVolumeSize clamping y of" << _voxelVolumeSize.y << "to max";
            _voxelVolumeSize.y = MAX_VOXEL_DIMENSION;
        }

        if (_voxelVolumeSize.z < 1) {
            qDebug() << "PolyVoxEntityItem::setVoxelVolumeSize clamping z of" << _voxelVolumeSize.z << "to 1";
            _voxelVolumeSize.z = 1;
        }
        if (_voxelVolumeSize.z > MAX_VOXEL_DIMENSION) {
            qDebug() << "PolyVoxEntityItem::setVoxelVolumeSize clamping z of" << _voxelVolumeSize.z << "to max";
            _voxelVolumeSize.z = MAX_VOXEL_DIMENSION;
        }
    });
}
Exemplo n.º 11
0
void TextEntityItem::setBackgroundColor(const xColor& value) {
    withWriteLock([&] {
        _backgroundColor[RED_INDEX] = value.red;
        _backgroundColor[GREEN_INDEX] = value.green;
        _backgroundColor[BLUE_INDEX] = value.blue;
    });
}
Exemplo n.º 12
0
bool ZoneEntityItem::setSubClassProperties(const EntityItemProperties& properties) {
    bool somethingChanged = EntityItem::setSubClassProperties(properties); // set the properties in our base class

    SET_ENTITY_PROPERTY_FROM_PROPERTIES(shapeType, setShapeType);
    SET_ENTITY_PROPERTY_FROM_PROPERTIES(compoundShapeURL, setCompoundShapeURL);

    // Contains a QString property, must be synchronized
    withWriteLock([&] {
        _keyLightPropertiesChanged = _keyLightProperties.setProperties(properties);
        _ambientLightPropertiesChanged = _ambientLightProperties.setProperties(properties);
        _skyboxPropertiesChanged = _skyboxProperties.setProperties(properties);
    });
    _hazePropertiesChanged = _hazeProperties.setProperties(properties);
    _bloomPropertiesChanged = _bloomProperties.setProperties(properties);

    SET_ENTITY_PROPERTY_FROM_PROPERTIES(flyingAllowed, setFlyingAllowed);
    SET_ENTITY_PROPERTY_FROM_PROPERTIES(ghostingAllowed, setGhostingAllowed);
    SET_ENTITY_PROPERTY_FROM_PROPERTIES(filterURL, setFilterURL);

    SET_ENTITY_PROPERTY_FROM_PROPERTIES(keyLightMode, setKeyLightMode);
    SET_ENTITY_PROPERTY_FROM_PROPERTIES(ambientLightMode, setAmbientLightMode);
    SET_ENTITY_PROPERTY_FROM_PROPERTIES(skyboxMode, setSkyboxMode);
    SET_ENTITY_PROPERTY_FROM_PROPERTIES(hazeMode, setHazeMode);
    SET_ENTITY_PROPERTY_FROM_PROPERTIES(bloomMode, setBloomMode);
    SET_ENTITY_PROPERTY_FROM_PROPERTIES(avatarPriority, setAvatarPriority);

    somethingChanged = somethingChanged || _keyLightPropertiesChanged || _ambientLightPropertiesChanged ||
        _skyboxPropertiesChanged || _hazePropertiesChanged || _bloomPropertiesChanged;

    return somethingChanged;
}
Exemplo n.º 13
0
bool ObjectDynamic::updateArguments(QVariantMap arguments) {
    bool somethingChanged = false;

    withWriteLock([&]{
        quint64 previousExpires = _expires;
        QString previousTag = _tag;

        bool ttlSet = true;
        float ttl = EntityDynamicInterface::extractFloatArgument("dynamic", arguments, "ttl", ttlSet, false);
        if (ttlSet) {
            quint64 now = usecTimestampNow();
            _expires = now + (quint64)(ttl * USECS_PER_SECOND);
        } else {
            _expires = 0;
        }

        bool tagSet = true;
        QString tag = EntityDynamicInterface::extractStringArgument("dynamic", arguments, "tag", tagSet, false);
        if (tagSet) {
            _tag = tag;
        } else {
            tag = "";
        }

        if (previousExpires != _expires || previousTag != _tag) {
            somethingChanged = true;
        }
    });

    return somethingChanged;
}
Exemplo n.º 14
0
SpatiallyNestablePointer ObjectDynamic::getOther() {
    SpatiallyNestablePointer other;
    withWriteLock([&]{
        if (_otherID == QUuid()) {
            // no other
            return;
        }
        other = _other.lock();
        if (other && other->getID() == _otherID) {
            // other is already up-to-date
            return;
        }
        if (other) {
            // we have a pointer to other, but it's wrong
            other.reset();
            _other.reset();
        }
        // we have an other-id but no pointer to other cached
        QSharedPointer<SpatialParentFinder> parentFinder = DependencyManager::get<SpatialParentFinder>();
        if (!parentFinder) {
            return;
        }
        EntityItemPointer ownerEntity = _ownerEntity.lock();
        if (!ownerEntity) {
            return;
        }
        bool success;
        _other = parentFinder->find(_otherID, success, ownerEntity->getParentTree());
        if (success) {
            other = _other.lock();
        }
    });
    return other;
}
Exemplo n.º 15
0
bool WebEntityItem::setProperties(const EntityItemProperties& properties) {
    bool somethingChanged = false;
    somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class

    SET_ENTITY_PROPERTY_FROM_PROPERTIES(color, setColor);
    SET_ENTITY_PROPERTY_FROM_PROPERTIES(alpha, setAlpha);
    withWriteLock([&] {
        bool pulsePropertiesChanged = _pulseProperties.setProperties(properties);
        somethingChanged |= pulsePropertiesChanged;
    });
    SET_ENTITY_PROPERTY_FROM_PROPERTIES(billboardMode, setBillboardMode);

    SET_ENTITY_PROPERTY_FROM_PROPERTIES(sourceUrl, setSourceUrl);
    SET_ENTITY_PROPERTY_FROM_PROPERTIES(dpi, setDPI);
    SET_ENTITY_PROPERTY_FROM_PROPERTIES(scriptURL, setScriptURL);
    SET_ENTITY_PROPERTY_FROM_PROPERTIES(maxFPS, setMaxFPS);
    SET_ENTITY_PROPERTY_FROM_PROPERTIES(inputMode, setInputMode);
    SET_ENTITY_PROPERTY_FROM_PROPERTIES(showKeyboardFocusHighlight, setShowKeyboardFocusHighlight);

    if (somethingChanged) {
        bool wantDebug = false;
        if (wantDebug) {
            uint64_t now = usecTimestampNow();
            int elapsed = now - getLastEdited();
            qCDebug(entities) << "WebEntityItem::setProperties() AFTER update... edited AGO=" << elapsed <<
                    "now=" << now << " getLastEdited()=" << getLastEdited();
        }
        setLastEdited(properties._lastEdited);
    }

    return somethingChanged;
}
Exemplo n.º 16
0
void ZoneEntityItem::setCompoundShapeURL(const QString& url) {
    withWriteLock([&] {
        _compoundShapeURL = url;
        if (_compoundShapeURL.isEmpty() && _shapeType == SHAPE_TYPE_COMPOUND) {
            _shapeType = DEFAULT_SHAPE_TYPE;
        }
    });
}
Exemplo n.º 17
0
void PolyLineEntityItem::setTextures(const QString& textures) {
    withWriteLock([&] {
        if (_textures != textures) {
            _textures = textures;
            _texturesChangedFlag = true;
        }
    });
}
Exemplo n.º 18
0
bool ObjectActionOffset::updateArguments(QVariantMap arguments) {
    glm::vec3 pointToOffsetFrom;
    float linearTimeScale;
    float linearDistance;

    bool needUpdate = false;
    bool somethingChanged = ObjectAction::updateArguments(arguments);

    withReadLock([&] {
        bool ok = true;
        pointToOffsetFrom =
        EntityActionInterface::extractVec3Argument("offset action", arguments, "pointToOffsetFrom", ok, true);
        if (!ok) {
            pointToOffsetFrom = _pointToOffsetFrom;
        }

        ok = true;
        linearTimeScale =
        EntityActionInterface::extractFloatArgument("offset action", arguments, "linearTimeScale", ok, false);
        if (!ok) {
            linearTimeScale = _linearTimeScale;
        }

        ok = true;
        linearDistance =
        EntityActionInterface::extractFloatArgument("offset action", arguments, "linearDistance", ok, false);
        if (!ok) {
            linearDistance = _linearDistance;
        }

        // only change stuff if something actually changed
        if (somethingChanged ||
        _pointToOffsetFrom != pointToOffsetFrom ||
        _linearTimeScale != linearTimeScale ||
        _linearDistance != linearDistance) {
            needUpdate = true;
        }
    });


    if (needUpdate) {
        withWriteLock([&] {
            _pointToOffsetFrom = pointToOffsetFrom;
            _linearTimeScale = linearTimeScale;
            _linearDistance = linearDistance;
            _positionalTargetSet = true;
            _active = true;

            auto ownerEntity = _ownerEntity.lock();
            if (ownerEntity) {
                ownerEntity->setActionDataDirty(true);
            }
        });
        activateBody();
    }

    return true;
}
Exemplo n.º 19
0
void ZoneEntityItem::resetRenderingPropertiesChanged() {
    withWriteLock([&] {
        _keyLightPropertiesChanged = false;
        _ambientLightPropertiesChanged = false;
        _skyboxPropertiesChanged = false;
        _hazePropertiesChanged = false;
        _bloomPropertiesChanged = false;
    });
}
Exemplo n.º 20
0
void ZoneEntityItem::somethingChangedNotification() {
    EntityItem::somethingChangedNotification();
    withWriteLock([&] {
        _keyLightPropertiesChanged = false;
        _backgroundPropertiesChanged = false;
        _stagePropertiesChanged = false;
        _skyboxPropertiesChanged = false;
    });
}
Exemplo n.º 21
0
 void Manager::registerHandle(Interface* handle) {
     const QString& key = handle->getKey();
     withWriteLock([&] {
         if (_handles.contains(key)) {
             qWarning() << "Setting::Manager::registerHandle(): Key registered more than once, overriding: " << key;
         }
         _handles.insert(key, handle);
     });
 }
Exemplo n.º 22
0
bool ObjectConstraintBallSocket::updateArguments(QVariantMap arguments) {
    glm::vec3 pivotInA;
    QUuid otherEntityID;
    glm::vec3 pivotInB;

    bool needUpdate = false;
    bool somethingChanged = ObjectDynamic::updateArguments(arguments);
    withReadLock([&]{
        bool ok = true;
        pivotInA = EntityDynamicInterface::extractVec3Argument("ball-socket constraint", arguments, "pivot", ok, false);
        if (!ok) {
            pivotInA = _pivotInA;
        }

        ok = true;
        otherEntityID = QUuid(EntityDynamicInterface::extractStringArgument("ball-socket constraint",
                                                                            arguments, "otherEntityID", ok, false));
        if (!ok) {
            otherEntityID = _otherID;
        }

        ok = true;
        pivotInB = EntityDynamicInterface::extractVec3Argument("ball-socket constraint", arguments, "otherPivot", ok, false);
        if (!ok) {
            pivotInB = _pivotInB;
        }

        if (somethingChanged ||
            pivotInA != _pivotInA ||
            otherEntityID != _otherID ||
            pivotInB != _pivotInB) {
            // something changed
            needUpdate = true;
        }
    });

    if (needUpdate) {
        withWriteLock([&] {
            _pivotInA = pivotInA;
            _otherID = otherEntityID;
            _pivotInB = pivotInB;

            _active = true;

            auto ownerEntity = _ownerEntity.lock();
            if (ownerEntity) {
                ownerEntity->setDynamicDataDirty(true);
                ownerEntity->setDynamicDataNeedsTransmit(true);
            }
        });

        updateBallSocket();
    }

    return true;
}
Exemplo n.º 23
0
void ZoneEntityItem::setFilterURL(QString url) {
    withWriteLock([&] {
        _filterURL = url;
    });
    if (DependencyManager::isSet<EntityEditFilters>()) {
        auto entityEditFilters = DependencyManager::get<EntityEditFilters>();
        qCDebug(entities) << "adding filter " << url << "for zone" << getEntityItemID();
        entityEditFilters->addFilter(getEntityItemID(), url);
    }
}
Exemplo n.º 24
0
    void Manager::saveSetting(Interface* handle) {
        const auto& key = handle->getKey();
        QVariant handleValue = UNSET_VALUE;
        if (handle->isSet()) {
            handleValue = handle->getVariant();
        }

        withWriteLock([&] {
            _pendingChanges[key] = handleValue;
        });
    }
Exemplo n.º 25
0
btTypedConstraint* ObjectConstraintBallSocket::getConstraint() {
    btPoint2PointConstraint* constraint { nullptr };
    QUuid otherEntityID;
    glm::vec3 pivotInA;
    glm::vec3 pivotInB;

    withReadLock([&]{
        constraint = static_cast<btPoint2PointConstraint*>(_constraint);
        pivotInA = _pivotInA;
        otherEntityID = _otherID;
        pivotInB = _pivotInB;
    });
    if (constraint) {
        return constraint;
    }

    static QString repeatedBallSocketNoRigidBody = LogHandler::getInstance().addRepeatedMessageRegex(
        "ObjectConstraintBallSocket::getConstraint -- no rigidBody.*");

    btRigidBody* rigidBodyA = getRigidBody();
    if (!rigidBodyA) {
        qCDebug(physics) << "ObjectConstraintBallSocket::getConstraint -- no rigidBodyA";
        return nullptr;
    }

    if (!otherEntityID.isNull()) {
        // This constraint is between two entities... find the other rigid body.

        btRigidBody* rigidBodyB = getOtherRigidBody(otherEntityID);
        if (!rigidBodyB) {
            qCDebug(physics) << "ObjectConstraintBallSocket::getConstraint -- no rigidBodyB";
            return nullptr;
        }

        constraint = new btPoint2PointConstraint(*rigidBodyA, *rigidBodyB, glmToBullet(pivotInA), glmToBullet(pivotInB));
    } else {
        // This constraint is between an entity and the world-frame.

        constraint = new btPoint2PointConstraint(*rigidBodyA, glmToBullet(pivotInA));
    }

    withWriteLock([&]{
        _constraint = constraint;
    });

    // if we don't wake up rigidBodyA, we may not send the dynamicData property over the network
    forceBodyNonStatic();
    activateBody();

    updateBallSocket();

    return constraint;
}
Exemplo n.º 26
0
void WebEntityItem::setScriptURL(const QString& value) {
    withWriteLock([&] {
        if (_scriptURL != value) {
            auto newURL = QUrl::fromUserInput(value);

            if (newURL.isValid()) {
                _scriptURL = newURL.toDisplayString();
            } else {
                qCDebug(entities) << "Not setting web entity script URL since" << value << "cannot be parsed to a valid URL.";
            }
        }
    });
}
Exemplo n.º 27
0
void ZoneEntityItem::setCompoundShapeURL(const QString& url) {
    QString oldCompoundShapeURL = _compoundShapeURL;
    withWriteLock([&] {
        _compoundShapeURL = url;
    });
    if (oldCompoundShapeURL != url) {
        if (_shapeType == SHAPE_TYPE_COMPOUND) {
            fetchCollisionGeometryResource();
        } else {
            _shapeResource.reset();
        }
    }
}
Exemplo n.º 28
0
 void Manager::loadSetting(Interface* handle) {
     const auto& key = handle->getKey();
     withWriteLock([&] {
         QVariant loadedValue;
         if (_pendingChanges.contains(key)) {
             loadedValue = _pendingChanges[key];
         } else {
             loadedValue = value(key);
         }
         if (loadedValue.isValid()) {
             handle->setVariant(loadedValue);
         }
     });
 }
Exemplo n.º 29
0
void AvatarActionHold::prepareForPhysicsSimulation() {
    auto avatarManager = DependencyManager::get<AvatarManager>();
    auto holdingAvatar = std::static_pointer_cast<Avatar>(avatarManager->getAvatarBySessionID(_holderID));

    if (!holdingAvatar || !holdingAvatar->isMyAvatar()) {
        return;
    }

    withWriteLock([&]{
        glm::vec3 avatarRigidBodyPosition;
        glm::quat avatarRigidBodyRotation;
        getAvatarRigidBodyLocation(avatarRigidBodyPosition, avatarRigidBodyRotation);

        if (_ignoreIK) {
            return;
        }

        glm::vec3 palmPosition;
        glm::quat palmRotation;
        if (_hand == "right") {
            palmPosition = holdingAvatar->getUncachedRightPalmPosition();
            palmRotation = holdingAvatar->getUncachedRightPalmRotation();
        } else {
            palmPosition = holdingAvatar->getUncachedLeftPalmPosition();
            palmRotation = holdingAvatar->getUncachedLeftPalmRotation();
        }


        // determine the difference in translation and rotation between the avatar's
        // rigid body and the palm position.  The avatar's rigid body will be moved by bullet
        // between this call and the call to getTarget, below.  A call to get*PalmPosition in
        // getTarget would get the palm position of the previous location of the avatar (because
        // bullet has moved the av's rigid body but the rigid body's location has not yet been
        // copied out into the Avatar class.
        //glm::quat avatarRotationInverse = glm::inverse(avatarRigidBodyRotation);

        // the offset should be in the frame of the avatar, but something about the order
        // things are updated makes this wrong:
        //   _palmOffsetFromRigidBody = avatarRotationInverse * (palmPosition - avatarRigidBodyPosition);
        // I'll leave it here as a comment in case avatar handling changes.
        _palmOffsetFromRigidBody = palmPosition - avatarRigidBodyPosition;

        // rotation should also be needed, but again, the order of updates makes this unneeded.  leaving
        // code here for future reference.
        // _palmRotationFromRigidBody = avatarRotationInverse * palmRotation;
    });

    activateBody(true);
}
Exemplo n.º 30
0
bool AvatarActionHold::updateArguments(QVariantMap arguments) {
    bool ok = true;
    glm::vec3 relativePosition =
        EntityActionInterface::extractVec3Argument("hold", arguments, "relativePosition", ok, false);
    if (!ok) {
        relativePosition = _relativePosition;
    }

    ok = true;
    glm::quat relativeRotation =
        EntityActionInterface::extractQuatArgument("hold", arguments, "relativeRotation", ok, false);
    if (!ok) {
        relativeRotation = _relativeRotation;
    }
    
    ok = true;
    float timeScale =
        EntityActionInterface::extractFloatArgument("hold", arguments, "timeScale", ok, false);
    if (!ok) {
        timeScale = _linearTimeScale;
    }

    ok = true;
    QString hand =
        EntityActionInterface::extractStringArgument("hold", arguments, "hand", ok, false);
    if (!ok || !(hand == "left" || hand == "right")) {
        hand = _hand;
    }

    if (relativePosition != _relativePosition
            || relativeRotation != _relativeRotation
            || timeScale != _linearTimeScale
            || hand != _hand) {
        withWriteLock([&] {
            _relativePosition = relativePosition;
            _relativeRotation = relativeRotation;
            const float MIN_TIMESCALE = 0.1f;
            _linearTimeScale = glm::min(MIN_TIMESCALE, timeScale);
            _angularTimeScale = _linearTimeScale;
            _hand = hand;

            _mine = true;
            _active = true;
            activateBody();
        });
    }
    return true;
}