mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 23:09:52 +02:00
Add back the anchor to panel transform names.
position -> anchorPosition rotation -> anchorRotation scale -> anchorScale
This commit is contained in:
parent
f9630942aa
commit
743e73874f
8 changed files with 99 additions and 101 deletions
|
@ -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 ADDRESS_BAR_IMAGE_URL = HIFI_PUBLIC_BUCKET + "images/tools/address-bar-toggle.svg";
|
||||||
|
|
||||||
var panel = new OverlayPanel({
|
var panel = new OverlayPanel({
|
||||||
positionBinding: { avatar: "MyAvatar" },
|
anchorPositionBinding: { avatar: "MyAvatar" },
|
||||||
offsetPosition: { x: 0, y: 0.4, z: 1 },
|
offsetPosition: { x: 0, y: 0.4, z: 1 },
|
||||||
offsetRotation: { w: 0, x: 0, y: 1, z: 0 },
|
offsetRotation: { w: 0, x: 0, y: 1, z: 0 },
|
||||||
visible: false
|
visible: false
|
||||||
|
@ -210,7 +210,7 @@ function onMouseUp(event) {
|
||||||
if (event.isRightButton && mouseDown.maxDistance < 10) {
|
if (event.isRightButton && mouseDown.maxDistance < 10) {
|
||||||
panel.setProperties({
|
panel.setProperties({
|
||||||
visible: !panel.visible,
|
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 })
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 BLUE_SQUARE_IMAGE_URL = HIFI_PUBLIC_BUCKET + "images/blue-square.svg";
|
||||||
|
|
||||||
var mainPanel = new OverlayPanel({
|
var mainPanel = new OverlayPanel({
|
||||||
positionBinding: { avatar: "MyAvatar" },
|
anchorPositionBinding: { avatar: "MyAvatar" },
|
||||||
position: { x: 0, y: 0, z: 0 },
|
anchorPosition: { x: 0, y: 0, z: 0 },
|
||||||
rotation: { w: 0, x: 0, y: 1, z: 0 },
|
anchorRotation: { w: 1, x: 0, y: 0, z: 0 },
|
||||||
offsetPosition: { x: 0, y: 0.4, z: 1 },
|
offsetPosition: { x: 0, y: 0.4, z: 1 },
|
||||||
offsetRotation: { w: 1, x: 0, y: 0, z: 0 },
|
offsetRotation: { w: 0, x: 0, y: 1, z: 0 },
|
||||||
isFacingAvatar: true
|
isFacingAvatar: false
|
||||||
});
|
});
|
||||||
|
|
||||||
var bluePanel = mainPanel.addChild(new OverlayPanel ({
|
var bluePanel = mainPanel.addChild(new OverlayPanel ({
|
||||||
|
|
|
@ -389,7 +389,7 @@
|
||||||
that.prototype.constructor = that;
|
that.prototype.constructor = that;
|
||||||
|
|
||||||
var props = [
|
var props = [
|
||||||
"position", "positionBinding", "rotation", "rotationBinding", "scale", "visible"
|
"anchorPosition", "anchorPositionBinding", "anchorRotation", "anchorRotationBinding", "anchorScale", "visible"
|
||||||
].concat(PanelAttachable).concat(Billboardable)
|
].concat(PanelAttachable).concat(Billboardable)
|
||||||
|
|
||||||
props.forEach(function(prop) {
|
props.forEach(function(prop) {
|
||||||
|
|
|
@ -41,9 +41,6 @@ QScriptValue Billboard3DOverlay::getProperty(const QString &property) {
|
||||||
void Billboard3DOverlay::applyTransformTo(Transform& transform, bool force) {
|
void Billboard3DOverlay::applyTransformTo(Transform& transform, bool force) {
|
||||||
if (force || usecTimestampNow() > _transformExpiry) {
|
if (force || usecTimestampNow() > _transformExpiry) {
|
||||||
PanelAttachable::applyTransformTo(transform, true);
|
PanelAttachable::applyTransformTo(transform, true);
|
||||||
transformLookAtCamera(transform);
|
pointTransformAtCamera(transform, getOffsetRotation());
|
||||||
if (isFacingAvatar()) {
|
|
||||||
transform.postRotate(getOffsetRotation());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,8 @@ QScriptValue Billboardable::getProperty(QScriptEngine* scriptEngine, const QStri
|
||||||
return QScriptValue();
|
return QScriptValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Billboardable::transformLookAtCamera(Transform& transform) {
|
void Billboardable::pointTransformAtCamera(Transform& transform, glm::quat offsetRotation) {
|
||||||
if (_isFacingAvatar) {
|
if (isFacingAvatar()) {
|
||||||
glm::vec3 billboardPos = transform.getTranslation();
|
glm::vec3 billboardPos = transform.getTranslation();
|
||||||
glm::vec3 cameraPos = Application::getInstance()->getCamera()->getPosition();
|
glm::vec3 cameraPos = Application::getInstance()->getCamera()->getPosition();
|
||||||
glm::vec3 look = cameraPos - billboardPos;
|
glm::vec3 look = cameraPos - billboardPos;
|
||||||
|
@ -36,5 +36,6 @@ void Billboardable::transformLookAtCamera(Transform& transform) {
|
||||||
float azimuth = atan2f(look.x, look.z);
|
float azimuth = atan2f(look.x, look.z);
|
||||||
glm::quat rotation(glm::vec3(elevation, azimuth, 0));
|
glm::quat rotation(glm::vec3(elevation, azimuth, 0));
|
||||||
transform.setRotation(rotation);
|
transform.setRotation(rotation);
|
||||||
|
transform.postRotate(offsetRotation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ protected:
|
||||||
void setProperties(const QScriptValue& properties);
|
void setProperties(const QScriptValue& properties);
|
||||||
QScriptValue getProperty(QScriptEngine* scriptEngine, const QString& property);
|
QScriptValue getProperty(QScriptEngine* scriptEngine, const QString& property);
|
||||||
|
|
||||||
void transformLookAtCamera(Transform& transform);
|
void pointTransformAtCamera(Transform& transform, glm::quat offsetRotation = {1, 0, 0, 0});
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _isFacingAvatar = false;
|
bool _isFacingAvatar = false;
|
||||||
|
|
|
@ -64,24 +64,26 @@ void OverlayPanel::removeChild(unsigned int childId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QScriptValue OverlayPanel::getProperty(const QString &property) {
|
QScriptValue OverlayPanel::getProperty(const QString &property) {
|
||||||
if (property == "position") {
|
if (property == "anchorPosition") {
|
||||||
return vec3toScriptValue(_scriptEngine, getPosition());
|
return vec3toScriptValue(_scriptEngine, getAnchorPosition());
|
||||||
}
|
}
|
||||||
if (property == "positionBinding") {
|
if (property == "anchorPositionBinding") {
|
||||||
return propertyBindingToScriptValue(_scriptEngine, PropertyBinding(_positionBindMyAvatar ?
|
return propertyBindingToScriptValue(_scriptEngine,
|
||||||
"MyAvatar" : "",
|
PropertyBinding(_anchorPositionBindMyAvatar ?
|
||||||
_positionBindEntity));
|
"MyAvatar" : "",
|
||||||
|
_anchorPositionBindEntity));
|
||||||
}
|
}
|
||||||
if (property == "rotation") {
|
if (property == "anchorRotation") {
|
||||||
return quatToScriptValue(_scriptEngine, getRotation());
|
return quatToScriptValue(_scriptEngine, getAnchorRotation());
|
||||||
}
|
}
|
||||||
if (property == "rotationBinding") {
|
if (property == "anchorRotationBinding") {
|
||||||
return propertyBindingToScriptValue(_scriptEngine, PropertyBinding(_rotationBindMyAvatar ?
|
return propertyBindingToScriptValue(_scriptEngine,
|
||||||
"MyAvatar" : "",
|
PropertyBinding(_anchorRotationBindMyAvatar ?
|
||||||
_rotationBindEntity));
|
"MyAvatar" : "",
|
||||||
|
_anchorRotationBindEntity));
|
||||||
}
|
}
|
||||||
if (property == "scale") {
|
if (property == "anchorScale") {
|
||||||
return vec3toScriptValue(_scriptEngine, getScale());
|
return vec3toScriptValue(_scriptEngine, getAnchorScale());
|
||||||
}
|
}
|
||||||
if (property == "visible") {
|
if (property == "visible") {
|
||||||
return getVisible();
|
return getVisible();
|
||||||
|
@ -105,53 +107,53 @@ void OverlayPanel::setProperties(const QScriptValue &properties) {
|
||||||
PanelAttachable::setProperties(properties);
|
PanelAttachable::setProperties(properties);
|
||||||
Billboardable::setProperties(properties);
|
Billboardable::setProperties(properties);
|
||||||
|
|
||||||
QScriptValue position = properties.property("position");
|
QScriptValue anchorPosition = properties.property("anchorPosition");
|
||||||
if (position.isValid() &&
|
if (anchorPosition.isValid() &&
|
||||||
position.property("x").isValid() &&
|
anchorPosition.property("x").isValid() &&
|
||||||
position.property("y").isValid() &&
|
anchorPosition.property("y").isValid() &&
|
||||||
position.property("z").isValid()) {
|
anchorPosition.property("z").isValid()) {
|
||||||
glm::vec3 newPosition;
|
glm::vec3 newPosition;
|
||||||
vec3FromScriptValue(position, newPosition);
|
vec3FromScriptValue(anchorPosition, newPosition);
|
||||||
setPosition(newPosition);
|
setAnchorPosition(newPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
QScriptValue positionBinding = properties.property("positionBinding");
|
QScriptValue anchorPositionBinding = properties.property("anchorPositionBinding");
|
||||||
if (positionBinding.isValid()) {
|
if (anchorPositionBinding.isValid()) {
|
||||||
PropertyBinding binding = {};
|
PropertyBinding binding = {};
|
||||||
propertyBindingFromScriptValue(positionBinding, binding);
|
propertyBindingFromScriptValue(anchorPositionBinding, binding);
|
||||||
_positionBindMyAvatar = binding.avatar == "MyAvatar";
|
_anchorPositionBindMyAvatar = binding.avatar == "MyAvatar";
|
||||||
_positionBindEntity = binding.entity;
|
_anchorPositionBindEntity = binding.entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
QScriptValue rotation = properties.property("rotation");
|
QScriptValue anchorRotation = properties.property("anchorRotation");
|
||||||
if (rotation.isValid() &&
|
if (anchorRotation.isValid() &&
|
||||||
rotation.property("x").isValid() &&
|
anchorRotation.property("x").isValid() &&
|
||||||
rotation.property("y").isValid() &&
|
anchorRotation.property("y").isValid() &&
|
||||||
rotation.property("z").isValid() &&
|
anchorRotation.property("z").isValid() &&
|
||||||
rotation.property("w").isValid()) {
|
anchorRotation.property("w").isValid()) {
|
||||||
glm::quat newRotation;
|
glm::quat newRotation;
|
||||||
quatFromScriptValue(rotation, newRotation);
|
quatFromScriptValue(anchorRotation, newRotation);
|
||||||
setRotation(newRotation);
|
setAnchorRotation(newRotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
QScriptValue rotationBinding = properties.property("rotationBinding");
|
QScriptValue anchorRotationBinding = properties.property("anchorRotationBinding");
|
||||||
if (rotationBinding.isValid()) {
|
if (anchorRotationBinding.isValid()) {
|
||||||
PropertyBinding binding = {};
|
PropertyBinding binding = {};
|
||||||
propertyBindingFromScriptValue(positionBinding, binding);
|
propertyBindingFromScriptValue(anchorPositionBinding, binding);
|
||||||
_rotationBindMyAvatar = binding.avatar == "MyAvatar";
|
_anchorRotationBindMyAvatar = binding.avatar == "MyAvatar";
|
||||||
_rotationBindEntity = binding.entity;
|
_anchorRotationBindEntity = binding.entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
QScriptValue scale = properties.property("scale");
|
QScriptValue anchorScale = properties.property("anchorScale");
|
||||||
if (scale.isValid()) {
|
if (anchorScale.isValid()) {
|
||||||
if (scale.property("x").isValid() &&
|
if (anchorScale.property("x").isValid() &&
|
||||||
scale.property("y").isValid() &&
|
anchorScale.property("y").isValid() &&
|
||||||
scale.property("z").isValid()) {
|
anchorScale.property("z").isValid()) {
|
||||||
glm::vec3 newScale;
|
glm::vec3 newScale;
|
||||||
vec3FromScriptValue(scale, newScale);
|
vec3FromScriptValue(anchorScale, newScale);
|
||||||
setScale(newScale);
|
setAnchorScale(newScale);
|
||||||
} else {
|
} else {
|
||||||
setScale(scale.toVariant().toFloat());
|
setAnchorScale(anchorScale.toVariant().toFloat());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,34 +167,34 @@ void OverlayPanel::applyTransformTo(Transform& transform, bool force) {
|
||||||
if (force || usecTimestampNow() > _transformExpiry) {
|
if (force || usecTimestampNow() > _transformExpiry) {
|
||||||
PanelAttachable::applyTransformTo(transform, true);
|
PanelAttachable::applyTransformTo(transform, true);
|
||||||
if (!getParentPanel()) {
|
if (!getParentPanel()) {
|
||||||
updateTransform();
|
if (_anchorPositionBindMyAvatar) {
|
||||||
transform.setTranslation(getPosition());
|
transform.setTranslation(DependencyManager::get<AvatarManager>()->getMyAvatar()
|
||||||
transform.setRotation(getRotation());
|
->getPosition());
|
||||||
transform.setScale(getScale());
|
} 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.postTranslate(getOffsetPosition());
|
||||||
transform.postRotate(getOffsetRotation());
|
transform.postRotate(getOffsetRotation());
|
||||||
transform.postScale(getOffsetScale());
|
transform.postScale(getOffsetScale());
|
||||||
}
|
}
|
||||||
transformLookAtCamera(transform);
|
pointTransformAtCamera(transform, getOffsetRotation());
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,16 +43,16 @@ public:
|
||||||
void init(QScriptEngine* scriptEngine) { _scriptEngine = scriptEngine; }
|
void init(QScriptEngine* scriptEngine) { _scriptEngine = scriptEngine; }
|
||||||
|
|
||||||
// getters
|
// getters
|
||||||
glm::vec3 getPosition() const { return _transform.getTranslation(); }
|
glm::vec3 getAnchorPosition() const { return _anchorTransform.getTranslation(); }
|
||||||
glm::quat getRotation() const { return _transform.getRotation(); }
|
glm::quat getAnchorRotation() const { return _anchorTransform.getRotation(); }
|
||||||
glm::vec3 getScale() const { return _transform.getScale(); }
|
glm::vec3 getAnchorScale() const { return _anchorTransform.getScale(); }
|
||||||
bool getVisible() const { return _visible; }
|
bool getVisible() const { return _visible; }
|
||||||
|
|
||||||
// setters
|
// setters
|
||||||
void setPosition(const glm::vec3& position) { _transform.setTranslation(position); }
|
void setAnchorPosition(const glm::vec3& position) { _anchorTransform.setTranslation(position); }
|
||||||
void setRotation(const glm::quat& rotation) { _transform.setRotation(rotation); }
|
void setAnchorRotation(const glm::quat& rotation) { _anchorTransform.setRotation(rotation); }
|
||||||
void setScale(float scale) { _transform.setScale(scale); }
|
void setAnchorScale(float scale) { _anchorTransform.setScale(scale); }
|
||||||
void setScale(const glm::vec3& scale) { _transform.setScale(scale); }
|
void setAnchorScale(const glm::vec3& scale) { _anchorTransform.setScale(scale); }
|
||||||
void setVisible(bool visible) { _visible = visible; }
|
void setVisible(bool visible) { _visible = visible; }
|
||||||
|
|
||||||
const QList<unsigned int>& getChildren() { return _children; }
|
const QList<unsigned int>& getChildren() { return _children; }
|
||||||
|
@ -66,15 +66,13 @@ public:
|
||||||
virtual void applyTransformTo(Transform& transform, bool force = false);
|
virtual void applyTransformTo(Transform& transform, bool force = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateTransform();
|
Transform _anchorTransform;
|
||||||
|
|
||||||
Transform _transform;
|
bool _anchorPositionBindMyAvatar = false;
|
||||||
|
QUuid _anchorPositionBindEntity;
|
||||||
|
|
||||||
bool _positionBindMyAvatar = false;
|
bool _anchorRotationBindMyAvatar = false;
|
||||||
QUuid _positionBindEntity;
|
QUuid _anchorRotationBindEntity;
|
||||||
|
|
||||||
bool _rotationBindMyAvatar = false;
|
|
||||||
QUuid _rotationBindEntity;
|
|
||||||
|
|
||||||
bool _visible = true;
|
bool _visible = true;
|
||||||
QList<unsigned int> _children;
|
QList<unsigned int> _children;
|
||||||
|
|
Loading…
Reference in a new issue