mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 16:53:16 +02:00
Merge pull request #7212 from ZappoMan/depthReticleWork
add fade between depths in depth reticle
This commit is contained in:
commit
d932cb7578
2 changed files with 32 additions and 7 deletions
|
@ -12,17 +12,23 @@
|
||||||
|
|
||||||
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 TIME_BETWEEN_DEPTH_CHECKS = 100;
|
||||||
|
var MINIMUM_DEPTH_ADJUST = 0.01;
|
||||||
|
var NON_LINEAR_DIVISOR = 2;
|
||||||
|
|
||||||
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 +43,30 @@ 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) {
|
||||||
|
desiredDepth = newDesiredDepth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// move the reticle toward the desired depth
|
||||||
|
if (desiredDepth != Reticle.depth) {
|
||||||
|
|
||||||
|
// 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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -301,7 +301,7 @@ void ApplicationCompositor::displayOverlayTextureHmd(RenderArgs* renderArgs, int
|
||||||
// look at borrowed from overlays
|
// look at borrowed from overlays
|
||||||
float elevation = -asinf(relativePosition.y / glm::length(relativePosition));
|
float elevation = -asinf(relativePosition.y / glm::length(relativePosition));
|
||||||
float azimuth = atan2f(relativePosition.x, relativePosition.z);
|
float azimuth = atan2f(relativePosition.x, relativePosition.z);
|
||||||
glm::quat faceCamera = glm::quat(glm::vec3(elevation, azimuth, 0)) * quat(vec3(0, 0, -1)); // this extra *quat(vec3(0,0,-1)) was required to get the quad to flip this seems like we could optimize
|
glm::quat faceCamera = glm::quat(glm::vec3(elevation, azimuth, 0)) * quat(vec3(0, -PI, 0)); // this extra *quat(vec3(0,-PI,0)) was required to get the quad to flip this seems like we could optimize
|
||||||
|
|
||||||
Transform transform;
|
Transform transform;
|
||||||
transform.setTranslation(relativePosition);
|
transform.setTranslation(relativePosition);
|
||||||
|
|
Loading…
Reference in a new issue