mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 12:04:18 +02:00
Fix for some of tablet size issues, on switching domains.
This commit is contained in:
parent
b81f85e1ae
commit
bb5e808051
2 changed files with 22 additions and 39 deletions
|
@ -8,7 +8,7 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
/* 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/controllers.js"));
|
||||
|
@ -42,7 +42,7 @@ var LOCAL_TABLET_MODEL_PATH = Script.resourcesPath() + "meshes/tablet-with-home-
|
|||
// returns object with two fields:
|
||||
// * position - position in front of the user
|
||||
// * rotation - rotation of entity so it faces the user.
|
||||
function calcSpawnInfo(hand, tabletHeight, landscape) {
|
||||
function calcSpawnInfo(hand, height, landscape) {
|
||||
var finalPosition;
|
||||
|
||||
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;
|
||||
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 * sensorScaleFactor, z: 0.1 * sensorScaleFactor };
|
||||
position = Vec3.sum(position, Vec3.multiplyQbyV(rotation, Vec3.multiply(tabletHeight, RELATIVE_SPAWN_OFFSET)));
|
||||
var RELATIVE_SPAWN_OFFSET = { x: 0, y: 0.6 * height, z: 0.1 * height };
|
||||
position = Vec3.sum(position, Vec3.multiplyQbyV(rotation, RELATIVE_SPAWN_OFFSET));
|
||||
|
||||
return {
|
||||
position: position,
|
||||
|
@ -110,18 +109,19 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location, visible) {
|
|||
var sensorScaleFactor = MyAvatar.sensorToWorldScale;
|
||||
|
||||
// scale factor of natural tablet dimensions.
|
||||
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;
|
||||
var tabletWidth = (width || DEFAULT_WIDTH) * sensorScaleFactor;
|
||||
var tabletScaleFactor = tabletWidth / TABLET_NATURAL_DIMENSIONS.x;
|
||||
var tabletHeight = TABLET_NATURAL_DIMENSIONS.y * tabletScaleFactor;
|
||||
var tabletDepth = TABLET_NATURAL_DIMENSIONS.z * tabletScaleFactor;
|
||||
this.landscape = false;
|
||||
|
||||
visible = visible === true;
|
||||
|
||||
var tabletDpi;
|
||||
if (dpi) {
|
||||
this.dpi = dpi;
|
||||
tabletDpi = dpi;
|
||||
} else {
|
||||
this.dpi = DEFAULT_DPI * (DEFAULT_WIDTH / this.width);
|
||||
tabletDpi = DEFAULT_DPI * (DEFAULT_WIDTH / tabletWidth);
|
||||
}
|
||||
|
||||
var modelURL = LOCAL_TABLET_MODEL_PATH;
|
||||
|
@ -135,7 +135,7 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location, visible) {
|
|||
userData: JSON.stringify({
|
||||
"grabbableKey": {"grabbable": true}
|
||||
}),
|
||||
dimensions: this.getDimensions(),
|
||||
dimensions: { x: tabletWidth, y: tabletHeight, z: tabletDepth },
|
||||
parentID: AVATAR_SELF_ID,
|
||||
visible: visible
|
||||
};
|
||||
|
@ -155,7 +155,7 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location, visible) {
|
|||
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);
|
||||
|
||||
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 },
|
||||
localRotation: Quat.angleAxis(180, Y_AXIS),
|
||||
resolution: this.getTabletTextureResolution(),
|
||||
dpi: this.dpi,
|
||||
dpi: tabletDpi,
|
||||
color: { red: 255, green: 255, blue: 255 },
|
||||
alpha: 1.0,
|
||||
parentID: this.tabletEntityID,
|
||||
|
@ -173,7 +173,7 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location, 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", {
|
||||
name: "homeButton",
|
||||
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);
|
||||
};
|
||||
|
||||
WebTablet.prototype.getDimensions = function() {
|
||||
return { x: this.width, y: this.height, z: this.depth };
|
||||
};
|
||||
|
||||
WebTablet.prototype.getTabletTextureResolution = function() {
|
||||
if (this.landscape) {
|
||||
return { x: TABLET_TEXTURE_RESOLUTION.y , y: TABLET_TEXTURE_RESOLUTION.x };
|
||||
|
@ -324,12 +320,10 @@ WebTablet.prototype.destroy = function () {
|
|||
|
||||
WebTablet.prototype.geometryChanged = function (geometry) {
|
||||
if (!HMD.active) {
|
||||
var tabletProperties = {};
|
||||
|
||||
var tabletProperties = { dimensions: Overlays.getProperty(HMD.tabletID, "dimensions") };
|
||||
// compute position, rotation & parentJointIndex of the tablet
|
||||
this.calculateTabletAttachmentProperties(NO_HANDS, false, tabletProperties);
|
||||
// TODO -- is this still needed?
|
||||
// Entities.editEntity(this.tabletEntityID, tabletProperties);
|
||||
Overlays.editOverlay(HMD.tabletID, tabletProperties);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -403,7 +397,7 @@ WebTablet.prototype.calculateTabletAttachmentProperties = function (hand, useMou
|
|||
tabletProperties.parentJointIndex = SENSOR_TO_ROOM_MATRIX;
|
||||
|
||||
// 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.rotation = spawnInfo.rotation;
|
||||
} else {
|
||||
|
@ -426,12 +420,10 @@ WebTablet.prototype.calculateTabletAttachmentProperties = function (hand, useMou
|
|||
};
|
||||
|
||||
WebTablet.prototype.onHmdChanged = function () {
|
||||
|
||||
var tabletProperties = {};
|
||||
var tabletProperties = { dimensions: Overlays.getProperty(HMD.tabletID, "dimensions") };
|
||||
// compute position, rotation & parentJointIndex of the tablet
|
||||
this.calculateTabletAttachmentProperties(NO_HANDS, false, tabletProperties);
|
||||
// TODO -- is this still needed?
|
||||
// Entities.editEntity(this.tabletEntityID, tabletProperties);
|
||||
Overlays.editOverlay(HMD.tabletID, tabletProperties);
|
||||
};
|
||||
|
||||
WebTablet.prototype.pickle = function () {
|
||||
|
@ -511,16 +503,7 @@ WebTablet.prototype.mousePressEvent = function (event) {
|
|||
};
|
||||
|
||||
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) {
|
||||
|
|
|
@ -120,7 +120,7 @@
|
|||
if (debugTablet) {
|
||||
print("TABLET in showTabletUI, already rezzed");
|
||||
}
|
||||
var tabletProperties = {};
|
||||
var tabletProperties = { dimensions: Overlays.getProperty(HMD.tabletID, "dimensions") };
|
||||
UIWebTablet.calculateTabletAttachmentProperties(activeHand, true, tabletProperties);
|
||||
tabletProperties.visible = true;
|
||||
Overlays.editOverlay(HMD.tabletID, tabletProperties);
|
||||
|
|
Loading…
Reference in a new issue