From ddd25da430a52d87c0e9d4fb2798205668b1dc07 Mon Sep 17 00:00:00 2001 From: beholder Date: Thu, 26 Oct 2017 17:35:28 +0300 Subject: [PATCH] 8315 Stylus appears in wrong place on hand --- .../controllerModules/tabletStylusInput.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/scripts/system/controllers/controllerModules/tabletStylusInput.js b/scripts/system/controllers/controllerModules/tabletStylusInput.js index beb86d0ef4..46b630d023 100644 --- a/scripts/system/controllers/controllerModules/tabletStylusInput.js +++ b/scripts/system/controllers/controllerModules/tabletStylusInput.js @@ -154,6 +154,25 @@ Script.include("/~/system/libraries/controllers.js"); this.showStylus = function() { if (this.stylus) { + 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 modelOrientationAngles = Quat.safeEulerAngles(modelOrientation); + + var rotation = Overlays.getProperty(this.stylus, "rotation"); + var rotationAngles = Quat.safeEulerAngles(rotation); + + if(!Vec3.withinEpsilon(modelOrientationAngles, rotationAngles, 1)) { + var modelPositionOffset = Vec3.multiplyQbyV(modelOrientation, { x: 0, y: 0, z: MyAvatar.sensorToWorldScale * -WEB_STYLUS_LENGTH / 2 }); + + var updatedStylusProperties = { + position: Vec3.sum(this.stylusTip.position, modelPositionOffset), + rotation: modelOrientation, + dimensions: Vec3.multiply(MyAvatar.sensorToWorldScale, { x: 0.01, y: 0.01, z: WEB_STYLUS_LENGTH }), + }; + + Overlays.editOverlay(this.stylus, updatedStylusProperties); + } + return; }