mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
move autohide/show behavior to depthReticle, make it a default script
This commit is contained in:
parent
8de4a59078
commit
4009f03c38
3 changed files with 71 additions and 71 deletions
|
@ -1,70 +0,0 @@
|
|||
// autoHideReticle.js
|
||||
// examples
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 2/23/16.
|
||||
// Copyright 2016 High Fidelity, Inc.
|
||||
//
|
||||
// This script will auto-hide the reticle on inactivity... and then if it detects movement after being hidden
|
||||
// it will automatically move the reticle to the look at position
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
var MINIMUM_SEEK_DISTANCE = 0.01;
|
||||
var NON_LINEAR_DIVISOR = 2;
|
||||
|
||||
var lastMouseMove = Date.now();
|
||||
var HIDE_STATIC_MOUSE_AFTER = 5000; // 5 seconds
|
||||
var seekToLookAt = false;
|
||||
|
||||
Controller.mouseMoveEvent.connect(function(mouseEvent) {
|
||||
lastMouseMove = Date.now();
|
||||
|
||||
// if the reticle is hidden, show it...
|
||||
if (!Reticle.visible) {
|
||||
Reticle.visible = true;
|
||||
if (HMD.active) {
|
||||
seekToLookAt = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
Script.update.connect(function(deltaTime) {
|
||||
|
||||
// if we're currently seeking the lookAt move the mouse toward the lookat
|
||||
if (HMD.active && seekToLookAt) {
|
||||
var lookAt2D = HMD.getHUDLookAtPosition2D();
|
||||
var currentReticlePosition = Reticle.position;
|
||||
var distanceBetweenX = lookAt2D.x - Reticle.position.x;
|
||||
var distanceBetweenY = lookAt2D.y - Reticle.position.y;
|
||||
var moveX = distanceBetweenX / NON_LINEAR_DIVISOR;
|
||||
var moveY = distanceBetweenY / NON_LINEAR_DIVISOR;
|
||||
var newPosition = { x: Reticle.position.x + moveX, y: Reticle.position.y + moveY };
|
||||
var closeEnoughX = false;
|
||||
var closeEnoughY = false;
|
||||
if (moveX < MINIMUM_SEEK_DISTANCE) {
|
||||
newPosition.x = lookAt2D.x;
|
||||
closeEnoughX = true;
|
||||
}
|
||||
if (moveY < MINIMUM_SEEK_DISTANCE) {
|
||||
newPosition.y = lookAt2D.y;
|
||||
closeEnoughY = true;
|
||||
}
|
||||
if (closeEnoughX && closeEnoughY) {
|
||||
seekToLookAt = false;
|
||||
}
|
||||
Reticle.position = newPosition;
|
||||
}
|
||||
|
||||
// if we haven't moved in a long period of time, hide the reticle
|
||||
if (Reticle.visible) {
|
||||
var now = Date.now();
|
||||
var timeSinceLastMouseMove = now - lastMouseMove;
|
||||
if (timeSinceLastMouseMove > HIDE_STATIC_MOUSE_AFTER) {
|
||||
Reticle.visible = false;
|
||||
}
|
||||
}
|
||||
});
|
|
@ -22,3 +22,4 @@ Script.load("grab.js");
|
|||
Script.load("directory.js");
|
||||
Script.load("dialTone.js");
|
||||
Script.load("attachedEntitiesManager.js");
|
||||
Script.load("depthReticle.js");
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
// Copyright 2016 High Fidelity, Inc.
|
||||
//
|
||||
// When used in HMD, this script will make the reticle depth track to any clickable item in view.
|
||||
// This script also handles auto-hiding the reticle after inactivity, as well as having the reticle
|
||||
// seek the look at position upon waking up.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
@ -17,8 +19,63 @@ var desiredDepth = APPARENT_2D_OVERLAY_DEPTH;
|
|||
var TIME_BETWEEN_DEPTH_CHECKS = 100;
|
||||
var MINIMUM_DEPTH_ADJUST = 0.01;
|
||||
var NON_LINEAR_DIVISOR = 2;
|
||||
var MINIMUM_SEEK_DISTANCE = 0.01;
|
||||
|
||||
Script.update.connect(function(deltaTime) {
|
||||
var lastMouseMove = Date.now();
|
||||
var HIDE_STATIC_MOUSE_AFTER = 3000; // 3 seconds
|
||||
var shouldSeekToLookAt = false;
|
||||
|
||||
Controller.mouseMoveEvent.connect(function(mouseEvent) {
|
||||
lastMouseMove = Date.now();
|
||||
|
||||
// if the reticle is hidden, show it...
|
||||
if (!Reticle.visible) {
|
||||
Reticle.visible = true;
|
||||
if (HMD.active) {
|
||||
shouldSeekToLookAt = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function seekToLookAt() {
|
||||
// if we're currently seeking the lookAt move the mouse toward the lookat
|
||||
if (shouldSeekToLookAt) {
|
||||
var lookAt2D = HMD.getHUDLookAtPosition2D();
|
||||
var currentReticlePosition = Reticle.position;
|
||||
var distanceBetweenX = lookAt2D.x - Reticle.position.x;
|
||||
var distanceBetweenY = lookAt2D.y - Reticle.position.y;
|
||||
var moveX = distanceBetweenX / NON_LINEAR_DIVISOR;
|
||||
var moveY = distanceBetweenY / NON_LINEAR_DIVISOR;
|
||||
var newPosition = { x: Reticle.position.x + moveX, y: Reticle.position.y + moveY };
|
||||
var closeEnoughX = false;
|
||||
var closeEnoughY = false;
|
||||
if (moveX < MINIMUM_SEEK_DISTANCE) {
|
||||
newPosition.x = lookAt2D.x;
|
||||
closeEnoughX = true;
|
||||
}
|
||||
if (moveY < MINIMUM_SEEK_DISTANCE) {
|
||||
newPosition.y = lookAt2D.y;
|
||||
closeEnoughY = true;
|
||||
}
|
||||
if (closeEnoughX && closeEnoughY) {
|
||||
shouldSeekToLookAt = false;
|
||||
}
|
||||
Reticle.position = newPosition;
|
||||
}
|
||||
}
|
||||
|
||||
function autoHideReticle() {
|
||||
// if we haven't moved in a long period of time, hide the reticle
|
||||
if (Reticle.visible) {
|
||||
var now = Date.now();
|
||||
var timeSinceLastMouseMove = now - lastMouseMove;
|
||||
if (timeSinceLastMouseMove > HIDE_STATIC_MOUSE_AFTER) {
|
||||
Reticle.visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function checkReticleDepth() {
|
||||
var now = Date.now();
|
||||
var timeSinceLastDepthCheck = now - lastDepthCheckTime;
|
||||
if (timeSinceLastDepthCheck > TIME_BETWEEN_DEPTH_CHECKS) {
|
||||
|
@ -56,6 +113,9 @@ Script.update.connect(function(deltaTime) {
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function moveToDesiredDepth() {
|
||||
// move the reticle toward the desired depth
|
||||
if (desiredDepth != Reticle.depth) {
|
||||
|
||||
|
@ -69,4 +129,13 @@ Script.update.connect(function(deltaTime) {
|
|||
|
||||
Reticle.setDepth(newDepth);
|
||||
}
|
||||
}
|
||||
|
||||
Script.update.connect(function(deltaTime) {
|
||||
autoHideReticle(); // auto hide reticle for desktop or HMD mode
|
||||
if (HMD.active) {
|
||||
seekToLookAt(); // handle moving the reticle toward the look at
|
||||
checkReticleDepth(); // make sure reticle is at correct depth
|
||||
moveToDesiredDepth(); // move the fade the reticle to the desired depth
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue