Make transforms cascade down the pannel chain.

This commit is contained in:
Zander Otavka 2015-08-06 17:29:37 -07:00
parent 2aacd17843
commit f870f19837
3 changed files with 44 additions and 34 deletions

View file

@ -21,32 +21,6 @@
#include "Application.h"
#include "Base3DOverlay.h"
glm::vec3 OverlayPanel::getComputedPosition() const {
if (getParentPanel()) {
return getParentPanel()->getComputedRotation() * getParentPanel()->getOffsetPosition() +
getParentPanel()->getComputedPosition();
} else if (_positionBindMyAvatar) {
return DependencyManager::get<AvatarManager>()->getMyAvatar()->getPosition();
} else if (!_positionBindEntity.isNull()) {
return DependencyManager::get<EntityScriptingInterface>()->getEntityTree()->
findEntityByID(_positionBindEntity)->getPosition();
}
return getPosition();
}
glm::quat OverlayPanel::getComputedRotation() const {
if (getParentPanel()) {
return getParentPanel()->getComputedRotation() * getParentPanel()->getOffsetRotation();
} else if (_rotationBindMyAvatar) {
return DependencyManager::get<AvatarManager>()->getMyAvatar()->getOrientation() *
glm::angleAxis(glm::pi<float>(), IDENTITY_UP);
} else if (!_rotationBindEntity.isNull()) {
return DependencyManager::get<EntityScriptingInterface>()->getEntityTree()->
findEntityByID(_rotationBindEntity)->getRotation();
}
return getRotation();
}
void OverlayPanel::addChild(unsigned int childId) {
if (!_children.contains(childId)) {
_children.append(childId);
@ -72,7 +46,6 @@ QScriptValue OverlayPanel::getProperty(const QString &property) {
obj.setProperty("entity", _scriptEngine->newVariant(_positionBindEntity));
}
obj.setProperty("computed", vec3toScriptValue(_scriptEngine, getComputedPosition()));
return obj;
}
if (property == "rotation") {
@ -87,7 +60,6 @@ QScriptValue OverlayPanel::getProperty(const QString &property) {
obj.setProperty("entity", _scriptEngine->newVariant(_rotationBindEntity));
}
obj.setProperty("computed", quatToScriptValue(_scriptEngine, getComputedRotation()));
return obj;
}
if (property == "visible") {
@ -173,3 +145,37 @@ void OverlayPanel::setProperties(const QScriptValue &properties) {
setVisible(visible.toVariant().toBool());
}
}
void OverlayPanel::applyTransformTo(Transform& transform) {
if (getParentPanel()) {
getParentPanel()->applyTransformTo(transform);
} else {
transform.setTranslation(getComputedPosition());
transform.setRotation(getComputedRotation());
}
_position = transform.getTranslation();
_rotation = transform.getRotation();
transform.postTranslate(getOffsetPosition());
transform.postRotate(getOffsetRotation());
}
glm::vec3 OverlayPanel::getComputedPosition() const {
if (_positionBindMyAvatar) {
return DependencyManager::get<AvatarManager>()->getMyAvatar()->getPosition();
} else if (!_positionBindEntity.isNull()) {
return DependencyManager::get<EntityScriptingInterface>()->getEntityTree()->
findEntityByID(_positionBindEntity)->getPosition();
}
return getPosition();
}
glm::quat OverlayPanel::getComputedRotation() const {
if (_rotationBindMyAvatar) {
return DependencyManager::get<AvatarManager>()->getMyAvatar()->getOrientation() *
glm::angleAxis(glm::pi<float>(), IDENTITY_UP);
} else if (!_rotationBindEntity.isNull()) {
return DependencyManager::get<EntityScriptingInterface>()->getEntityTree()->
findEntityByID(_rotationBindEntity)->getRotation();
}
return getRotation();
}

View file

@ -31,9 +31,7 @@ public:
// getters
glm::vec3 getPosition() const { return _position; }
glm::vec3 getComputedPosition() const;
glm::quat getRotation() const { return _rotation; }
glm::quat getComputedRotation() const;
bool getVisible() const { return _visible; }
// setters
@ -49,7 +47,12 @@ public:
QScriptValue getProperty(const QString& property);
void setProperties(const QScriptValue& properties);
virtual void applyTransformTo(Transform& transform);
private:
glm::vec3 getComputedPosition() const;
glm::quat getComputedRotation() const;
glm::vec3 _position = {0, 0, 0};
glm::quat _rotation = {1, 0, 0, 0};

View file

@ -25,10 +25,11 @@ bool PanelAttachable::getParentVisible() const {
void PanelAttachable::applyTransformTo(Transform& transform) {
if (getParentPanel()) {
transform.setTranslation(getParentPanel()->getComputedPosition());
transform.setRotation(getParentPanel()->getComputedRotation());
transform.postTranslate(getParentPanel()->getOffsetPosition());
transform.postRotate(getParentPanel()->getOffsetRotation());
// transform.setTranslation(getParentPanel()->getComputedPosition());
// transform.setRotation(getParentPanel()->getComputedRotation());
// transform.postTranslate(getParentPanel()->getOffsetPosition());
// transform.postRotate(getParentPanel()->getOffsetRotation());
getParentPanel()->applyTransformTo(transform);
transform.postTranslate(getOffsetPosition());
transform.postRotate(getOffsetRotation());
}