From b5199220ab459aaffd0539612543c4cf3952f46c Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 2 Nov 2017 17:07:53 -0700 Subject: [PATCH] cleanup SpatiallyNestable Velocity to match WorldVelocity naming --- interface/src/avatar/AvatarMotionState.cpp | 4 +-- interface/src/avatar/MyAvatar.cpp | 12 +++---- interface/src/ui/OverlayConductor.cpp | 2 +- interface/src/ui/Stats.cpp | 2 +- .../src/avatars-renderer/Avatar.cpp | 6 ++-- libraries/avatars/src/AvatarData.h | 4 +-- libraries/avatars/src/ScriptAvatarData.cpp | 4 +-- libraries/entities/src/EntityItem.h | 13 +++---- .../entities/src/EntityScriptingInterface.cpp | 4 +-- libraries/entities/src/PolyLineEntityItem.h | 2 +- libraries/physics/src/EntityMotionState.cpp | 6 ++-- libraries/physics/src/EntityMotionState.h | 4 +-- libraries/shared/src/SpatiallyNestable.cpp | 34 +++++++++---------- libraries/shared/src/SpatiallyNestable.h | 16 ++++----- 14 files changed, 57 insertions(+), 56 deletions(-) diff --git a/interface/src/avatar/AvatarMotionState.cpp b/interface/src/avatar/AvatarMotionState.cpp index 4f6f2b0b71..900c1c0a11 100644 --- a/interface/src/avatar/AvatarMotionState.cpp +++ b/interface/src/avatar/AvatarMotionState.cpp @@ -116,12 +116,12 @@ glm::quat AvatarMotionState::getObjectRotation() const { // virtual glm::vec3 AvatarMotionState::getObjectLinearVelocity() const { - return _avatar->getVelocity(); + return _avatar->getWorldVelocity(); } // virtual glm::vec3 AvatarMotionState::getObjectAngularVelocity() const { - return _avatar->getAngularVelocity(); + return _avatar->getWorldAngularVelocity(); } // virtual diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index bfaae00f68..5427f3974d 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -1617,13 +1617,13 @@ void MyAvatar::harvestResultsFromPhysicsSimulation(float deltaTime) { _bodySensorMatrix = _follow.postPhysicsUpdate(*this, _bodySensorMatrix); if (_characterController.isEnabledAndReady()) { - setVelocity(_characterController.getLinearVelocity() + _characterController.getFollowVelocity()); + setWorldVelocity(_characterController.getLinearVelocity() + _characterController.getFollowVelocity()); if (_characterController.isStuck()) { _physicsSafetyPending = true; _goToPosition = getWorldPosition(); } } else { - setVelocity(getVelocity() + _characterController.getFollowVelocity()); + setWorldVelocity(getWorldVelocity() + _characterController.getFollowVelocity()); } } @@ -1962,7 +1962,7 @@ void MyAvatar::updateOrientation(float deltaTime) { if (qApp->isHMDMode() && getCharacterController()->getState() == CharacterController::State::Hover && _hmdRollControlEnabled && hasDriveInput()) { // Turn with head roll. const float MIN_CONTROL_SPEED = 0.01f; - float speed = glm::length(getVelocity()); + float speed = glm::length(getWorldVelocity()); if (speed >= MIN_CONTROL_SPEED) { // Feather turn when stopping moving. float speedFactor; @@ -1973,7 +1973,7 @@ void MyAvatar::updateOrientation(float deltaTime) { speedFactor = glm::min(speed / _lastDrivenSpeed, 1.0f); } - float direction = glm::dot(getVelocity(), getWorldOrientation() * Vectors::UNIT_NEG_Z) > 0.0f ? 1.0f : -1.0f; + float direction = glm::dot(getWorldVelocity(), getWorldOrientation() * Vectors::UNIT_NEG_Z) > 0.0f ? 1.0f : -1.0f; float rollAngle = glm::degrees(asinf(glm::dot(IDENTITY_UP, _hmdSensorOrientation * IDENTITY_RIGHT))); float rollSign = rollAngle < 0.0f ? -1.0f : 1.0f; @@ -2084,7 +2084,7 @@ void MyAvatar::updatePosition(float deltaTime) { updateActionMotor(deltaTime); } - vec3 velocity = getVelocity(); + vec3 velocity = getWorldVelocity(); float sensorToWorldScale = getSensorToWorldScale(); float sensorToWorldScale2 = sensorToWorldScale * sensorToWorldScale; const float MOVING_SPEED_THRESHOLD_SQUARED = 0.0001f; // 0.01 m/s @@ -2896,7 +2896,7 @@ glm::mat4 MyAvatar::FollowHelper::postPhysicsUpdate(const MyAvatar& myAvatar, co } float MyAvatar::getAccelerationEnergy() { - glm::vec3 velocity = getVelocity(); + glm::vec3 velocity = getWorldVelocity(); int changeInVelocity = abs(velocity.length() - priorVelocity.length()); float changeInEnergy = priorVelocity.length() * changeInVelocity * AVATAR_MOVEMENT_ENERGY_CONSTANT; priorVelocity = velocity; diff --git a/interface/src/ui/OverlayConductor.cpp b/interface/src/ui/OverlayConductor.cpp index dbf58c5cbc..ed8fa53fe2 100644 --- a/interface/src/ui/OverlayConductor.cpp +++ b/interface/src/ui/OverlayConductor.cpp @@ -49,7 +49,7 @@ bool OverlayConductor::updateAvatarIsAtRest() { const quint64 REST_DISABLE_TIME_USECS = 200 * 1000; // 200 ms const float AT_REST_THRESHOLD = 0.01f; - bool desiredAtRest = glm::length(myAvatar->getVelocity()) < AT_REST_THRESHOLD; + bool desiredAtRest = glm::length(myAvatar->getWorldVelocity()) < AT_REST_THRESHOLD; if (desiredAtRest != _desiredAtRest) { // start timer _desiredAtRestTimer = usecTimestampNow() + (desiredAtRest ? REST_ENABLE_TIME_USECS : REST_DISABLE_TIME_USECS); diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index 4fa5e5726b..e194551add 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -194,7 +194,7 @@ void Stats::updateStats(bool force) { auto myAvatar = avatarManager->getMyAvatar(); glm::vec3 avatarPos = myAvatar->getWorldPosition(); STAT_UPDATE(position, QVector3D(avatarPos.x, avatarPos.y, avatarPos.z)); - STAT_UPDATE_FLOAT(speed, glm::length(myAvatar->getVelocity()), 0.01f); + STAT_UPDATE_FLOAT(speed, glm::length(myAvatar->getWorldVelocity()), 0.01f); STAT_UPDATE_FLOAT(yaw, myAvatar->getBodyYaw(), 0.1f); if (_expanded || force) { SharedNodePointer avatarMixer = nodeList->soloNodeOfType(NodeType::AvatarMixer); diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index 072eb22532..881f30299e 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -436,7 +436,7 @@ bool Avatar::isLookingAtMe(AvatarSharedPointer avatar) const { void Avatar::slamPosition(const glm::vec3& newPosition) { setWorldPosition(newPosition); _positionDeltaAccumulator = glm::vec3(0.0f); - setVelocity(glm::vec3(0.0f)); + setWorldVelocity(glm::vec3(0.0f)); _lastVelocity = glm::vec3(0.0f); } @@ -460,13 +460,13 @@ void Avatar::measureMotionDerivatives(float deltaTime) { _positionDeltaAccumulator = glm::vec3(0.0f); _acceleration = (velocity - _lastVelocity) * invDeltaTime; _lastVelocity = velocity; - setVelocity(velocity); + setWorldVelocity(velocity); // angular glm::quat orientation = getWorldOrientation(); glm::quat delta = glm::inverse(_lastOrientation) * orientation; glm::vec3 angularVelocity = glm::axis(delta) * glm::angle(delta) * invDeltaTime; - setAngularVelocity(angularVelocity); + setWorldAngularVelocity(angularVelocity); _lastOrientation = getWorldOrientation(); } diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 61e27a482e..cad547b03c 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -365,8 +365,8 @@ class AvatarData : public QObject, public SpatiallyNestable { Q_PROPERTY(float headYaw READ getHeadYaw WRITE setHeadYaw) Q_PROPERTY(float headRoll READ getHeadRoll WRITE setHeadRoll) - Q_PROPERTY(glm::vec3 velocity READ getVelocity WRITE setVelocity) - Q_PROPERTY(glm::vec3 angularVelocity READ getAngularVelocity WRITE setAngularVelocity) + Q_PROPERTY(glm::vec3 velocity READ getWorldVelocity WRITE setWorldVelocity) + Q_PROPERTY(glm::vec3 angularVelocity READ getWorldAngularVelocity WRITE setWorldAngularVelocity) Q_PROPERTY(float audioLoudness READ getAudioLoudness WRITE setAudioLoudness) Q_PROPERTY(float audioAverageLoudness READ getAudioAverageLoudness WRITE setAudioAverageLoudness) diff --git a/libraries/avatars/src/ScriptAvatarData.cpp b/libraries/avatars/src/ScriptAvatarData.cpp index 6a57bab0b7..64cd534c8b 100644 --- a/libraries/avatars/src/ScriptAvatarData.cpp +++ b/libraries/avatars/src/ScriptAvatarData.cpp @@ -110,14 +110,14 @@ float ScriptAvatarData::getHeadRoll() const { // glm::vec3 ScriptAvatarData::getVelocity() const { if (AvatarSharedPointer sharedAvatarData = _avatarData.lock()) { - return sharedAvatarData->getVelocity(); + return sharedAvatarData->getWorldVelocity(); } else { return glm::vec3(); } } glm::vec3 ScriptAvatarData::getAngularVelocity() const { if (AvatarSharedPointer sharedAvatarData = _avatarData.lock()) { - return sharedAvatarData->getAngularVelocity(); + return sharedAvatarData->getWorldAngularVelocity(); } else { return glm::vec3(); } diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index a57e4fefda..403c41704b 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -192,7 +192,7 @@ public: float getDensity() const; - bool hasVelocity() const { return getVelocity() != ENTITY_ITEM_ZERO_VEC3; } + bool hasVelocity() const { return getWorldVelocity() != ENTITY_ITEM_ZERO_VEC3; } bool hasLocalVelocity() const { return getLocalVelocity() != ENTITY_ITEM_ZERO_VEC3; } glm::vec3 getGravity() const; /// get gravity in meters @@ -254,9 +254,9 @@ public: glm::vec3 getRegistrationPoint() const; /// registration point as ratio of entity /// registration point as ratio of entity - virtual void setRegistrationPoint(const glm::vec3& value); + virtual void setRegistrationPoint(const glm::vec3& value); // FIXME: this is suspicious! - bool hasAngularVelocity() const { return getAngularVelocity() != ENTITY_ITEM_ZERO_VEC3; } + bool hasAngularVelocity() const { return getWorldAngularVelocity() != ENTITY_ITEM_ZERO_VEC3; } bool hasLocalAngularVelocity() const { return getLocalAngularVelocity() != ENTITY_ITEM_ZERO_VEC3; } virtual void setAngularVelocity(const glm::vec3& angularVelocity); @@ -292,7 +292,7 @@ public: void setLocked(bool value); QString getUserData() const; - virtual void setUserData(const QString& value); + virtual void setUserData(const QString& value); // FIXME: This is suspicious // FIXME not thread safe? const SimulationOwner& getSimulationOwner() const { return _simulationOwner; } @@ -349,10 +349,11 @@ public: void setPosition(const glm::vec3& value); virtual void setParentID(const QUuid& parentID); - virtual void setRotation(glm::quat orientation); - virtual void setVelocity(const glm::vec3& velocity); virtual void setShapeType(ShapeType type) { /* do nothing */ } + void setRotation(glm::quat orientation); + void setVelocity(const glm::vec3& velocity); + uint32_t getDirtyFlags() const; void markDirtyFlags(uint32_t mask); void clearDirtyFlags(uint32_t mask = 0xffffffff); diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 8382bc1920..155ec5b84a 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -376,7 +376,7 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& // If any of these changed, pull any missing properties from the entity. //existing entity, retrieve old velocity for check down below - oldVelocity = entity->getVelocity().length(); + oldVelocity = entity->getWorldVelocity().length(); if (!scriptSideProperties.parentIDChanged()) { properties.setParentID(entity->getParentID()); @@ -532,7 +532,7 @@ void EntityScriptingInterface::deleteEntity(QUuid id) { auto dimensions = entity->getDimensions(); float volume = dimensions.x * dimensions.y * dimensions.z; auto density = entity->getDensity(); - auto velocity = entity->getVelocity().length(); + auto velocity = entity->getWorldVelocity().length(); float cost = calculateCost(density * volume, velocity, 0); cost *= costMultiplier; diff --git a/libraries/entities/src/PolyLineEntityItem.h b/libraries/entities/src/PolyLineEntityItem.h index 7e47ce3aa7..3164a9646b 100644 --- a/libraries/entities/src/PolyLineEntityItem.h +++ b/libraries/entities/src/PolyLineEntityItem.h @@ -99,7 +99,7 @@ class PolyLineEntityItem : public EntityItem { void** intersectedObject, bool precisionPicking) const override { return false; } // disable these external interfaces as PolyLineEntities caculate their own dimensions based on the points they contain - virtual void setRegistrationPoint(const glm::vec3& value) override {}; + virtual void setRegistrationPoint(const glm::vec3& value) override {}; // FIXME: this is suspicious! virtual void debugDump() const override; static const float DEFAULT_LINE_WIDTH; diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index da98e838b0..8ebce9f811 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -125,7 +125,7 @@ void EntityMotionState::handleEasyChanges(uint32_t& flags) { if (flags & Simulation::DIRTY_SIMULATOR_ID) { if (_entity->getSimulatorID().isNull()) { // simulation ownership has been removed by an external simulator - if (glm::length2(_entity->getVelocity()) == 0.0f) { + if (glm::length2(_entity->getWorldVelocity()) == 0.0f) { // this object is coming to rest --> clear the ACTIVATION flag and _outgoingPriority flags &= ~Simulation::DIRTY_PHYSICS_ACTIVATION; _body->setActivationState(WANTS_DEACTIVATION); @@ -542,8 +542,8 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ const float DYNAMIC_ANGULAR_VELOCITY_THRESHOLD = 0.087266f; // ~5 deg/sec bool movingSlowlyLinear = - glm::length2(_entity->getVelocity()) < (DYNAMIC_LINEAR_VELOCITY_THRESHOLD * DYNAMIC_LINEAR_VELOCITY_THRESHOLD); - bool movingSlowlyAngular = glm::length2(_entity->getAngularVelocity()) < + glm::length2(_entity->getWorldVelocity()) < (DYNAMIC_LINEAR_VELOCITY_THRESHOLD * DYNAMIC_LINEAR_VELOCITY_THRESHOLD); + bool movingSlowlyAngular = glm::length2(_entity->getWorldAngularVelocity()) < (DYNAMIC_ANGULAR_VELOCITY_THRESHOLD * DYNAMIC_ANGULAR_VELOCITY_THRESHOLD); bool movingSlowly = movingSlowlyLinear && movingSlowlyAngular && _entity->getAcceleration() == Vectors::ZERO; diff --git a/libraries/physics/src/EntityMotionState.h b/libraries/physics/src/EntityMotionState.h index 2bb692da81..ddfd7e1e4c 100644 --- a/libraries/physics/src/EntityMotionState.h +++ b/libraries/physics/src/EntityMotionState.h @@ -59,8 +59,8 @@ public: virtual glm::vec3 getObjectPosition() const override { return _entity->getWorldPosition() - ObjectMotionState::getWorldOffset(); } virtual glm::quat getObjectRotation() const override { return _entity->getWorldOrientation(); } - virtual glm::vec3 getObjectLinearVelocity() const override { return _entity->getVelocity(); } - virtual glm::vec3 getObjectAngularVelocity() const override { return _entity->getAngularVelocity(); } + virtual glm::vec3 getObjectLinearVelocity() const override { return _entity->getWorldVelocity(); } + virtual glm::vec3 getObjectAngularVelocity() const override { return _entity->getWorldAngularVelocity(); } virtual glm::vec3 getObjectGravity() const override { return _entity->getGravity(); } virtual glm::vec3 getObjectLinearVelocityChange() const override; diff --git a/libraries/shared/src/SpatiallyNestable.cpp b/libraries/shared/src/SpatiallyNestable.cpp index a931a524fd..2114cbf944 100644 --- a/libraries/shared/src/SpatiallyNestable.cpp +++ b/libraries/shared/src/SpatiallyNestable.cpp @@ -240,7 +240,7 @@ glm::vec3 SpatiallyNestable::worldToLocalVelocity(const glm::vec3& velocity, con if (!success) { return velocity; } - glm::vec3 parentVelocity = parent->getVelocity(success); + glm::vec3 parentVelocity = parent->getWorldVelocity(success); if (!success) { return velocity; } @@ -345,7 +345,7 @@ glm::vec3 SpatiallyNestable::localToWorldVelocity(const glm::vec3& velocity, con if (!success) { return velocity; } - glm::vec3 parentVelocity = parent->getVelocity(success); + glm::vec3 parentVelocity = parent->getWorldVelocity(success); if (!success) { return velocity; } @@ -473,7 +473,7 @@ void SpatiallyNestable::setWorldOrientation(const glm::quat& orientation) { #endif } -glm::vec3 SpatiallyNestable::getVelocity(bool& success) const { +glm::vec3 SpatiallyNestable::getWorldVelocity(bool& success) const { glm::vec3 result; Transform parentTransform = getParentTransform(success); if (!success) { @@ -490,16 +490,16 @@ glm::vec3 SpatiallyNestable::getVelocity(bool& success) const { return result; } -glm::vec3 SpatiallyNestable::getVelocity() const { +glm::vec3 SpatiallyNestable::getWorldVelocity() const { bool success; - glm::vec3 result = getVelocity(success); + glm::vec3 result = getWorldVelocity(success); if (!success) { - qCDebug(shared) << "Warning -- getVelocity failed" << getID(); + qCDebug(shared) << "Warning -- getWorldVelocity failed" << getID(); } return result; } -void SpatiallyNestable::setVelocity(const glm::vec3& velocity, bool& success) { +void SpatiallyNestable::setWorldVelocity(const glm::vec3& velocity, bool& success) { glm::vec3 parentVelocity = getParentVelocity(success); Transform parentTransform = getParentTransform(success); _velocityLock.withWriteLock([&] { @@ -518,9 +518,9 @@ void SpatiallyNestable::setVelocity(const glm::vec3& velocity, bool& success) { }); } -void SpatiallyNestable::setVelocity(const glm::vec3& velocity) { +void SpatiallyNestable::setWorldVelocity(const glm::vec3& velocity) { bool success; - setVelocity(velocity, success); + setWorldVelocity(velocity, success); if (!success) { qCDebug(shared) << "Warning -- setVelocity failed" << getID(); } @@ -533,12 +533,12 @@ glm::vec3 SpatiallyNestable::getParentVelocity(bool& success) const { return result; } if (parent) { - result = parent->getVelocity(success); + result = parent->getWorldVelocity(success); } return result; } -glm::vec3 SpatiallyNestable::getAngularVelocity(bool& success) const { +glm::vec3 SpatiallyNestable::getWorldAngularVelocity(bool& success) const { glm::vec3 result; Transform parentTransform = getParentTransform(success); if (!success) { @@ -554,16 +554,16 @@ glm::vec3 SpatiallyNestable::getAngularVelocity(bool& success) const { return result; } -glm::vec3 SpatiallyNestable::getAngularVelocity() const { +glm::vec3 SpatiallyNestable::getWorldAngularVelocity() const { bool success; - glm::vec3 result = getAngularVelocity(success); + glm::vec3 result = getWorldAngularVelocity(success); if (!success) { qCDebug(shared) << "Warning -- getAngularVelocity failed" << getID(); } return result; } -void SpatiallyNestable::setAngularVelocity(const glm::vec3& angularVelocity, bool& success) { +void SpatiallyNestable::setWorldAngularVelocity(const glm::vec3& angularVelocity, bool& success) { glm::vec3 parentAngularVelocity = getParentAngularVelocity(success); Transform parentTransform = getParentTransform(success); _angularVelocityLock.withWriteLock([&] { @@ -571,9 +571,9 @@ void SpatiallyNestable::setAngularVelocity(const glm::vec3& angularVelocity, boo }); } -void SpatiallyNestable::setAngularVelocity(const glm::vec3& angularVelocity) { +void SpatiallyNestable::setWorldAngularVelocity(const glm::vec3& angularVelocity) { bool success; - setAngularVelocity(angularVelocity, success); + setWorldAngularVelocity(angularVelocity, success); if (!success) { qCDebug(shared) << "Warning -- setAngularVelocity failed" << getID(); } @@ -586,7 +586,7 @@ glm::vec3 SpatiallyNestable::getParentAngularVelocity(bool& success) const { return result; } if (parent) { - result = parent->getAngularVelocity(success); + result = parent->getWorldAngularVelocity(success); } return result; } diff --git a/libraries/shared/src/SpatiallyNestable.h b/libraries/shared/src/SpatiallyNestable.h index 929c2d53f2..9cd38f9ce9 100644 --- a/libraries/shared/src/SpatiallyNestable.h +++ b/libraries/shared/src/SpatiallyNestable.h @@ -89,16 +89,16 @@ public: virtual void setWorldOrientation(const glm::quat& orientation, bool& success, bool tellPhysics = true); virtual void setWorldOrientation(const glm::quat& orientation); - virtual glm::vec3 getVelocity(bool& success) const; - virtual glm::vec3 getVelocity() const; - virtual void setVelocity(const glm::vec3& velocity, bool& success); - virtual void setVelocity(const glm::vec3& velocity); + virtual glm::vec3 getWorldVelocity(bool& success) const; + virtual glm::vec3 getWorldVelocity() const; + virtual void setWorldVelocity(const glm::vec3& velocity, bool& success); + virtual void setWorldVelocity(const glm::vec3& velocity); virtual glm::vec3 getParentVelocity(bool& success) const; - virtual glm::vec3 getAngularVelocity(bool& success) const; - virtual glm::vec3 getAngularVelocity() const; - virtual void setAngularVelocity(const glm::vec3& angularVelocity, bool& success); - virtual void setAngularVelocity(const glm::vec3& angularVelocity); + virtual glm::vec3 getWorldAngularVelocity(bool& success) const; + virtual glm::vec3 getWorldAngularVelocity() const; + virtual void setWorldAngularVelocity(const glm::vec3& angularVelocity, bool& success); + virtual void setWorldAngularVelocity(const glm::vec3& angularVelocity); virtual glm::vec3 getParentAngularVelocity(bool& success) const; virtual AACube getMaximumAACube(bool& success) const;