Fix controllerModules with appropriate IPD scale changes

This commit is contained in:
Anthony J. Thibault 2017-09-13 18:23:54 -07:00
parent 8fb69a9867
commit 9a9f4a0d24
7 changed files with 36 additions and 20 deletions

View file

@ -555,7 +555,7 @@ Script.include("/~/system/libraries/controllers.js");
joint: (this.hand === RIGHT_HAND) ? "_CAMERA_RELATIVE_CONTROLLER_RIGHTHAND" : "_CAMERA_RELATIVE_CONTROLLER_LEFTHAND",
filter: RayPick.PICK_ENTITIES | RayPick.PICK_OVERLAYS,
maxDistance: PICK_MAX_DISTANCE,
posOffset: getGrabPointSphereOffset(this.handToController()),
posOffset: getGrabPointSphereOffset(this.handToController(), true),
renderStates: renderStates,
faceAvatar: true,
defaultRenderStates: defaultRenderStates

View file

@ -202,7 +202,7 @@ Script.include("/~/system/libraries/controllers.js");
joint: (this.hand === RIGHT_HAND) ? "_CAMERA_RELATIVE_CONTROLLER_RIGHTHAND" : "_CAMERA_RELATIVE_CONTROLLER_LEFTHAND",
filter: RayPick.PICK_ENTITIES | RayPick.PICK_OVERLAYS,
maxDistance: PICK_MAX_DISTANCE,
posOffset: getGrabPointSphereOffset(this.handToController()),
posOffset: getGrabPointSphereOffset(this.handToController(), true),
renderStates: renderStates,
faceAvatar: true,
defaultRenderStates: defaultRenderStates

View file

@ -239,7 +239,7 @@ Script.include("/~/system/libraries/utils.js");
joint: (this.hand === RIGHT_HAND) ? "_CONTROLLER_RIGHTHAND" : "_CONTROLLER_LEFTHAND",
filter: RayPick.PICK_ENTITIES | RayPick.PICK_OVERLAYS,
maxDistance: PICK_MAX_DISTANCE,
posOffset: getGrabPointSphereOffset(this.handToController()),
posOffset: getGrabPointSphereOffset(this.handToController(), true),
renderStates: renderStates,
faceAvatar: true,
defaultRenderStates: defaultRenderStates

View file

@ -120,6 +120,11 @@ var GRAB_RADIUS = 0.35;
}
Overlays.editOverlay(this.grabbedThingID, reparentProps);
// resizeTablet to counter adjust offsets to account for change of scale from sensorToWorldMatrix
if (this.grabbedThingID === HMD.tabletID) {
resizeTablet(getTabletWidthFromSettings(), reparentProps.parentJointIndex);
}
Messages.sendMessage('Hifi-Object-Manipulation', JSON.stringify({
action: 'grab',
grabbedEntity: this.grabbedThingID,
@ -140,6 +145,11 @@ var GRAB_RADIUS = 0.35;
parentID: this.previousParentID[this.grabbedThingID],
parentJointIndex: this.previousParentJointIndex[this.grabbedThingID]
});
// resizeTablet to counter adjust offsets to account for change of scale from sensorToWorldMatrix
if (this.grabbedThingID === HMD.tabletID) {
resizeTablet(getTabletWidthFromSettings(), this.previousParentJointIndex[this.grabbedThingID]);
}
}
this.grabbedThingID = null;

View file

@ -528,7 +528,7 @@ Script.include("/~/system/libraries/controllers.js");
joint: (this.hand === RIGHT_HAND) ? "_CONTROLLER_RIGHTHAND" : "_CONTROLLER_LEFTHAND",
filter: RayPick.PICK_OVERLAYS,
maxDistance: PICK_MAX_DISTANCE,
posOffset: getGrabPointSphereOffset(this.handToController()),
posOffset: getGrabPointSphereOffset(this.handToController(), true),
renderStates: renderStates,
faceAvatar: true,
defaultRenderStates: defaultRenderStates

View file

