Fix for some of tablet size issues, on switching domains.

This commit is contained in:
Anthony J. Thibault 2017-09-11 18:59:52 -07:00
parent b81f85e1ae
commit bb5e808051
2 changed files with 22 additions and 39 deletions

View file

@ -8,7 +8,7 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
/* global getControllerWorldLocation, Tablet, WebTablet:true, HMD, Settings, Script, /* global getControllerWorldLocation, Tablet, WebTablet:true, HMD, Settings, Script,
Vec3, Quat, MyAvatar, Entities, Overlays, Camera, Messages, Xform, clamp, Controller, Mat4 */ Vec3, Quat, MyAvatar, Entities, Overlays, Camera, Messages, Xform, clamp, Controller, Mat4, resizeTablet */
Script.include(Script.resolvePath("../libraries/utils.js")); Script.include(Script.resolvePath("../libraries/utils.js"));
Script.include(Script.resolvePath("../libraries/controllers.js")); Script.include(Script.resolvePath("../libraries/controllers.js"));
@ -42,7 +42,7 @@ var LOCAL_TABLET_MODEL_PATH = Script.resourcesPath() + "meshes/tablet-with-home-
// returns object with two fields: // returns object with two fields:
// * position - position in front of the user // * position - position in front of the user
// * rotation - rotation of entity so it faces the user. // * rotation - rotation of entity so it faces the user.
function calcSpawnInfo(hand, tabletHeight, landscape) { function calcSpawnInfo(hand, height, landscape) {
var finalPosition; var finalPosition;
var headPos = (HMD.active && Camera.mode === "first person") ? HMD.position : Camera.position; var headPos = (HMD.active && Camera.mode === "first person") ? HMD.position : Camera.position;
@ -76,9 +76,8 @@ function calcSpawnInfo(hand, tabletHeight, landscape) {
var TABLET_RAKE_ANGLE = 30; var TABLET_RAKE_ANGLE = 30;
rotation = Quat.multiply(Quat.angleAxis(TABLET_RAKE_ANGLE, Vec3.multiplyQbyV(lookAt, Vec3.UNIT_X)), lookAt); rotation = Quat.multiply(Quat.angleAxis(TABLET_RAKE_ANGLE, Vec3.multiplyQbyV(lookAt, Vec3.UNIT_X)), lookAt);
var sensorScaleFactor = MyAvatar.sensorToWorldScale; var RELATIVE_SPAWN_OFFSET = { x: 0, y: 0.6 * height, z: 0.1 * height };
var RELATIVE_SPAWN_OFFSET = { x: 0, y: 0.6 * sensorScaleFactor, z: 0.1 * sensorScaleFactor }; position = Vec3.sum(position, Vec3.multiplyQbyV(rotation, RELATIVE_SPAWN_OFFSET));
position = Vec3.sum(position, Vec3.multiplyQbyV(rotation, Vec3.multiply(tabletHeight, RELATIVE_SPAWN_OFFSET)));
return { return {
position: position, position: position,
@ -110,18 +109,19 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location, visible) {
var sensorScaleFactor = MyAvatar.sensorToWorldScale; var sensorScaleFactor = MyAvatar.sensorToWorldScale;
// scale factor of natural tablet dimensions. // scale factor of natural tablet dimensions.
this.width = (width || DEFAULT_WIDTH) * sensorScaleFactor; var tabletWidth = (width || DEFAULT_WIDTH) * sensorScaleFactor;
var tabletScaleFactor = this.width / TABLET_NATURAL_DIMENSIONS.x; var tabletScaleFactor = tabletWidth / TABLET_NATURAL_DIMENSIONS.x;
this.height = TABLET_NATURAL_DIMENSIONS.y * tabletScaleFactor; var tabletHeight = TABLET_NATURAL_DIMENSIONS.y * tabletScaleFactor;
this.depth = TABLET_NATURAL_DIMENSIONS.z * tabletScaleFactor; var tabletDepth = TABLET_NATURAL_DIMENSIONS.z * tabletScaleFactor;
this.landscape = false; this.landscape = false;
visible = visible === true; visible = visible === true;
var tabletDpi;
if (dpi) { if (dpi) {
this.dpi = dpi; tabletDpi = dpi;
} else { } else {
this.dpi = DEFAULT_DPI * (DEFAULT_WIDTH / this.width); tabletDpi = DEFAULT_DPI * (DEFAULT_WIDTH / tabletWidth);
} }
var modelURL = LOCAL_TABLET_MODEL_PATH; var modelURL = LOCAL_TABLET_MODEL_PATH;
@ -135,7 +135,7 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location, visible) {
userData: JSON.stringify({ userData: JSON.stringify({
"grabbableKey": {"grabbable": true} "grabbableKey": {"grabbable": true}
}), }),
dimensions: this.getDimensions(), dimensions: { x: tabletWidth, y: tabletHeight, z: tabletDepth },
parentID: AVATAR_SELF_ID, parentID: AVATAR_SELF_ID,
visible: visible visible: visible
}; };
@ -155,7 +155,7 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location, visible) {
Overlays.deleteOverlay(this.webOverlayID); Overlays.deleteOverlay(this.webOverlayID);
} }
var WEB_ENTITY_Z_OFFSET = (this.depth / 2) * (1 / sensorScaleFactor); var WEB_ENTITY_Z_OFFSET = (tabletDepth / 2) * (1 / sensorScaleFactor);
var WEB_ENTITY_Y_OFFSET = 0.004 * (1 / sensorScaleFactor); var WEB_ENTITY_Y_OFFSET = 0.004 * (1 / sensorScaleFactor);
this.webOverlayID = Overlays.addOverlay("web3d", { this.webOverlayID = Overlays.addOverlay("web3d", {
@ -164,7 +164,7 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location, visible) {
localPosition: { x: 0, y: WEB_ENTITY_Y_OFFSET, z: -WEB_ENTITY_Z_OFFSET }, localPosition: { x: 0, y: WEB_ENTITY_Y_OFFSET, z: -WEB_ENTITY_Z_OFFSET },
localRotation: Quat.angleAxis(180, Y_AXIS), localRotation: Quat.angleAxis(180, Y_AXIS),
resolution: this.getTabletTextureResolution(), resolution: this.getTabletTextureResolution(),
dpi: this.dpi, dpi: tabletDpi,
color: { red: 255, green: 255, blue: 255 }, color: { red: 255, green: 255, blue: 255 },
alpha: 1.0, alpha: 1.0,
parentID: this.tabletEntityID, parentID: this.tabletEntityID,
@ -173,7 +173,7 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location, visible) {
visible: visible visible: visible
}); });
var HOME_BUTTON_Y_OFFSET = ((this.height / 2) - (this.height / 20)) * (1 / sensorScaleFactor); var HOME_BUTTON_Y_OFFSET = ((tabletHeight / 2) - (tabletHeight / 20)) * (1 / sensorScaleFactor);
this.homeButtonID = Overlays.addOverlay("sphere", { this.homeButtonID = Overlays.addOverlay("sphere", {
name: "homeButton", name: "homeButton",
localPosition: {x: -0.001, y: -HOME_BUTTON_Y_OFFSET, z: 0.0}, localPosition: {x: -0.001, y: -HOME_BUTTON_Y_OFFSET, z: 0.0},
@ -250,10 +250,6 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location, visible) {
Camera.modeUpdated.connect(this.myCameraModeChanged); Camera.modeUpdated.connect(this.myCameraModeChanged);
}; };
WebTablet.prototype.getDimensions = function() {
return { x: this.width, y: this.height, z: this.depth };
};
WebTablet.prototype.getTabletTextureResolution = function() { WebTablet.prototype.getTabletTextureResolution = function() {
if (this.landscape) { if (this.landscape) {
return { x: TABLET_TEXTURE_RESOLUTION.y , y: TABLET_TEXTURE_RESOLUTION.x }; return { x: TABLET_TEXTURE_RESOLUTION.y , y: TABLET_TEXTURE_RESOLUTION.x };
@ -324,12 +320,10 @@ WebTablet.prototype.destroy = function () {
WebTablet.prototype.geometryChanged = function (geometry) { WebTablet.prototype.geometryChanged = function (geometry) {
if (!HMD.active) { if (!HMD.active) {
var tabletProperties = {}; var tabletProperties = { dimensions: Overlays.getProperty(HMD.tabletID, "dimensions") };
// compute position, rotation & parentJointIndex of the tablet // compute position, rotation & parentJointIndex of the tablet
this.calculateTabletAttachmentProperties(NO_HANDS, false, tabletProperties); this.calculateTabletAttachmentProperties(NO_HANDS, false, tabletProperties);
// TODO -- is this still needed? Overlays.editOverlay(HMD.tabletID, tabletProperties);
// Entities.editEntity(this.tabletEntityID, tabletProperties);
} }
}; };
@ -403,7 +397,7 @@ WebTablet.prototype.calculateTabletAttachmentProperties = function (hand, useMou
tabletProperties.parentJointIndex = SENSOR_TO_ROOM_MATRIX; tabletProperties.parentJointIndex = SENSOR_TO_ROOM_MATRIX;
// compute the appropriate position of the tablet, near the hand controller that was used to spawn it. // compute the appropriate position of the tablet, near the hand controller that was used to spawn it.
var spawnInfo = calcSpawnInfo(hand, this.height, this.landscape); var spawnInfo = calcSpawnInfo(hand, tabletProperties.dimensions.y, this.landscape);
tabletProperties.position = spawnInfo.position; tabletProperties.position = spawnInfo.position;
tabletProperties.rotation = spawnInfo.rotation; tabletProperties.rotation = spawnInfo.rotation;
} else { } else {
@ -426,12 +420,10 @@ WebTablet.prototype.calculateTabletAttachmentProperties = function (hand, useMou
}; };
WebTablet.prototype.onHmdChanged = function () { WebTablet.prototype.onHmdChanged = function () {
var tabletProperties = { dimensions: Overlays.getProperty(HMD.tabletID, "dimensions") };
var tabletProperties = {};
// compute position, rotation & parentJointIndex of the tablet // compute position, rotation & parentJointIndex of the tablet
this.calculateTabletAttachmentProperties(NO_HANDS, false, tabletProperties); this.calculateTabletAttachmentProperties(NO_HANDS, false, tabletProperties);
// TODO -- is this still needed? Overlays.editOverlay(HMD.tabletID, tabletProperties);
// Entities.editEntity(this.tabletEntityID, tabletProperties);
}; };
WebTablet.prototype.pickle = function () { WebTablet.prototype.pickle = function () {
@ -511,16 +503,7 @@ WebTablet.prototype.mousePressEvent = function (event) {
}; };
WebTablet.prototype.cameraModeChanged = function (newMode) { WebTablet.prototype.cameraModeChanged = function (newMode) {
// reposition the tablet. ;
// This allows HMD.position to reflect the new camera mode.
if (HMD.active) {
var self = this;
var tabletProperties = {};
// compute position, rotation & parentJointIndex of the tablet
self.calculateTabletAttachmentProperties(NO_HANDS, false, tabletProperties);
// TODO -- is this still needed?
// Entities.editEntity(self.tabletEntityID, tabletProperties);
}
}; };
function rayIntersectPlane(planePosition, planeNormal, rayStart, rayDirection) { function rayIntersectPlane(planePosition, planeNormal, rayStart, rayDirection) {

View file

@ -120,7 +120,7 @@
if (debugTablet) { if (debugTablet) {
print("TABLET in showTabletUI, already rezzed"); print("TABLET in showTabletUI, already rezzed");
} }
var tabletProperties = {}; var tabletProperties = { dimensions: Overlays.getProperty(HMD.tabletID, "dimensions") };
UIWebTablet.calculateTabletAttachmentProperties(activeHand, true, tabletProperties); UIWebTablet.calculateTabletAttachmentProperties(activeHand, true, tabletProperties);
tabletProperties.visible = true; tabletProperties.visible = true;
Overlays.editOverlay(HMD.tabletID, tabletProperties); Overlays.editOverlay(HMD.tabletID, tabletProperties);