Change tablet dimensions as sensorToWorldScale changes

This commit is contained in:
Anthony J. Thibault 2017-08-30 18:21:25 -07:00
parent c9cdaadeb5
commit 6e6687c3a6
7 changed files with 40 additions and 13 deletions

View file

@ -16,6 +16,9 @@
#include "Overlay.h"
// AJT: keep or remove this.
// #define USE_SN_SCALE
class Base3DOverlay : public Overlay, public SpatiallyNestable {
Q_OBJECT

View file

@ -47,7 +47,9 @@ void ModelOverlay::update(float deltatime) {
_updateModel = false;
_model->setSnapModelToCenter(true);
Transform transform = getTransform();
#ifndef USE_SN_SCALE
transform.setScale(1.0f); // disable inherited scale
#endif
if (_scaleToFit) {
_model->setScaleToFit(true, transform.getScale() * getDimensions());
} else {

View file

@ -40,6 +40,9 @@ void Sphere3DOverlay::render(RenderArgs* args) {
if (batch) {
Transform transform = getTransform();
#ifndef USE_SN_SCALE
transform.setScale(1.0f); // ignore inherited scale from SpatiallyNestable
#endif
transform.postScale(getDimensions() * SPHERE_OVERLAY_SCALE);
batch->setModelTransform(transform);

View file

@ -56,7 +56,11 @@ bool Volume3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::ve
float& distance, BoxFace& face, glm::vec3& surfaceNormal) {
// extents is the entity relative, scaled, centered extents of the entity
glm::mat4 worldToEntityMatrix;
getTransform().getInverseMatrix(worldToEntityMatrix);
Transform transform = getTransform();
#ifndef USE_SN_SCALE
transform.setScale(1.0f); // ignore any inherited scale from SpatiallyNestable
#endif
transform.getInverseMatrix(worldToEntityMatrix);
glm::vec3 overlayFrameOrigin = glm::vec3(worldToEntityMatrix * glm::vec4(origin, 1.0f));
glm::vec3 overlayFrameDirection = glm::vec3(worldToEntityMatrix * glm::vec4(direction, 0.0f));

View file

@ -305,7 +305,9 @@ void Web3DOverlay::render(RenderArgs* args) {
vec4 color(toGlm(getColor()), getAlpha());
Transform transform = getTransform();
#ifndef USE_SN_SCALE
transform.setScale(1.0f); // ignore inherited scale factor from parents
#endif
if (glm::length2(getDimensions()) != 1.0f) {
transform.postScale(vec3(getDimensions(), 1.0f));
}

View file

@ -106,8 +106,10 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location, visible) {
var _this = this;
var sensorScaleFactor = MyAvatar.sensorToWorldScale;
// scale factor of natural tablet dimensions.
this.width = width || DEFAULT_WIDTH;
this.width = (width || DEFAULT_WIDTH) * sensorScaleFactor;
var tabletScaleFactor = this.width / TABLET_NATURAL_DIMENSIONS.x;
this.height = TABLET_NATURAL_DIMENSIONS.y * tabletScaleFactor;
this.depth = TABLET_NATURAL_DIMENSIONS.z * tabletScaleFactor;
@ -152,8 +154,8 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location, visible) {
Overlays.deleteOverlay(this.webOverlayID);
}
var WEB_ENTITY_Z_OFFSET = (this.depth / 2);
var WEB_ENTITY_Y_OFFSET = 0.004;
var WEB_ENTITY_Z_OFFSET = (this.depth / 2) * (1 / sensorScaleFactor);
var WEB_ENTITY_Y_OFFSET = 0.004 * (1 / sensorScaleFactor);
this.webOverlayID = Overlays.addOverlay("web3d", {
name: "WebTablet Web",
@ -170,13 +172,13 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location, visible) {
visible: visible
});
var HOME_BUTTON_Y_OFFSET = (this.height / 2) - (this.height / 20);
var HOME_BUTTON_Y_OFFSET = ((this.height / 2) - (this.height / 20)) * (1 / sensorScaleFactor);
this.homeButtonID = Overlays.addOverlay("sphere", {
name: "homeButton",
localPosition: {x: -0.001, y: -HOME_BUTTON_Y_OFFSET, z: 0.0},
localRotation: {x: 0, y: 1, z: 0, w: 0},
dimensions: { x: 4 * tabletScaleFactor, y: 4 * tabletScaleFactor, z: 4 * tabletScaleFactor},
alpha: 0.0,
alpha: 1.0,
visible: visible,
drawInFront: false,
parentID: this.tabletEntityID,
@ -301,9 +303,10 @@ WebTablet.prototype.getOverlayObject = function () {
};
WebTablet.prototype.setWidth = function (width) {
var sensorScaleFactor = MyAvatar.sensorToWorldScale;
// scale factor of natural tablet dimensions.
this.width = width || DEFAULT_WIDTH;
this.width = (width || DEFAULT_WIDTH) * sensorScaleFactor;
var tabletScaleFactor = this.width / TABLET_NATURAL_DIMENSIONS.x;
this.height = TABLET_NATURAL_DIMENSIONS.y * tabletScaleFactor;
this.depth = TABLET_NATURAL_DIMENSIONS.z * tabletScaleFactor;
@ -313,15 +316,15 @@ WebTablet.prototype.setWidth = function (width) {
Overlays.editOverlay(this.tabletEntityID, { dimensions: this.getDimensions() });
// update webOverlay
var WEB_ENTITY_Z_OFFSET = (this.depth / 2);
var WEB_ENTITY_Y_OFFSET = 0.004;
var WEB_ENTITY_Z_OFFSET = (this.depth / 2) * (1 / sensorScaleFactor);
var WEB_ENTITY_Y_OFFSET = 0.004 * (1 / sensorScaleFactor);
Overlays.editOverlay(this.webOverlayID, {
localPosition: { x: 0, y: WEB_ENTITY_Y_OFFSET, z: -WEB_ENTITY_Z_OFFSET },
dpi: this.dpi
});
// update homeButton
var HOME_BUTTON_Y_OFFSET = (this.height / 2) - (this.height / 20);
var HOME_BUTTON_Y_OFFSET = ((this.height / 2) - (this.height / 20)) * (1 / sensorScaleFactor);
Overlays.editOverlay(this.homeButtonID, {
localPosition: {x: -0.001, y: -HOME_BUTTON_Y_OFFSET, z: 0.0},
dimensions: { x: 4 * tabletScaleFactor, y: 4 * tabletScaleFactor, z: 4 * tabletScaleFactor}

View file

@ -28,6 +28,7 @@
var MSECS_PER_SEC = 1000.0;
var MUTE_MICROPHONE_MENU_ITEM = "Mute Microphone";
var gTablet = null;
var avatarSensorScale = MyAvatar.sensorToWorldScale;
Script.include("../libraries/WebTablet.js");
@ -71,9 +72,9 @@
return tabletScalePercentage;
}
function updateTabletWidthFromSettings() {
function updateTabletWidthFromSettings(force) {
var newTabletScalePercentage = getTabletScalePercentageFromSettings();
if (newTabletScalePercentage !== tabletScalePercentage && UIWebTablet) {
if ((force || newTabletScalePercentage !== tabletScalePercentage) && UIWebTablet) {
tabletScalePercentage = newTabletScalePercentage;
UIWebTablet.setWidth(DEFAULT_WIDTH * (tabletScalePercentage / 100));
}
@ -121,6 +122,7 @@
Overlays.editOverlay(HMD.homeButtonID, { visible: true });
Overlays.editOverlay(HMD.tabletScreenID, { visible: true });
Overlays.editOverlay(HMD.tabletScreenID, { maxFPS: 90 });
updateTabletWidthFromSettings(true);
}
gTablet.tabletShown = true;
}
@ -185,7 +187,15 @@
if (now - validCheckTime > MSECS_PER_SEC) {
validCheckTime = now;
updateTabletWidthFromSettings();
// force tablet to resize if sensorToWorldScale changes
var force = false;
if (avatarSensorScale !== MyAvatar.sensorToWorldScale) {
force = true;
avatarSensorScale = MyAvatar.sensorToWorldScale;
}
updateTabletWidthFromSettings(force);
if (UIWebTablet) {
UIWebTablet.setLandscape(landscape);
}