Fix PanelAttachable transformations.

Apply the offsetPosition of the PanelAttachable after the facingRotation
of the FloatingUIPanel, not before.
This commit is contained in:
Zander Otavka 2015-08-03 16:56:56 -07:00
parent be558eb62e
commit 28050a2ac9
6 changed files with 53 additions and 24 deletions

View file

@ -26,7 +26,8 @@ var panel = new FloatingUIPanel({
anchorPosition: { anchorPosition: {
bind: "myAvatar" bind: "myAvatar"
}, },
offsetPosition: { x: 0, y: 0.4, z: 1 } offsetPosition: { x: 0, y: 0.4, z: 1 },
facingRotation: { w: 0, x: 0, y: 1, z: 0 }
}); });
var background = new BillboardOverlay({ var background = new BillboardOverlay({
@ -51,9 +52,9 @@ var closeButton = new BillboardOverlay({
alpha: 1.0, alpha: 1.0,
ignoreRayIntersection: false, ignoreRayIntersection: false,
offsetPosition: { offsetPosition: {
x: -0.1, x: 0.1,
y: 0.1, y: 0.1,
z: -0.001 z: 0.001
} }
}); });
closeButton.onClick = function(event) { closeButton.onClick = function(event) {
@ -77,9 +78,9 @@ var micMuteButton = new BillboardOverlay({
alpha: 1.0, alpha: 1.0,
ignoreRayIntersection: false, ignoreRayIntersection: false,
offsetPosition: { offsetPosition: {
x: 0.1, x: -0.1,
y: 0.1, y: 0.1,
z: -0.001 z: 0.001
} }
}); });
micMuteButton.onClick = function(event) { micMuteButton.onClick = function(event) {
@ -103,9 +104,9 @@ var faceMuteButton = new BillboardOverlay({
alpha: 1.0, alpha: 1.0,
ignoreRayIntersection: false, ignoreRayIntersection: false,
offsetPosition: { offsetPosition: {
x: 0.1, x: -0.1,
y: -0.1, y: -0.1,
z: -0.001 z: 0.001
} }
}); });
faceMuteButton.onClick = function(event) { faceMuteButton.onClick = function(event) {
@ -129,9 +130,9 @@ var addressBarButton = new BillboardOverlay({
alpha: 1.0, alpha: 1.0,
ignoreRayIntersection: false, ignoreRayIntersection: false,
offsetPosition: { offsetPosition: {
x: -0.1, x: 0.1,
y: -0.1, y: -0.1,
z: -0.001 z: 0.001
} }
}); });
addressBarButton.onClick = function(event) { addressBarButton.onClick = function(event) {

View file

@ -23,11 +23,12 @@ var mainPanel = new FloatingUIPanel({
bind: "quat", bind: "quat",
value: { w: 1, x: 0, y: 0, z: 0 } value: { w: 1, x: 0, y: 0, z: 0 }
}, },
offsetPosition: { x: 0, y: 0.4, z: 1 } offsetPosition: { x: 0, y: 0.4, z: 1 },
facingRotation: { w: 0, x: 0, y: 1, z: 0 }
}); });
var bluePanel = mainPanel.addChild(new FloatingUIPanel ({ var bluePanel = mainPanel.addChild(new FloatingUIPanel ({
offsetPosition: { x: 0.1, y: 0.1, z: -0.2 } offsetPosition: { x: 0.1, y: 0.1, z: 0.2 }
})); }));
var mainPanelBackground = new BillboardOverlay({ var mainPanelBackground = new BillboardOverlay({
@ -42,7 +43,7 @@ var mainPanelBackground = new BillboardOverlay({
offsetPosition: { offsetPosition: {
x: 0, x: 0,
y: 0, y: 0,
z: 0.001 z: -0.001
} }
}); });
@ -55,6 +56,34 @@ bluePanelBackground.dimensions = {
mainPanel.addChild(mainPanelBackground); mainPanel.addChild(mainPanelBackground);
bluePanel.addChild(bluePanelBackground); bluePanel.addChild(bluePanelBackground);
var textWidth = .5;
var textHeight = .1;
var numberOfLines = 2;
var textMargin = 0.00625;
var lineHeight = (textHeight - (2 * textMargin)) / numberOfLines;
var text = mainPanel.addChild(new Text3DOverlay({
text: "TEXT",
isFacingAvatar: true,
alpha: 1.0,
ignoreRayIntersection: false,
offsetPosition: {
x: -0.15,
y: -0.15,
z: 0
},
dimensions: { x: textWidth, y: textHeight },
backgroundColor: { red: 0, green: 0, blue: 0 },
color: { red: 255, green: 255, blue: 255 },
topMargin: textMargin,
leftMargin: textMargin,
bottomMargin: textMargin,
rightMargin: textMargin,
lineHeight: lineHeight,
alpha: 0.9,
backgroundAlpha: 0.9
}));
var redDot = mainPanel.addChild(new BillboardOverlay({ var redDot = mainPanel.addChild(new BillboardOverlay({
url: RED_DOT_IMAGE_URL, url: RED_DOT_IMAGE_URL,
dimensions: { dimensions: {
@ -149,7 +178,7 @@ function onMouseUp(event) {
var newPos = { var newPos = {
x: Number(oldPos.x), x: Number(oldPos.x),
y: Number(oldPos.y), y: Number(oldPos.y),
z: Number(oldPos.z) + 0.1 z: Number(oldPos.z) - 0.1
}; };
overlay.offsetPosition = newPos; overlay.offsetPosition = newPos;
} }

View file

@ -94,7 +94,6 @@
OverlayManager = { OverlayManager = {
findOnRay: function(pickRay, knownOverlaysOnly, searchList) { findOnRay: function(pickRay, knownOverlaysOnly, searchList) {
var rayPickResult = Overlays.findRayIntersection(pickRay); var rayPickResult = Overlays.findRayIntersection(pickRay);
print("raypick " + rayPickResult.overlayID);
if (rayPickResult.intersects) { if (rayPickResult.intersects) {
return findOverlay(rayPickResult.overlayID, knownOverlaysOnly, searchList); return findOverlay(rayPickResult.overlayID, knownOverlaysOnly, searchList);
} }
@ -102,7 +101,6 @@
}, },
findAtPoint: function(point, knownOverlaysOnly, searchList) { findAtPoint: function(point, knownOverlaysOnly, searchList) {
var foundID = Overlays.getOverlayAtPoint(point); var foundID = Overlays.getOverlayAtPoint(point);
print("at point " + foundID);
if (foundID) { if (foundID) {
return findOverlay(foundID, knownOverlaysOnly, searchList); return findOverlay(foundID, knownOverlaysOnly, searchList);
} else { } else {
@ -270,7 +268,7 @@
generateOverlayClass(Planar3DOverlay, "text3d", [ generateOverlayClass(Planar3DOverlay, "text3d", [
"text", "backgroundColor", "backgroundAlpha", "lineHeight", "leftMargin", "topMargin", "text", "backgroundColor", "backgroundAlpha", "lineHeight", "leftMargin", "topMargin",
"rightMargin", "bottomMargin", "isFacingAvatar" "rightMargin", "bottomMargin", "isFacingAvatar"
]); ].concat(PANEL_ATTACHABLE_FIELDS));
generateOverlayClass(Volume3DOverlay, "cube", [ generateOverlayClass(Volume3DOverlay, "cube", [
"borderSize" "borderSize"
@ -443,7 +441,6 @@
function onPanelDeleted(id) { function onPanelDeleted(id) {
if (id in panels) { if (id in panels) {
panels[id]._children.forEach(function(child) { panels[id]._children.forEach(function(child) {
print(JSON.stringify(child.destroy));
child.destroy(); child.destroy();
}); });
delete panels[id]; delete panels[id];

View file

@ -43,8 +43,7 @@ void BillboardOverlay::setTransforms(Transform& transform) {
PanelAttachable::setTransforms(transform); PanelAttachable::setTransforms(transform);
if (_isFacingAvatar) { if (_isFacingAvatar) {
glm::quat rotation = Application::getInstance()->getCamera()->getOrientation(); glm::quat rotation = Application::getInstance()->getCamera()->getOrientation();
rotation *= glm::angleAxis(glm::pi<float>(), IDENTITY_UP); transform.setRotation(rotation);
setRotation(rotation);
} }
} }
@ -101,6 +100,7 @@ void BillboardOverlay::render(RenderArgs* args) {
setTransforms(_transform); setTransforms(_transform);
Transform transform = _transform; Transform transform = _transform;
transform.postScale(glm::vec3(getDimensions(), 1.0f)); transform.postScale(glm::vec3(getDimensions(), 1.0f));
transform.postRotate(glm::angleAxis(glm::pi<float>(), IDENTITY_UP));
batch->setModelTransform(transform); batch->setModelTransform(transform);
batch->setResourceTexture(0, _texture->getGPUTexture()); batch->setResourceTexture(0, _texture->getGPUTexture());

View file

@ -15,6 +15,7 @@
PanelAttachable::PanelAttachable() : PanelAttachable::PanelAttachable() :
_attachedPanel(nullptr), _attachedPanel(nullptr),
_offsetPosition(0, 0, 0),
_facingRotation(1, 0, 0, 0) _facingRotation(1, 0, 0, 0)
{ {
} }
@ -30,8 +31,9 @@ void PanelAttachable::setTransforms(Transform& transform) {
if (getAttachedPanel()) { if (getAttachedPanel()) {
transform.setTranslation(getAttachedPanel()->getAnchorPosition()); transform.setTranslation(getAttachedPanel()->getAnchorPosition());
transform.setRotation(getAttachedPanel()->getOffsetRotation()); transform.setRotation(getAttachedPanel()->getOffsetRotation());
transform.postTranslate(getOffsetPosition() + getAttachedPanel()->getOffsetPosition()); transform.postTranslate(getAttachedPanel()->getOffsetPosition());
transform.postRotate(getFacingRotation() * getAttachedPanel()->getFacingRotation()); transform.postRotate(getFacingRotation() * getAttachedPanel()->getFacingRotation());
transform.postTranslate(getOffsetPosition());
} }
} }

View file

@ -23,12 +23,12 @@ public:
PanelAttachable(const PanelAttachable* panelAttachable); PanelAttachable(const PanelAttachable* panelAttachable);
FloatingUIPanel::Pointer getAttachedPanel() const { return _attachedPanel; } FloatingUIPanel::Pointer getAttachedPanel() const { return _attachedPanel; }
glm::vec3 getOffsetPosition() const { return _offsetPosition; } virtual glm::vec3 getOffsetPosition() const { return _offsetPosition; }
glm::quat getFacingRotation() const { return _facingRotation; } virtual glm::quat getFacingRotation() const { return _facingRotation; }
void setAttachedPanel(FloatingUIPanel::Pointer panel) { _attachedPanel = panel; } void setAttachedPanel(FloatingUIPanel::Pointer panel) { _attachedPanel = panel; }
void setOffsetPosition(const glm::vec3& position) { _offsetPosition = position; } virtual void setOffsetPosition(const glm::vec3& position) { _offsetPosition = position; }
void setFacingRotation(const glm::quat& rotation) { _facingRotation = rotation; } virtual void setFacingRotation(const glm::quat& rotation) { _facingRotation = rotation; }
QScriptValue getProperty(QScriptEngine* scriptEngine, const QString& property); QScriptValue getProperty(QScriptEngine* scriptEngine, const QString& property);
void setProperties(const QScriptValue& properties); void setProperties(const QScriptValue& properties);