@ -356,7 +356,7 @@ Script.include("/~/system/libraries/controllers.js");
this.stylusTip = getControllerWorldLocation(this.handToController(), true);
// translate tip forward according to constant.
var TIP_OFFSET = {x: 0, y: WEB_STYLUS_LENGTH - WEB_TOUCH_Y_OFFSET, z: 0};
var TIP_OFFSET = Vec3.multiply(MyAvatar.sensorToWorldScale, {x: 0, y: WEB_STYLUS_LENGTH - WEB_TOUCH_Y_OFFSET, z: 0});
this.stylusTip.position = Vec3.sum(this.stylusTip.position,
Vec3.multiplyQbyV(this.stylusTip.orientation, TIP_OFFSET));
}
@ -380,17 +380,17 @@ Script.include("/~/system/libraries/controllers.js");
return;
}
var X_ROT_NEG_90 = { x: -0.70710678, y: 0, z: 0, w: 0.70710678 };
var modelOrientation = Quat.multiply(this.stylusTip.orientation, X_ROT_NEG_90);
var modelPositionOffset = Vec3.multiplyQbyV(modelOrientation, { x: 0, y: 0, z: MyAvatar.sensorToWorldScale * -WEB_STYLUS_LENGTH / 2 });
var stylusProperties = {
name: "stylus",
url: Script.resourcesPath() + "meshes/tablet-stylus-fat.fbx",
loadPriority: 10.0,
localPosition: Vec3.sum({
x: 0.0,
y: WEB_TOUCH_Y_OFFSET,
z: 0.0
}, getGrabPointSphereOffset(this.handToController())),
localRotation: Quat.fromVec3Degrees({ x: -90, y: 0, z: 0 }),
dimensions: { x: 0.01, y: 0.01, z: WEB_STYLUS_LENGTH },
position: Vec3.sum(this.stylusTip.position, modelPositionOffset),
rotation: modelOrientation,
dimensions: Vec3.multiply(MyAvatar.sensorToWorldScale, { x: 0.01, y: 0.01, z: WEB_STYLUS_LENGTH }),
solid: true,
visible: true,
ignoreRayIntersection: true,
@ -527,9 +527,11 @@ Script.include("/~/system/libraries/controllers.js");
hysteresisOffset = 0.05;
}
this.isNearStylusTarget = isNearStylusTarget(stylusTargets, EDGE_BORDER + hysteresisOffset,
TABLET_MIN_TOUCH_DISTANCE - hysteresisOffset,
WEB_DISPLAY_STYLUS_DISTANCE + hysteresisOffset);
var sensorScaleFactor = MyAvatar.sensorToWorldScale;
this.isNearStylusTarget = isNearStylusTarget(stylusTargets,
(EDGE_BORDER + hysteresisOffset) * sensorScaleFactor,
(TABLET_MIN_TOUCH_DISTANCE - hysteresisOffset) * sensorScaleFactor,
(WEB_DISPLAY_STYLUS_DISTANCE + hysteresisOffset) * sensorScaleFactor);
if (this.isNearStylusTarget) {
if (!this.useFingerInsteadOfStylus) {
@ -544,8 +546,12 @@ Script.include("/~/system/libraries/controllers.js");
var nearestStylusTarget = calculateNearestStylusTarget(stylusTargets);
if (nearestStylusTarget && nearestStylusTarget.distance > TABLET_MIN_TOUCH_DISTANCE &&
nearestStylusTarget.distance < TABLET_MAX_HOVER_DISTANCE) {
var SCALED_TABLET_MIN_TOUCH_DISTANCE = TABLET_MIN_TOUCH_DISTANCE * sensorScaleFactor;
var SCALED_TABLET_MAX_TOUCH_DISTANCE = TABLET_MAX_TOUCH_DISTANCE * sensorScaleFactor;
var SCALED_TABLET_MAX_HOVER_DISTANCE = TABLET_MAX_HOVER_DISTANCE * sensorScaleFactor;
if (nearestStylusTarget && nearestStylusTarget.distance > SCALED_TABLET_MIN_TOUCH_DISTANCE &&
nearestStylusTarget.distance < SCALED_TABLET_MAX_HOVER_DISTANCE) {
this.requestTouchFocus(nearestStylusTarget);
@ -559,8 +565,8 @@ Script.include("/~/system/libraries/controllers.js");
// filter out presses when tip is moving away from tablet.
// ensure that stylus is within bounding box by checking normalizedPosition
if (nearestStylusTarget.valid && nearestStylusTarget.distance > TABLET_MIN_TOUCH_DISTANCE &&
nearestStylusTarget.distance < TABLET_MAX_TOUCH_DISTANCE &&
if (nearestStylusTarget.valid && nearestStylusTarget.distance > SCALED_TABLET_MIN_TOUCH_DISTANCE &&
nearestStylusTarget.distance < SCALED_TABLET_MAX_TOUCH_DISTANCE &&
Vec3.dot(this.stylusTip.velocity, nearestStylusTarget.normal) < 0 &&
nearestStylusTarget.normalizedPosition.x >= 0 && nearestStylusTarget.normalizedPosition.x <= 1 &&
nearestStylusTarget.normalizedPosition.y >= 0 && nearestStylusTarget.normalizedPosition.y <= 1) {

View file

@ -459,7 +459,7 @@ Script.include("/~/system/libraries/controllers.js");
joint: (this.hand === RIGHT_HAND) ? "_CONTROLLER_RIGHTHAND" : "_CONTROLLER_LEFTHAND",
filter: RayPick.PICK_ENTITIES,
maxDistance: PICK_MAX_DISTANCE,
posOffset: getGrabPointSphereOffset(this.handToController()),
posOffset: getGrabPointSphereOffset(this.handToController(), true),
renderStates: renderStates,
faceAvatar: true,
defaultRenderStates: defaultRenderStates