mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 18:50:00 +02:00
add fade between depths in depth reticle
This commit is contained in:
parent
783892ac2e
commit
6d9c585604
1 changed files with 41 additions and 6 deletions
|
@ -12,17 +12,24 @@
|
||||||
|
|
||||||
var APPARENT_2D_OVERLAY_DEPTH = 1.0;
|
var APPARENT_2D_OVERLAY_DEPTH = 1.0;
|
||||||
var APPARENT_MAXIMUM_DEPTH = 100.0; // this is a depth at which things all seem sufficiently distant
|
var APPARENT_MAXIMUM_DEPTH = 100.0; // this is a depth at which things all seem sufficiently distant
|
||||||
var lastDepthCheckTime = 0;
|
var lastDepthCheckTime = Date.now();
|
||||||
|
var desiredDepth = APPARENT_2D_OVERLAY_DEPTH;
|
||||||
|
var wasDepth = Reticle.depth; // depth at the time we changed our desired depth
|
||||||
|
var desiredDepthLastSet = lastDepthCheckTime; // time we changed our desired depth
|
||||||
|
var TIME_BETWEEN_DEPTH_CHECKS = 100;
|
||||||
|
var TIME_TO_FADE_DEPTH = 50;
|
||||||
|
|
||||||
Script.update.connect(function(deltaTime) {
|
Script.update.connect(function(deltaTime) {
|
||||||
var TIME_BETWEEN_DEPTH_CHECKS = 100;
|
var now = Date.now();
|
||||||
var timeSinceLastDepthCheck = Date.now() - lastDepthCheckTime;
|
var timeSinceLastDepthCheck = now - lastDepthCheckTime;
|
||||||
if (timeSinceLastDepthCheck > TIME_BETWEEN_DEPTH_CHECKS) {
|
if (timeSinceLastDepthCheck > TIME_BETWEEN_DEPTH_CHECKS) {
|
||||||
|
var newDesiredDepth = desiredDepth;
|
||||||
|
lastDepthCheckTime = now;
|
||||||
var reticlePosition = Reticle.position;
|
var reticlePosition = Reticle.position;
|
||||||
|
|
||||||
// first check the 2D Overlays
|
// first check the 2D Overlays
|
||||||
if (Reticle.pointingAtSystemOverlay || Overlays.getOverlayAtPoint(reticlePosition)) {
|
if (Reticle.pointingAtSystemOverlay || Overlays.getOverlayAtPoint(reticlePosition)) {
|
||||||
Reticle.setDepth(APPARENT_2D_OVERLAY_DEPTH);
|
newDesiredDepth = APPARENT_2D_OVERLAY_DEPTH;
|
||||||
} else {
|
} else {
|
||||||
var pickRay = Camera.computePickRay(reticlePosition.x, reticlePosition.y);
|
var pickRay = Camera.computePickRay(reticlePosition.x, reticlePosition.y);
|
||||||
|
|
||||||
|
@ -37,11 +44,39 @@ Script.update.connect(function(deltaTime) {
|
||||||
// If either the overlays or entities intersect, then set the reticle depth to
|
// If either the overlays or entities intersect, then set the reticle depth to
|
||||||
// the distance of intersection
|
// the distance of intersection
|
||||||
if (result.intersects) {
|
if (result.intersects) {
|
||||||
Reticle.setDepth(result.distance);
|
newDesiredDepth = result.distance;
|
||||||
} else {
|
} else {
|
||||||
// if nothing intersects... set the depth to some sufficiently large depth
|
// if nothing intersects... set the depth to some sufficiently large depth
|
||||||
Reticle.setDepth(APPARENT_MAXIMUM_DEPTH);
|
newDesiredDepth = APPARENT_MAXIMUM_DEPTH;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the desired depth has changed, reset our fade start time
|
||||||
|
if (desiredDepth != newDesiredDepth) {
|
||||||
|
desiredDepthLastSet = now;
|
||||||
|
desiredDepth = newDesiredDepth;
|
||||||
|
wasDepth = Reticle.depth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// move the reticle toward the desired depth
|
||||||
|
if (desiredDepth != Reticle.depth) {
|
||||||
|
|
||||||
|
// determine the time between now, and when we set our determined our desiredDepth
|
||||||
|
var elapsed = now - desiredDepthLastSet;
|
||||||
|
var distanceToFade = desiredDepth - wasDepth;
|
||||||
|
var percentElapsed = Math.min(1, elapsed / TIME_TO_FADE_DEPTH);
|
||||||
|
|
||||||
|
// special case to handle no fade settings
|
||||||
|
if (TIME_TO_FADE_DEPTH == 0) {
|
||||||
|
percentElapsed = 1;
|
||||||
|
}
|
||||||
|
var depthDelta = distanceToFade * percentElapsed;
|
||||||
|
|
||||||
|
var newDepth = wasDepth + depthDelta;
|
||||||
|
if (percentElapsed == 1) {
|
||||||
|
newDepth = desiredDepth;
|
||||||
|
}
|
||||||
|
Reticle.setDepth(newDepth);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue