mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 17:00:13 +02:00
Add ability to bind a panel to an entity.
This commit is contained in:
parent
4a1fcbf160
commit
865067aad9
2 changed files with 27 additions and 0 deletions
|
@ -14,6 +14,7 @@
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <RegisteredMetaTypes.h>
|
#include <RegisteredMetaTypes.h>
|
||||||
#include <DependencyManager.h>
|
#include <DependencyManager.h>
|
||||||
|
#include <EntityScriptingInterface.h>
|
||||||
|
|
||||||
#include "avatar/AvatarManager.h"
|
#include "avatar/AvatarManager.h"
|
||||||
#include "avatar/MyAvatar.h"
|
#include "avatar/MyAvatar.h"
|
||||||
|
@ -26,6 +27,9 @@ glm::vec3 FloatingUIPanel::getComputedAnchorPosition() const {
|
||||||
pos = getAttachedPanel()->getPosition();
|
pos = getAttachedPanel()->getPosition();
|
||||||
} else if (_anchorPositionBindMyAvatar) {
|
} else if (_anchorPositionBindMyAvatar) {
|
||||||
pos = DependencyManager::get<AvatarManager>()->getMyAvatar()->getPosition();
|
pos = DependencyManager::get<AvatarManager>()->getMyAvatar()->getPosition();
|
||||||
|
} else if (!_anchorPositionBindEntity.isNull()) {
|
||||||
|
pos = DependencyManager::get<EntityScriptingInterface>()->getEntityTree()->
|
||||||
|
findEntityByID(_anchorPositionBindEntity)->getPosition();
|
||||||
}
|
}
|
||||||
return pos + getAnchorPosition();
|
return pos + getAnchorPosition();
|
||||||
}
|
}
|
||||||
|
@ -37,6 +41,9 @@ glm::quat FloatingUIPanel::getComputedOffsetRotation() const {
|
||||||
} else if (_offsetRotationBindMyAvatar) {
|
} else if (_offsetRotationBindMyAvatar) {
|
||||||
rot = DependencyManager::get<AvatarManager>()->getMyAvatar()->getOrientation() *
|
rot = DependencyManager::get<AvatarManager>()->getMyAvatar()->getOrientation() *
|
||||||
glm::angleAxis(glm::pi<float>(), IDENTITY_UP);
|
glm::angleAxis(glm::pi<float>(), IDENTITY_UP);
|
||||||
|
} else if (!_offsetRotationBindEntity.isNull()) {
|
||||||
|
rot = DependencyManager::get<EntityScriptingInterface>()->getEntityTree()->
|
||||||
|
findEntityByID(_offsetRotationBindEntity)->getRotation();
|
||||||
}
|
}
|
||||||
return rot * getOffsetRotation();
|
return rot * getOffsetRotation();
|
||||||
}
|
}
|
||||||
|
@ -67,9 +74,13 @@ QScriptValue FloatingUIPanel::getProperty(const QString &property) {
|
||||||
}
|
}
|
||||||
if (property == "anchorPositionBinding") {
|
if (property == "anchorPositionBinding") {
|
||||||
QScriptValue obj = _scriptEngine->newObject();
|
QScriptValue obj = _scriptEngine->newObject();
|
||||||
|
|
||||||
if (_anchorPositionBindMyAvatar) {
|
if (_anchorPositionBindMyAvatar) {
|
||||||
obj.setProperty("avatar", "MyAvatar");
|
obj.setProperty("avatar", "MyAvatar");
|
||||||
|
} else if (!_anchorPositionBindEntity.isNull()) {
|
||||||
|
obj.setProperty("entity", _scriptEngine->newVariant(_anchorPositionBindEntity));
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.setProperty("computed", vec3toScriptValue(_scriptEngine, getComputedAnchorPosition()));
|
obj.setProperty("computed", vec3toScriptValue(_scriptEngine, getComputedAnchorPosition()));
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
@ -78,9 +89,13 @@ QScriptValue FloatingUIPanel::getProperty(const QString &property) {
|
||||||
}
|
}
|
||||||
if (property == "offsetRotationBinding") {
|
if (property == "offsetRotationBinding") {
|
||||||
QScriptValue obj = _scriptEngine->newObject();
|
QScriptValue obj = _scriptEngine->newObject();
|
||||||
|
|
||||||
if (_offsetRotationBindMyAvatar) {
|
if (_offsetRotationBindMyAvatar) {
|
||||||
obj.setProperty("avatar", "MyAvatar");
|
obj.setProperty("avatar", "MyAvatar");
|
||||||
|
} else if (!_offsetRotationBindEntity.isNull()) {
|
||||||
|
obj.setProperty("entity", _scriptEngine->newVariant(_offsetRotationBindEntity));
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.setProperty("computed", quatToScriptValue(_scriptEngine, getComputedOffsetRotation()));
|
obj.setProperty("computed", quatToScriptValue(_scriptEngine, getComputedOffsetRotation()));
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
@ -112,11 +127,15 @@ void FloatingUIPanel::setProperties(const QScriptValue &properties) {
|
||||||
QScriptValue anchorPositionBinding = properties.property("anchorPositionBinding");
|
QScriptValue anchorPositionBinding = properties.property("anchorPositionBinding");
|
||||||
if (anchorPositionBinding.isValid()) {
|
if (anchorPositionBinding.isValid()) {
|
||||||
_anchorPositionBindMyAvatar = false;
|
_anchorPositionBindMyAvatar = false;
|
||||||
|
_anchorPositionBindEntity = QUuid();
|
||||||
|
|
||||||
QScriptValue avatar = anchorPositionBinding.property("avatar");
|
QScriptValue avatar = anchorPositionBinding.property("avatar");
|
||||||
|
QScriptValue entity = anchorPositionBinding.property("entity");
|
||||||
|
|
||||||
if (avatar.isValid()) {
|
if (avatar.isValid()) {
|
||||||
_anchorPositionBindMyAvatar = (avatar.toVariant().toString() == "MyAvatar");
|
_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");
|
QScriptValue offsetRotationBinding = properties.property("offsetRotationBinding");
|
||||||
if (offsetRotationBinding.isValid()) {
|
if (offsetRotationBinding.isValid()) {
|
||||||
_offsetRotationBindMyAvatar = false;
|
_offsetRotationBindMyAvatar = false;
|
||||||
|
_offsetRotationBindEntity = QUuid();
|
||||||
|
|
||||||
QScriptValue avatar = offsetRotationBinding.property("avatar");
|
QScriptValue avatar = offsetRotationBinding.property("avatar");
|
||||||
|
QScriptValue entity = anchorPositionBinding.property("entity");
|
||||||
|
|
||||||
if (avatar.isValid()) {
|
if (avatar.isValid()) {
|
||||||
_offsetRotationBindMyAvatar = (avatar.toVariant().toString() == "MyAvatar");
|
_offsetRotationBindMyAvatar = (avatar.toVariant().toString() == "MyAvatar");
|
||||||
|
} else if (entity.isValid() && !entity.isNull()) {
|
||||||
|
_offsetRotationBindEntity = entity.toVariant().toUuid();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtc/quaternion.hpp>
|
#include <glm/gtc/quaternion.hpp>
|
||||||
#include <QScriptValue>
|
#include <QScriptValue>
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
class FloatingUIPanel : public QObject {
|
class FloatingUIPanel : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -59,7 +60,10 @@ private:
|
||||||
glm::quat _facingRotation = {1, 0, 0, 0};
|
glm::quat _facingRotation = {1, 0, 0, 0};
|
||||||
|
|
||||||
bool _anchorPositionBindMyAvatar = false;
|
bool _anchorPositionBindMyAvatar = false;
|
||||||
|
QUuid _anchorPositionBindEntity;
|
||||||
|
|
||||||
bool _offsetRotationBindMyAvatar = false;
|
bool _offsetRotationBindMyAvatar = false;
|
||||||
|
QUuid _offsetRotationBindEntity;
|
||||||
|
|
||||||
Pointer _attachedPanel = nullptr;
|
Pointer _attachedPanel = nullptr;
|
||||||
QScriptEngine* _scriptEngine;
|
QScriptEngine* _scriptEngine;
|
||||||
|
|
Loading…
Reference in a new issue