mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 19:55:07 +02:00
make fade non-linear
This commit is contained in:
parent
6d9c585604
commit
e403c990d9
1 changed files with 8 additions and 18 deletions
|
@ -14,10 +14,9 @@ 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 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;
|
||||
var MINIMUM_DEPTH_ADJUST = 0.01;
|
||||
var NON_LINEAR_DIVISOR = 2;
|
||||
|
||||
Script.update.connect(function(deltaTime) {
|
||||
var now = Date.now();
|
||||
|
@ -53,30 +52,21 @@ Script.update.connect(function(deltaTime) {
|
|||
|
||||
// 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) {
|
||||
// cut distance between desiredDepth and current depth in half until we're close enough
|
||||
var distanceToAdjustThisCycle = (desiredDepth - Reticle.depth) / NON_LINEAR_DIVISOR;
|
||||
if (Math.abs(distanceToAdjustThisCycle) < MINIMUM_DEPTH_ADJUST) {
|
||||
newDepth = desiredDepth;
|
||||
} else {
|
||||
newDepth = Reticle.depth + distanceToAdjustThisCycle;
|
||||
}
|
||||
|
||||
Reticle.setDepth(newDepth);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue