From 865067aad9f531a674fabfbf2d7ebbe076676cf1 Mon Sep 17 00:00:00 2001 From: Zander Otavka Date: Wed, 5 Aug 2015 16:12:46 -0700 Subject: [PATCH] Add ability to bind a panel to an entity. --- interface/src/ui/overlays/FloatingUIPanel.cpp | 23 +++++++++++++++++++ interface/src/ui/overlays/FloatingUIPanel.h | 4 ++++ 2 files changed, 27 insertions(+) diff --git a/interface/src/ui/overlays/FloatingUIPanel.cpp b/interface/src/ui/overlays/FloatingUIPanel.cpp index 99eab0f241..2fc33bd9ad 100644 --- a/interface/src/ui/overlays/FloatingUIPanel.cpp +++ b/interface/src/ui/overlays/FloatingUIPanel.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include "avatar/AvatarManager.h" #include "avatar/MyAvatar.h" @@ -26,6 +27,9 @@ glm::vec3 FloatingUIPanel::getComputedAnchorPosition() const { pos = getAttachedPanel()->getPosition(); } else if (_anchorPositionBindMyAvatar) { pos = DependencyManager::get()->getMyAvatar()->getPosition(); + } else if (!_anchorPositionBindEntity.isNull()) { + pos = DependencyManager::get()->getEntityTree()-> + findEntityByID(_anchorPositionBindEntity)->getPosition(); } return pos + getAnchorPosition(); } @@ -37,6 +41,9 @@ glm::quat FloatingUIPanel::getComputedOffsetRotation() const { } else if (_offsetRotationBindMyAvatar) { rot = DependencyManager::get()->getMyAvatar()->getOrientation() * glm::angleAxis(glm::pi(), IDENTITY_UP); + } else if (!_offsetRotationBindEntity.isNull()) { + rot = DependencyManager::get()->getEntityTree()-> + findEntityByID(_offsetRotationBindEntity)->getRotation(); } return rot * getOffsetRotation(); } @@ -67,9 +74,13 @@ QScriptValue FloatingUIPanel::getProperty(const QString &property) { } if (property == "anchorPositionBinding") { QScriptValue obj = _scriptEngine->newObject(); + if (_anchorPositionBindMyAvatar) { obj.setProperty("avatar", "MyAvatar"); + } else if (!_anchorPositionBindEntity.isNull()) { + obj.setProperty("entity", _scriptEngine->newVariant(_anchorPositionBindEntity)); } + obj.setProperty("computed", vec3toScriptValue(_scriptEngine, getComputedAnchorPosition())); return obj; } @@ -78,9 +89,13 @@ QScriptValue FloatingUIPanel::getProperty(const QString &property) { } if (property == "offsetRotationBinding") { QScriptValue obj = _scriptEngine->newObject(); + if (_offsetRotationBindMyAvatar) { obj.setProperty("avatar", "MyAvatar"); + } else if (!_offsetRotationBindEntity.isNull()) { + obj.setProperty("entity", _scriptEngine->newVariant(_offsetRotationBindEntity)); } + obj.setProperty("computed", quatToScriptValue(_scriptEngine, getComputedOffsetRotation())); return obj; } @@ -112,11 +127,15 @@ void FloatingUIPanel::setProperties(const QScriptValue &properties) { QScriptValue anchorPositionBinding = properties.property("anchorPositionBinding"); if (anchorPositionBinding.isValid()) { _anchorPositionBindMyAvatar = false; + _anchorPositionBindEntity = QUuid(); QScriptValue avatar = anchorPositionBinding.property("avatar"); + QScriptValue entity = anchorPositionBinding.property("entity"); if (avatar.isValid()) { _anchorPositionBindMyAvatar = (avatar.toVariant().toString() == "MyAvatar"); + } else if (entity.isValid() && !entity.isNull()) { + _anchorPositionBindEntity = entity.toVariant().toUuid(); } } @@ -140,11 +159,15 @@ void FloatingUIPanel::setProperties(const QScriptValue &properties) { QScriptValue offsetRotationBinding = properties.property("offsetRotationBinding"); if (offsetRotationBinding.isValid()) { _offsetRotationBindMyAvatar = false; + _offsetRotationBindEntity = QUuid(); QScriptValue avatar = offsetRotationBinding.property("avatar"); + QScriptValue entity = anchorPositionBinding.property("entity"); if (avatar.isValid()) { _offsetRotationBindMyAvatar = (avatar.toVariant().toString() == "MyAvatar"); + } else if (entity.isValid() && !entity.isNull()) { + _offsetRotationBindEntity = entity.toVariant().toUuid(); } } diff --git a/interface/src/ui/overlays/FloatingUIPanel.h b/interface/src/ui/overlays/FloatingUIPanel.h index a45f57fe4d..fcde560570 100644 --- a/interface/src/ui/overlays/FloatingUIPanel.h +++ b/interface/src/ui/overlays/FloatingUIPanel.h @@ -17,6 +17,7 @@ #include #include #include +#include class FloatingUIPanel : public QObject { Q_OBJECT @@ -59,7 +60,10 @@ private: glm::quat _facingRotation = {1, 0, 0, 0}; bool _anchorPositionBindMyAvatar = false; + QUuid _anchorPositionBindEntity; + bool _offsetRotationBindMyAvatar = false; + QUuid _offsetRotationBindEntity; Pointer _attachedPanel = nullptr; QScriptEngine* _scriptEngine;