mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 21:43:03 +02:00
Rotate mini tablet to keep it "vertical"
This commit is contained in:
parent
a1c49bd2b6
commit
54dd868b3c
1 changed files with 53 additions and 1 deletions
|
@ -317,6 +317,7 @@
|
||||||
dimensions: Vec3.multiply(scaleFactor, MINI_UI_DIMENSIONS),
|
dimensions: Vec3.multiply(scaleFactor, MINI_UI_DIMENSIONS),
|
||||||
dpi: MINI_UI_DPI / scaleFactor
|
dpi: MINI_UI_DPI / scaleFactor
|
||||||
});
|
});
|
||||||
|
updateRotation();
|
||||||
}
|
}
|
||||||
|
|
||||||
function startExpandingTablet(hand) {
|
function startExpandingTablet(hand) {
|
||||||
|
@ -380,6 +381,51 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateRotation() {
|
||||||
|
// Update the rotation of the tablet about its face normal so that its base is horizontal.
|
||||||
|
var COS_5_DEGREES = 0.996,
|
||||||
|
RADIANS_TO_DEGREES = DEGREES_180 / Math.PI,
|
||||||
|
defaultLocalRotation,
|
||||||
|
handOrientation,
|
||||||
|
defaultOrientation,
|
||||||
|
faceNormal,
|
||||||
|
desiredOrientation,
|
||||||
|
defaultYAxis,
|
||||||
|
desiredYAxis,
|
||||||
|
cross,
|
||||||
|
dot,
|
||||||
|
deltaAngle,
|
||||||
|
deltaRotation,
|
||||||
|
localRotation;
|
||||||
|
|
||||||
|
defaultLocalRotation = MINI_ROTATIONS[uiHand];
|
||||||
|
handOrientation =
|
||||||
|
Quat.multiply(MyAvatar.orientation, MyAvatar.getAbsoluteJointRotationInObjectFrame(handJointIndex(uiHand)));
|
||||||
|
defaultOrientation = Quat.multiply(handOrientation, defaultLocalRotation);
|
||||||
|
faceNormal = Vec3.multiplyQbyV(defaultOrientation, Vec3.UNIT_Z);
|
||||||
|
|
||||||
|
if (Math.abs(Vec3.dot(faceNormal, Vec3.UNIT_Y)) > COS_5_DEGREES) {
|
||||||
|
// Don't rotate mini tablet if almost flat in the x-z plane.
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
// Rotate the tablet so that its base is parallel with the x-z plane.
|
||||||
|
desiredOrientation = Quat.lookAt(Vec3.ZERO, Vec3.multiplyQbyV(defaultOrientation, Vec3.UNIT_Z), Vec3.UNIT_Y);
|
||||||
|
defaultYAxis = Vec3.multiplyQbyV(defaultOrientation, Vec3.UNIT_Y);
|
||||||
|
desiredYAxis = Vec3.multiplyQbyV(desiredOrientation, Vec3.UNIT_Y);
|
||||||
|
cross = Vec3.cross(defaultYAxis, desiredYAxis);
|
||||||
|
dot = Vec3.dot(defaultYAxis, desiredYAxis);
|
||||||
|
deltaAngle = Math.atan2(Vec3.length(cross), dot) * RADIANS_TO_DEGREES;
|
||||||
|
if (Vec3.dot(cross, Vec3.multiplyQbyV(desiredOrientation, Vec3.UNIT_Z)) > 0) {
|
||||||
|
deltaAngle = -deltaAngle;
|
||||||
|
}
|
||||||
|
deltaRotation = Quat.angleAxis(deltaAngle, Vec3.multiplyQbyV(defaultLocalRotation, Vec3.UNIT_Z));
|
||||||
|
localRotation = Quat.multiply(deltaRotation, defaultLocalRotation);
|
||||||
|
}
|
||||||
|
Overlays.editOverlay(miniOverlay, {
|
||||||
|
localRotation: localRotation
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function hide() {
|
function hide() {
|
||||||
Overlays.editOverlay(miniOverlay, {
|
Overlays.editOverlay(miniOverlay, {
|
||||||
parentID: Uuid.NULL, // Release hold so that hand can grab tablet proper.
|
parentID: Uuid.NULL, // Release hold so that hand can grab tablet proper.
|
||||||
|
@ -446,6 +492,7 @@
|
||||||
size: size,
|
size: size,
|
||||||
startExpandingTablet: startExpandingTablet,
|
startExpandingTablet: startExpandingTablet,
|
||||||
sizeAboutHandles: sizeAboutHandles,
|
sizeAboutHandles: sizeAboutHandles,
|
||||||
|
updateRotation: updateRotation,
|
||||||
hide: hide,
|
hide: hide,
|
||||||
destroy: destroy
|
destroy: destroy
|
||||||
};
|
};
|
||||||
|
@ -478,7 +525,7 @@
|
||||||
miniState = MINI_DISABLED,
|
miniState = MINI_DISABLED,
|
||||||
miniHand,
|
miniHand,
|
||||||
updateTimer = null,
|
updateTimer = null,
|
||||||
UPDATE_INTERVAL = 300,
|
UPDATE_INTERVAL = 25,
|
||||||
|
|
||||||
// Mini tablet scaling.
|
// Mini tablet scaling.
|
||||||
MINI_SCALE_DURATION = 250,
|
MINI_SCALE_DURATION = 250,
|
||||||
|
@ -702,6 +749,11 @@
|
||||||
} else {
|
} else {
|
||||||
setState(MINI_HIDING);
|
setState(MINI_HIDING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If state hasn't changed, update mini tablet rotation.
|
||||||
|
if (miniState === MINI_VISIBLE) {
|
||||||
|
ui.updateRotation();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateMiniGrabbed() {
|
function updateMiniGrabbed() {
|
||||||
|
|
Loading…
Reference in a new issue