Add back the anchor to panel transform names.

position -> anchorPosition
rotation -> anchorRotation
scale -> anchorScale
This commit is contained in:
Zander Otavka 2015-08-07 11:38:33 -07:00
parent f9630942aa
commit 743e73874f
8 changed files with 99 additions and 101 deletions

View file

@ -23,7 +23,7 @@ var FACE_IMAGE_URL = HIFI_PUBLIC_BUCKET + "images/tools/face-toggle.svg";
var ADDRESS_BAR_IMAGE_URL = HIFI_PUBLIC_BUCKET + "images/tools/address-bar-toggle.svg";
var panel = new OverlayPanel({
positionBinding: { avatar: "MyAvatar" },
anchorPositionBinding: { avatar: "MyAvatar" },
offsetPosition: { x: 0, y: 0.4, z: 1 },
offsetRotation: { w: 0, x: 0, y: 1, z: 0 },
visible: false
@ -210,7 +210,7 @@ function onMouseUp(event) {
if (event.isRightButton && mouseDown.maxDistance < 10) {
panel.setProperties({
visible: !panel.visible,
rotation: Quat.multiply(MyAvatar.orientation, { x: 0, y: 1, z: 0, w: 0 })
anchorRotation: Quat.multiply(MyAvatar.orientation, { x: 0, y: 1, z: 0, w: 0 })
});
}

View file

@ -19,12 +19,12 @@ var RED_DOT_IMAGE_URL = HIFI_PUBLIC_BUCKET + "images/red-dot.svg";
var BLUE_SQUARE_IMAGE_URL = HIFI_PUBLIC_BUCKET + "images/blue-square.svg";
var mainPanel = new OverlayPanel({
positionBinding: { avatar: "MyAvatar" },
position: { x: 0, y: 0, z: 0 },
rotation: { w: 0, x: 0, y: 1, z: 0 },
anchorPositionBinding: { avatar: "MyAvatar" },
anchorPosition: { x: 0, y: 0, z: 0 },
anchorRotation: { w: 1, x: 0, y: 0, z: 0 },
offsetPosition: { x: 0, y: 0.4, z: 1 },
offsetRotation: { w: 1, x: 0, y: 0, z: 0 },
isFacingAvatar: true
offsetRotation: { w: 0, x: 0, y: 1, z: 0 },
isFacingAvatar: false
});
var bluePanel = mainPanel.addChild(new OverlayPanel ({

View file

@ -389,7 +389,7 @@
that.prototype.constructor = that;
var props = [
"position", "positionBinding", "rotation", "rotationBinding", "scale", "visible"
"anchorPosition", "anchorPositionBinding", "anchorRotation", "anchorRotationBinding", "anchorScale", "visible"
].concat(PanelAttachable).concat(Billboardable)
props.forEach(function(prop) {

View file

@ -41,9 +41,6 @@ QScriptValue Billboard3DOverlay::getProperty(const QString &property) {
void Billboard3DOverlay::applyTransformTo(Transform& transform, bool force) {
if (force || usecTimestampNow() > _transformExpiry) {
PanelAttachable::applyTransformTo(transform, true);
transformLookAtCamera(transform);
if (isFacingAvatar()) {
transform.postRotate(getOffsetRotation());
}
pointTransformAtCamera(transform, getOffsetRotation());
}
}

View file

@ -27,8 +27,8 @@ QScriptValue Billboardable::getProperty(QScriptEngine* scriptEngine, const QStri
return QScriptValue();
}
void Billboardable::transformLookAtCamera(Transform& transform) {
if (_isFacingAvatar) {
void Billboardable::pointTransformAtCamera(Transform& transform, glm::quat offsetRotation) {
if (isFacingAvatar()) {
glm::vec3 billboardPos = transform.getTranslation();
glm::vec3 cameraPos = Application::getInstance()->getCamera()->getPosition();
glm::vec3 look = cameraPos - billboardPos;
@ -36,5 +36,6 @@ void Billboardable::transformLookAtCamera(Transform& transform) {
float azimuth = atan2f(look.x, look.z);
glm::quat rotation(glm::vec3(elevation, azimuth, 0));
transform.setRotation(rotation);
transform.postRotate(offsetRotation);
}
}

View file

@ -26,7 +26,7 @@ protected:
void setProperties(const QScriptValue& properties);
QScriptValue getProperty(QScriptEngine* scriptEngine, const QString& property);
void transformLookAtCamera(Transform& transform);
void pointTransformAtCamera(Transform& transform, glm::quat offsetRotation = {1, 0, 0, 0});
private:
bool _isFacingAvatar = false;

View file

@ -64,24 +64,26 @@ void OverlayPanel::removeChild(unsigned int childId) {
}
QScriptValue OverlayPanel::getProperty(const QString &property) {
if (property == "position") {
return vec3toScriptValue(_scriptEngine, getPosition());
if (property == "anchorPosition") {
return vec3toScriptValue(_scriptEngine, getAnchorPosition());
}
if (property == "positionBinding") {
return propertyBindingToScriptValue(_scriptEngine, PropertyBinding(_positionBindMyAvatar ?
"MyAvatar" : "",
_positionBindEntity));
if (property == "anchorPositionBinding") {
return propertyBindingToScriptValue(_scriptEngine,
PropertyBinding(_anchorPositionBindMyAvatar ?
"MyAvatar" : "",
_anchorPositionBindEntity));
}
if (property == "rotation") {
return quatToScriptValue(_scriptEngine, getRotation());
if (property == "anchorRotation") {
return quatToScriptValue(_scriptEngine, getAnchorRotation());
}
if (property == "rotationBinding") {
return propertyBindingToScriptValue(_scriptEngine, PropertyBinding(_rotationBindMyAvatar ?
"MyAvatar" : "",
_rotationBindEntity));
if (property == "anchorRotationBinding") {
return propertyBindingToScriptValue(_scriptEngine,
PropertyBinding(_anchorRotationBindMyAvatar ?
"MyAvatar" : "",
_anchorRotationBindEntity));
}
if (property == "scale") {
return vec3toScriptValue(_scriptEngine, getScale());
if (property == "anchorScale") {
return vec3toScriptValue(_scriptEngine, getAnchorScale());
}
if (property == "visible") {
return getVisible();
@ -105,53 +107,53 @@ void OverlayPanel::setProperties(const QScriptValue &properties) {
PanelAttachable::setProperties(properties);
Billboardable::setProperties(properties);
QScriptValue position = properties.property("position");
if (position.isValid() &&
position.property("x").isValid() &&
position.property("y").isValid() &&
position.property("z").isValid()) {
QScriptValue anchorPosition = properties.property("anchorPosition");
if (anchorPosition.isValid() &&
anchorPosition.property("x").isValid() &&
anchorPosition.property("y").isValid() &&
anchorPosition.property("z").isValid()) {
glm::vec3 newPosition;
vec3FromScriptValue(position, newPosition);
setPosition(newPosition);
vec3FromScriptValue(anchorPosition, newPosition);
setAnchorPosition(newPosition);
}
QScriptValue positionBinding = properties.property("positionBinding");
if (positionBinding.isValid()) {
QScriptValue anchorPositionBinding = properties.property("anchorPositionBinding");
if (anchorPositionBinding.isValid()) {
PropertyBinding binding = {};
propertyBindingFromScriptValue(positionBinding, binding);
_positionBindMyAvatar = binding.avatar == "MyAvatar";
_positionBindEntity = binding.entity;
propertyBindingFromScriptValue(anchorPositionBinding, binding);
_anchorPositionBindMyAvatar = binding.avatar == "MyAvatar";
_anchorPositionBindEntity = binding.entity;
}
QScriptValue rotation = properties.property("rotation");
if (rotation.isValid() &&
rotation.property("x").isValid() &&
rotation.property("y").isValid() &&
rotation.property("z").isValid() &&
rotation.property("w").isValid()) {
QScriptValue anchorRotation = properties.property("anchorRotation");
if (anchorRotation.isValid() &&
anchorRotation.property("x").isValid() &&
anchorRotation.property("y").isValid() &&
anchorRotation.property("z").isValid() &&
anchorRotation.property("w").isValid()) {
glm::quat newRotation;
quatFromScriptValue(rotation, newRotation);
setRotation(newRotation);
quatFromScriptValue(anchorRotation, newRotation);
setAnchorRotation(newRotation);
}
QScriptValue rotationBinding = properties.property("rotationBinding");
if (rotationBinding.isValid()) {
QScriptValue anchorRotationBinding = properties.property("anchorRotationBinding");
if (anchorRotationBinding.isValid()) {
PropertyBinding binding = {};
propertyBindingFromScriptValue(positionBinding, binding);
_rotationBindMyAvatar = binding.avatar == "MyAvatar";
_rotationBindEntity = binding.entity;
propertyBindingFromScriptValue(anchorPositionBinding, binding);
_anchorRotationBindMyAvatar = binding.avatar == "MyAvatar";
_anchorRotationBindEntity = binding.entity;
}
QScriptValue scale = properties.property("scale");
if (scale.isValid()) {
if (scale.property("x").isValid() &&
scale.property("y").isValid() &&
scale.property("z").isValid()) {
QScriptValue anchorScale = properties.property("anchorScale");
if (anchorScale.isValid()) {
if (anchorScale.property("x").isValid() &&
anchorScale.property("y").isValid() &&
anchorScale.property("z").isValid()) {
glm::vec3 newScale;
vec3FromScriptValue(scale, newScale);
setScale(newScale);
vec3FromScriptValue(anchorScale, newScale);
setAnchorScale(newScale);
} else {
setScale(scale.toVariant().toFloat());
setAnchorScale(anchorScale.toVariant().toFloat());
}
}
@ -165,34 +167,34 @@ void OverlayPanel::applyTransformTo(Transform& transform, bool force) {
if (force || usecTimestampNow() > _transformExpiry) {
PanelAttachable::applyTransformTo(transform, true);
if (!getParentPanel()) {
updateTransform();
transform.setTranslation(getPosition());
transform.setRotation(getRotation());
transform.setScale(getScale());
if (_anchorPositionBindMyAvatar) {
transform.setTranslation(DependencyManager::get<AvatarManager>()->getMyAvatar()
->getPosition());
} else if (!_anchorPositionBindEntity.isNull()) {
transform.setTranslation(DependencyManager::get<EntityScriptingInterface>()
->getEntityTree()->findEntityByID(_anchorPositionBindEntity)
->getPosition());
} else {
transform.setTranslation(getAnchorPosition());
}
if (_anchorRotationBindMyAvatar) {
transform.setRotation(DependencyManager::get<AvatarManager>()->getMyAvatar()
->getOrientation());
} else if (!_anchorRotationBindEntity.isNull()) {
transform.setRotation(DependencyManager::get<EntityScriptingInterface>()
->getEntityTree()->findEntityByID(_anchorRotationBindEntity)
->getRotation());
} else {
transform.setRotation(getAnchorRotation());
}
transform.setScale(getAnchorScale());
transform.postTranslate(getOffsetPosition());
transform.postRotate(getOffsetRotation());
transform.postScale(getOffsetScale());
}
transformLookAtCamera(transform);
if (isFacingAvatar()) {
transform.postRotate(getOffsetRotation());
}
}
}
void OverlayPanel::updateTransform() {
if (_positionBindMyAvatar) {
setPosition(DependencyManager::get<AvatarManager>()->getMyAvatar()->getPosition());
} else if (!_positionBindEntity.isNull()) {
setPosition(DependencyManager::get<EntityScriptingInterface>()->getEntityTree()->
findEntityByID(_positionBindEntity)->getPosition());
}
if (_rotationBindMyAvatar) {
setRotation(DependencyManager::get<AvatarManager>()->getMyAvatar()->getOrientation() *
glm::angleAxis(glm::pi<float>(), IDENTITY_UP));
} else if (!_rotationBindEntity.isNull()) {
setRotation(DependencyManager::get<EntityScriptingInterface>()->getEntityTree()->
findEntityByID(_rotationBindEntity)->getRotation());
pointTransformAtCamera(transform, getOffsetRotation());
}
}

View file

@ -43,16 +43,16 @@ public:
void init(QScriptEngine* scriptEngine) { _scriptEngine = scriptEngine; }
// getters
glm::vec3 getPosition() const { return _transform.getTranslation(); }
glm::quat getRotation() const { return _transform.getRotation(); }
glm::vec3 getScale() const { return _transform.getScale(); }
glm::vec3 getAnchorPosition() const { return _anchorTransform.getTranslation(); }
glm::quat getAnchorRotation() const { return _anchorTransform.getRotation(); }
glm::vec3 getAnchorScale() const { return _anchorTransform.getScale(); }
bool getVisible() const { return _visible; }
// setters
void setPosition(const glm::vec3& position) { _transform.setTranslation(position); }
void setRotation(const glm::quat& rotation) { _transform.setRotation(rotation); }
void setScale(float scale) { _transform.setScale(scale); }
void setScale(const glm::vec3& scale) { _transform.setScale(scale); }
void setAnchorPosition(const glm::vec3& position) { _anchorTransform.setTranslation(position); }
void setAnchorRotation(const glm::quat& rotation) { _anchorTransform.setRotation(rotation); }
void setAnchorScale(float scale) { _anchorTransform.setScale(scale); }
void setAnchorScale(const glm::vec3& scale) { _anchorTransform.setScale(scale); }
void setVisible(bool visible) { _visible = visible; }
const QList<unsigned int>& getChildren() { return _children; }
@ -66,15 +66,13 @@ public:
virtual void applyTransformTo(Transform& transform, bool force = false);
private:
void updateTransform();
Transform _anchorTransform;
Transform _transform;
bool _anchorPositionBindMyAvatar = false;
QUuid _anchorPositionBindEntity;
bool _positionBindMyAvatar = false;
QUuid _positionBindEntity;
bool _rotationBindMyAvatar = false;
QUuid _rotationBindEntity;
bool _anchorRotationBindMyAvatar = false;
QUuid _anchorRotationBindEntity;
bool _visible = true;
QList<unsigned int> _children;