mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 20:34:07 +02:00
Only update the (invisible) cursor position from hand controllers when the
trigger is partially squeezed.
This commit is contained in:
parent
3fca0d655c
commit
799686f29d
1 changed files with 47 additions and 24 deletions
|
@ -187,6 +187,32 @@ function overlayFromWorldPoint(point) {
|
|||
return { x: horizontalPixels, y: verticalPixels };
|
||||
}
|
||||
|
||||
function activeHudPoint2d(activeHand) { // if controller is valid, update reticle position and answer 2d point. Otherwise falsey.
|
||||
var controllerPose = Controller.getPoseValue(activeHand);
|
||||
// Valid if any plugged-in hand controller is "on". (uncradled Hydra, green-lighted Vive...)
|
||||
if (!controllerPose.valid) {
|
||||
return; // Controller is cradled.
|
||||
}
|
||||
var controllerPosition = Vec3.sum(Vec3.multiplyQbyV(MyAvatar.orientation, controllerPose.translation),
|
||||
MyAvatar.position);
|
||||
// This gets point direction right, but if you want general quaternion it would be more complicated:
|
||||
var controllerDirection = Quat.getUp(Quat.multiply(MyAvatar.orientation, controllerPose.rotation));
|
||||
|
||||
var hudPoint3d = calculateRayUICollisionPoint(controllerPosition, controllerDirection);
|
||||
if (!hudPoint3d) {
|
||||
if (Menu.isOptionChecked("Overlays")) { // With our hud resetting strategy, hudPoint3d should be valid here
|
||||
print('Controller is parallel to HUD'); // so let us know that our assumptions are wrong.
|
||||
}
|
||||
return;
|
||||
}
|
||||
var hudPoint2d = overlayFromWorldPoint(hudPoint3d);
|
||||
|
||||
// We don't know yet if we'll want to make the cursor or laser visble, but we need to move it to see if
|
||||
// it's pointing at a QML tool (aka system overlay).
|
||||
setReticlePosition(hudPoint2d);
|
||||
return hudPoint2d;
|
||||
}
|
||||
|
||||
// MOUSE ACTIVITY --------
|
||||
//
|
||||
var isSeeking = false;
|
||||
|
@ -351,8 +377,23 @@ function isPointingAtOverlayStartedNonFullTrigger(trigger) {
|
|||
}
|
||||
clickMapping.from(rightTrigger.full).when(isPointingAtOverlayStartedNonFullTrigger(rightTrigger)).to(Controller.Actions.ReticleClick);
|
||||
clickMapping.from(leftTrigger.full).when(isPointingAtOverlayStartedNonFullTrigger(leftTrigger)).to(Controller.Actions.ReticleClick);
|
||||
clickMapping.from(Controller.Standard.RightSecondaryThumb).peek().to(Controller.Actions.ContextMenu);
|
||||
clickMapping.from(Controller.Standard.LeftSecondaryThumb).peek().to(Controller.Actions.ContextMenu);
|
||||
// The following is essentially like Left and Right versions of
|
||||
// clickMapping.from(Controller.Standard.RightSecondaryThumb).peek().to(Controller.Actions.ContextMenu);
|
||||
// except that we first update the reticle position from the appropriate hand position, before invoking the ContextMenu.
|
||||
var wantsMenu = 0;
|
||||
clickMapping.from(function () { return wantsMenu; }).to(Controller.Actions.ContextMenu);
|
||||
clickMapping.from(Controller.Standard.RightSecondaryThumb).peek().to(function (clicked) {
|
||||
if (clicked) {
|
||||
activeHudPoint2d(Controller.Standard.RightHand);
|
||||
}
|
||||
wantsMenu = clicked;
|
||||
});
|
||||
clickMapping.from(Controller.Standard.LeftSecondaryThumb).peek().to(function (clicked) {
|
||||
if (clicked) {
|
||||
activeHudPoint2d(Controller.Standard.LeftHand);
|
||||
}
|
||||
wantsMenu = clicked;
|
||||
});
|
||||
clickMapping.from(Controller.Hardware.Keyboard.RightMouseClicked).peek().to(function () {
|
||||
// Allow the reticle depth to be set correctly:
|
||||
// Wait a tick for the context menu to be displayed, and then simulate a (non-hand-controller) mouse move
|
||||
|
@ -408,28 +449,13 @@ function update() {
|
|||
}
|
||||
leftTrigger.update();
|
||||
rightTrigger.update();
|
||||
var controllerPose = Controller.getPoseValue(activeHand);
|
||||
// Valid if any plugged-in hand controller is "on". (uncradled Hydra, green-lighted Vive...)
|
||||
if (!controllerPose.valid) {
|
||||
return off(); // Controller is cradled.
|
||||
if (!activeTrigger.state) {
|
||||
return off(); // No trigger
|
||||
}
|
||||
var controllerPosition = Vec3.sum(Vec3.multiplyQbyV(MyAvatar.orientation, controllerPose.translation),
|
||||
MyAvatar.position);
|
||||
// This gets point direction right, but if you want general quaternion it would be more complicated:
|
||||
var controllerDirection = Quat.getUp(Quat.multiply(MyAvatar.orientation, controllerPose.rotation));
|
||||
|
||||
var hudPoint3d = calculateRayUICollisionPoint(controllerPosition, controllerDirection);
|
||||
if (!hudPoint3d) {
|
||||
if (Menu.isOptionChecked("Overlays")) { // With our hud resetting strategy, hudPoint3d should be valid here
|
||||
print('Controller is parallel to HUD'); // so let us know that our assumptions are wrong.
|
||||
}
|
||||
var hudPoint2d = activeHudPoint2d(activeHand);
|
||||
if (!hudPoint2d) {
|
||||
return off();
|
||||
}
|
||||
var hudPoint2d = overlayFromWorldPoint(hudPoint3d);
|
||||
|
||||
// We don't know yet if we'll want to make the cursor visble, but we need to move it to see if
|
||||
// it's pointing at a QML tool (aka system overlay).
|
||||
setReticlePosition(hudPoint2d);
|
||||
// If there's a HUD element at the (newly moved) reticle, just make it visible and bail.
|
||||
if (isPointingAtOverlay(hudPoint2d)) {
|
||||
if (HMD.active) {
|
||||
|
@ -446,9 +472,6 @@ function update() {
|
|||
return;
|
||||
}
|
||||
// We are not pointing at a HUD element (but it could be a 3d overlay).
|
||||
if (!activeTrigger.state) {
|
||||
return off(); // No trigger
|
||||
}
|
||||
clearSystemLaser();
|
||||
Reticle.visible = false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue