diff --git a/interface/src/raypick/LaserPointer.cpp b/interface/src/raypick/LaserPointer.cpp index 5fbe3a90b5..e5d76483df 100644 --- a/interface/src/raypick/LaserPointer.cpp +++ b/interface/src/raypick/LaserPointer.cpp @@ -14,13 +14,14 @@ #include "avatar/AvatarManager.h" #include +#include "PickManager.h" #include "RayPick.h" LaserPointer::LaserPointer(const QVariant& rayProps, const RenderStateMap& renderStates, const DefaultRenderStateMap& defaultRenderStates, bool hover, const PointerTriggers& triggers, bool faceAvatar, bool followNormal, float followNormalTime, bool centerEndY, bool lockEnd, - bool distanceScaleEnd, bool scaleWithAvatar, bool enabled) : + bool distanceScaleEnd, bool scaleWithParent, bool enabled) : PathPointer(PickQuery::Ray, rayProps, renderStates, defaultRenderStates, hover, triggers, faceAvatar, followNormal, followNormalTime, - centerEndY, lockEnd, distanceScaleEnd, scaleWithAvatar, enabled) + centerEndY, lockEnd, distanceScaleEnd, scaleWithParent, enabled) { } @@ -28,9 +29,9 @@ void LaserPointer::editRenderStatePath(const std::string& state, const QVariant& auto renderState = std::static_pointer_cast(_renderStates[state]); if (renderState) { updateRenderStateOverlay(renderState->getPathID(), pathProps); - QVariant lineWidth = pathProps.toMap()["lineWidth"]; - if (lineWidth.isValid()) { - renderState->setLineWidth(lineWidth.toFloat()); + QVariant pathWidth = pathProps.toMap()["lineWidth"]; + if (pathWidth.isValid()) { + renderState->setPathWidth(pathWidth.toFloat()); } } } @@ -117,7 +118,7 @@ LaserPointer::RenderState::RenderState(const OverlayID& startID, const OverlayID { if (!_pathID.isNull()) { _pathIgnoreRays = qApp->getOverlays().getProperty(_pathID, "ignoreRayIntersection").value.toBool(); - _lineWidth = qApp->getOverlays().getProperty(_pathID, "lineWidth").value.toFloat(); + _pathWidth = qApp->getOverlays().getProperty(_pathID, "lineWidth").value.toFloat(); } } @@ -138,9 +139,9 @@ void LaserPointer::RenderState::disable() { } } -void LaserPointer::RenderState::update(const glm::vec3& origin, const glm::vec3& end, const glm::vec3& surfaceNormal, bool scaleWithAvatar, bool distanceScaleEnd, bool centerEndY, +void LaserPointer::RenderState::update(const glm::vec3& origin, const glm::vec3& end, const glm::vec3& surfaceNormal, float parentScale, bool distanceScaleEnd, bool centerEndY, bool faceAvatar, bool followNormal, float followNormalStrength, float distance, const PickResultPointer& pickResult) { - StartEndRenderState::update(origin, end, surfaceNormal, scaleWithAvatar, distanceScaleEnd, centerEndY, faceAvatar, followNormal, followNormalStrength, distance, pickResult); + StartEndRenderState::update(origin, end, surfaceNormal, parentScale, distanceScaleEnd, centerEndY, faceAvatar, followNormal, followNormalStrength, distance, pickResult); QVariant endVariant = vec3toVariant(end); if (!getPathID().isNull()) { QVariantMap pathProps; @@ -148,9 +149,7 @@ void LaserPointer::RenderState::update(const glm::vec3& origin, const glm::vec3& pathProps.insert("end", endVariant); pathProps.insert("visible", true); pathProps.insert("ignoreRayIntersection", doesPathIgnoreRays()); - if (scaleWithAvatar) { - pathProps.insert("lineWidth", getLineWidth() * DependencyManager::get()->getMyAvatar()->getSensorToWorldScale()); - } + pathProps.insert("lineWidth", getPathWidth() * parentScale); qApp->getOverlays().editOverlay(getPathID(), pathProps); } } diff --git a/interface/src/raypick/LaserPointer.h b/interface/src/raypick/LaserPointer.h index c0ac3259d9..e5c195f9d4 100644 --- a/interface/src/raypick/LaserPointer.h +++ b/interface/src/raypick/LaserPointer.h @@ -24,23 +24,18 @@ public: const OverlayID& getPathID() const { return _pathID; } const bool& doesPathIgnoreRays() const { return _pathIgnoreRays; } - void setLineWidth(const float& lineWidth) { _lineWidth = lineWidth; } - const float& getLineWidth() const { return _lineWidth; } - void cleanup() override; void disable() override; - void update(const glm::vec3& origin, const glm::vec3& end, const glm::vec3& surfaceNormal, bool scaleWithAvatar, bool distanceScaleEnd, bool centerEndY, + void update(const glm::vec3& origin, const glm::vec3& end, const glm::vec3& surfaceNormal, float parentScale, bool distanceScaleEnd, bool centerEndY, bool faceAvatar, bool followNormal, float followNormalStrength, float distance, const PickResultPointer& pickResult) override; private: OverlayID _pathID; bool _pathIgnoreRays; - - float _lineWidth; }; LaserPointer(const QVariant& rayProps, const RenderStateMap& renderStates, const DefaultRenderStateMap& defaultRenderStates, bool hover, const PointerTriggers& triggers, - bool faceAvatar, bool followNormal, float followNormalStrength, bool centerEndY, bool lockEnd, bool distanceScaleEnd, bool scaleWithAvatar, bool enabled); + bool faceAvatar, bool followNormal, float followNormalStrength, bool centerEndY, bool lockEnd, bool distanceScaleEnd, bool scaleWithParent, bool enabled); QVariantMap toVariantMap() const override; diff --git a/interface/src/raypick/ParabolaPointer.cpp b/interface/src/raypick/ParabolaPointer.cpp index ad698c409b..71e4caeb76 100644 --- a/interface/src/raypick/ParabolaPointer.cpp +++ b/interface/src/raypick/ParabolaPointer.cpp @@ -190,9 +190,9 @@ void ParabolaPointer::RenderState::editParabola(const glm::vec3& color, float al } } -void ParabolaPointer::RenderState::update(const glm::vec3& origin, const glm::vec3& end, const glm::vec3& surfaceNormal, bool scaleWithAvatar, bool distanceScaleEnd, bool centerEndY, +void ParabolaPointer::RenderState::update(const glm::vec3& origin, const glm::vec3& end, const glm::vec3& surfaceNormal, float parentScale, bool distanceScaleEnd, bool centerEndY, bool faceAvatar, bool followNormal, float followNormalStrength, float distance, const PickResultPointer& pickResult) { - StartEndRenderState::update(origin, end, surfaceNormal, scaleWithAvatar, distanceScaleEnd, centerEndY, faceAvatar, followNormal, followNormalStrength, distance, pickResult); + StartEndRenderState::update(origin, end, surfaceNormal, parentScale, distanceScaleEnd, centerEndY, faceAvatar, followNormal, followNormalStrength, distance, pickResult); auto parabolaPickResult = std::static_pointer_cast(pickResult); if (parabolaPickResult && render::Item::isValidID(_pathID)) { render::Transaction transaction; @@ -202,7 +202,7 @@ void ParabolaPointer::RenderState::update(const glm::vec3& origin, const glm::ve glm::vec3 velocity = parabola.velocity; glm::vec3 acceleration = parabola.acceleration; float parabolicDistance = distance > 0.0f ? distance : parabolaPickResult->parabolicDistance; - float width = scaleWithAvatar ? getPathWidth() * DependencyManager::get()->getMyAvatar()->getSensorToWorldScale() : getPathWidth(); + float width = getPathWidth() * parentScale; transaction.updateItem(_pathID, [origin, velocity, acceleration, parabolicDistance, width](ParabolaRenderItem& item) { item.setVisible(true); item.setOrigin(origin); diff --git a/interface/src/raypick/ParabolaPointer.h b/interface/src/raypick/ParabolaPointer.h index 526abe3b0d..e4394bc509 100644 --- a/interface/src/raypick/ParabolaPointer.h +++ b/interface/src/raypick/ParabolaPointer.h @@ -76,22 +76,18 @@ public: }; RenderState() {} - RenderState(const OverlayID& startID, const OverlayID& endID, const glm::vec3& pathColor, float pathAlpha, float pathWidth, + RenderState(const OverlayID& startID, const OverlayID& endID, const glm::vec3& pathColor, float pathAlpha, float parentScale, bool isVisibleInSecondaryCamera, bool pathEnabled); - void setPathWidth(float width) { _pathWidth = width; } - float getPathWidth() const { return _pathWidth; } - void cleanup() override; void disable() override; - void update(const glm::vec3& origin, const glm::vec3& end, const glm::vec3& surfaceNormal, bool scaleWithAvatar, bool distanceScaleEnd, bool centerEndY, + void update(const glm::vec3& origin, const glm::vec3& end, const glm::vec3& surfaceNormal, float parentScale, bool distanceScaleEnd, bool centerEndY, bool faceAvatar, bool followNormal, float followNormalStrength, float distance, const PickResultPointer& pickResult) override; void editParabola(const glm::vec3& color, float alpha, float width, bool isVisibleInSecondaryCamera, bool enabled); private: int _pathID; - float _pathWidth; }; ParabolaPointer(const QVariant& rayProps, const RenderStateMap& renderStates, const DefaultRenderStateMap& defaultRenderStates, bool hover, const PointerTriggers& triggers, diff --git a/interface/src/raypick/PathPointer.cpp b/interface/src/raypick/PathPointer.cpp index 0301136bfa..6cc3dfba56 100644 --- a/interface/src/raypick/PathPointer.cpp +++ b/interface/src/raypick/PathPointer.cpp @@ -17,7 +17,7 @@ PathPointer::PathPointer(PickQuery::PickType type, const QVariant& rayProps, const RenderStateMap& renderStates, const DefaultRenderStateMap& defaultRenderStates, bool hover, const PointerTriggers& triggers, bool faceAvatar, bool followNormal, float followNormalStrength, bool centerEndY, bool lockEnd, - bool distanceScaleEnd, bool scaleWithAvatar, bool enabled) : + bool distanceScaleEnd, bool scaleWithParent, bool enabled) : Pointer(DependencyManager::get()->createPick(type, rayProps), enabled, hover), _renderStates(renderStates), _defaultRenderStates(defaultRenderStates), @@ -28,7 +28,7 @@ PathPointer::PathPointer(PickQuery::PickType type, const QVariant& rayProps, con _centerEndY(centerEndY), _lockEnd(lockEnd), _distanceScaleEnd(distanceScaleEnd), - _scaleWithAvatar(scaleWithAvatar) + _scaleWithParent(scaleWithParent) { for (auto& state : _renderStates) { if (!enabled || state.first != _currentRenderState) { @@ -146,12 +146,18 @@ void PathPointer::updateVisuals(const PickResultPointer& pickResult) { IntersectionType type = getPickedObjectType(pickResult); auto renderState = _renderStates.find(_currentRenderState); auto defaultRenderState = _defaultRenderStates.find(_currentRenderState); + float parentScale = 1; + if (_enabled && _scaleWithParent) { + glm::vec3 dimensions = DependencyManager::get()->getParentTransform(_pickUID).getScale(); + parentScale = glm::max(glm::max(dimensions.x, dimensions.y), dimensions.z); + } + if (_enabled && !_currentRenderState.empty() && renderState != _renderStates.end() && (type != IntersectionType::NONE || _pathLength > 0.0f)) { glm::vec3 origin = getPickOrigin(pickResult); glm::vec3 end = getPickEnd(pickResult, _pathLength); glm::vec3 surfaceNormal = getPickedObjectNormal(pickResult); - renderState->second->update(origin, end, surfaceNormal, _scaleWithAvatar, _distanceScaleEnd, _centerEndY, _faceAvatar, + renderState->second->update(origin, end, surfaceNormal, parentScale, _distanceScaleEnd, _centerEndY, _faceAvatar, _followNormal, _followNormalStrength, _pathLength, pickResult); if (defaultRenderState != _defaultRenderStates.end() && defaultRenderState->second.second->isEnabled()) { defaultRenderState->second.second->disable(); @@ -162,7 +168,7 @@ void PathPointer::updateVisuals(const PickResultPointer& pickResult) { } glm::vec3 origin = getPickOrigin(pickResult); glm::vec3 end = getPickEnd(pickResult, defaultRenderState->second.first); - defaultRenderState->second.second->update(origin, end, Vectors::UP, _scaleWithAvatar, _distanceScaleEnd, _centerEndY, + defaultRenderState->second.second->update(origin, end, Vectors::UP, parentScale, _distanceScaleEnd, _centerEndY, _faceAvatar, _followNormal, _followNormalStrength, defaultRenderState->second.first, pickResult); } else if (!_currentRenderState.empty()) { if (renderState != _renderStates.end() && renderState->second->isEnabled()) { @@ -281,15 +287,13 @@ void StartEndRenderState::disable() { _enabled = false; } -void StartEndRenderState::update(const glm::vec3& origin, const glm::vec3& end, const glm::vec3& surfaceNormal, bool scaleWithAvatar, bool distanceScaleEnd, bool centerEndY, +void StartEndRenderState::update(const glm::vec3& origin, const glm::vec3& end, const glm::vec3& surfaceNormal, float parentScale, bool distanceScaleEnd, bool centerEndY, bool faceAvatar, bool followNormal, float followNormalStrength, float distance, const PickResultPointer& pickResult) { if (!getStartID().isNull()) { QVariantMap startProps; startProps.insert("position", vec3toVariant(origin)); startProps.insert("visible", true); - if (scaleWithAvatar) { - startProps.insert("dimensions", vec3toVariant(getStartDim() * DependencyManager::get()->getMyAvatar()->getSensorToWorldScale())); - } + startProps.insert("dimensions", vec3toVariant(getStartDim() * parentScale)); startProps.insert("ignoreRayIntersection", doesStartIgnoreRays()); qApp->getOverlays().editOverlay(getStartID(), startProps); } @@ -300,8 +304,8 @@ void StartEndRenderState::update(const glm::vec3& origin, const glm::vec3& end, if (distanceScaleEnd) { dim = getEndDim() * glm::distance(origin, end); endProps.insert("dimensions", vec3toVariant(dim)); - } else if (scaleWithAvatar) { - dim = getEndDim() * DependencyManager::get()->getMyAvatar()->getSensorToWorldScale(); + } else { + dim = getEndDim() * parentScale; endProps.insert("dimensions", vec3toVariant(dim)); } diff --git a/interface/src/raypick/PathPointer.h b/interface/src/raypick/PathPointer.h index b3638d1f7d..5001d3d1bd 100644 --- a/interface/src/raypick/PathPointer.h +++ b/interface/src/raypick/PathPointer.h @@ -42,9 +42,12 @@ public: void setEndRot(const glm::quat& endRot) { _endRot = endRot; } const glm::quat& getEndRot() const { return _endRot; } + void setPathWidth(float width) { _pathWidth = width; } + float getPathWidth() const { return _pathWidth; } + virtual void cleanup(); virtual void disable(); - virtual void update(const glm::vec3& origin, const glm::vec3& end, const glm::vec3& surfaceNormal, bool scaleWithAvatar, bool distanceScaleEnd, bool centerEndY, + virtual void update(const glm::vec3& origin, const glm::vec3& end, const glm::vec3& surfaceNormal, float parentScale, bool distanceScaleEnd, bool centerEndY, bool faceAvatar, bool followNormal, float followNormalStrength, float distance, const PickResultPointer& pickResult); bool isEnabled() const { return _enabled; } @@ -58,6 +61,7 @@ protected: glm::vec3 _startDim; glm::vec3 _endDim; glm::quat _endRot; + float _pathWidth; glm::quat _avgEndRot; bool _avgEndRotInitialized { false }; @@ -73,7 +77,7 @@ class PathPointer : public Pointer { public: PathPointer(PickQuery::PickType type, const QVariant& rayProps, const RenderStateMap& renderStates, const DefaultRenderStateMap& defaultRenderStates, bool hover, const PointerTriggers& triggers, bool faceAvatar, bool followNormal, float followNormalStrength, bool centerEndY, bool lockEnd, - bool distanceScaleEnd, bool scaleWithAvatar, bool enabled); + bool distanceScaleEnd, bool scaleWithParent, bool enabled); virtual ~PathPointer(); void setRenderState(const std::string& state) override; @@ -97,7 +101,7 @@ protected: bool _centerEndY; bool _lockEnd; bool _distanceScaleEnd; - bool _scaleWithAvatar; + bool _scaleWithParent; LockEndObject _lockEndObject; struct TriggerState { diff --git a/libraries/pointers/src/PickManager.cpp b/libraries/pointers/src/PickManager.cpp index f7553cb66e..caa62f3397 100644 --- a/libraries/pointers/src/PickManager.cpp +++ b/libraries/pointers/src/PickManager.cpp @@ -90,6 +90,17 @@ void PickManager::setIncludeItems(unsigned int uid, const QVector& includ } } +Transform PickManager::getParentTransform(unsigned int uid) const { + auto pick = findPick(uid); + if (pick) { + auto parentTransform = pick->parentTransform; + if (parentTransform) { + return parentTransform->getTransform(); + } + } + return Transform(); +} + Transform PickManager::getResultTransform(unsigned int uid) const { auto pick = findPick(uid); if (pick) { diff --git a/libraries/pointers/src/PickManager.h b/libraries/pointers/src/PickManager.h index cf911236a1..9d5971078d 100644 --- a/libraries/pointers/src/PickManager.h +++ b/libraries/pointers/src/PickManager.h @@ -43,6 +43,7 @@ public: void setIgnoreItems(unsigned int uid, const QVector& ignore) const; void setIncludeItems(unsigned int uid, const QVector& include) const; + Transform getParentTransform(unsigned int uid) const; Transform getResultTransform(unsigned int uid) const; bool isLeftHand(unsigned int uid);