mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:24:00 +02:00
add support for auto-hide reticle and seek lookat on auto-show of reticle
This commit is contained in:
parent
188cf3694b
commit
8de4a59078
2 changed files with 84 additions and 12 deletions
70
examples/autoHideReticle.js
Normal file
70
examples/autoHideReticle.js
Normal file
|
@ -0,0 +1,70 @@
|
|||
// 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;
|
||||
}
|
||||
}
|
||||
});
|
|
@ -212,19 +212,21 @@ void ApplicationCompositor::displayOverlayTexture(RenderArgs* renderArgs) {
|
|||
geometryCache->renderUnitQuad(batch, vec4(vec3(1), _alpha));
|
||||
|
||||
//draw the mouse pointer
|
||||
// Get the mouse coordinates and convert to NDC [-1, 1]
|
||||
vec2 canvasSize = qApp->getCanvasSize(); // desktop, use actual canvas...
|
||||
vec2 mousePosition = toNormalizedDeviceScale(vec2(qApp->getMouse()), canvasSize);
|
||||
// Invert the Y axis
|
||||
mousePosition.y *= -1.0f;
|
||||
if (getReticleVisible()) {
|
||||
// Get the mouse coordinates and convert to NDC [-1, 1]
|
||||
vec2 canvasSize = qApp->getCanvasSize(); // desktop, use actual canvas...
|
||||
vec2 mousePosition = toNormalizedDeviceScale(vec2(qApp->getMouse()), canvasSize);
|
||||
// Invert the Y axis
|
||||
mousePosition.y *= -1.0f;
|
||||
|
||||
Transform model;
|
||||
model.setTranslation(vec3(mousePosition, 0));
|
||||
vec2 mouseSize = CURSOR_PIXEL_SIZE / canvasSize;
|
||||
model.setScale(vec3(mouseSize, 1.0f));
|
||||
batch.setModelTransform(model);
|
||||
bindCursorTexture(batch);
|
||||
geometryCache->renderUnitQuad(batch, vec4(1));
|
||||
Transform model;
|
||||
model.setTranslation(vec3(mousePosition, 0));
|
||||
vec2 mouseSize = CURSOR_PIXEL_SIZE / canvasSize;
|
||||
model.setScale(vec3(mouseSize, 1.0f));
|
||||
batch.setModelTransform(model);
|
||||
bindCursorTexture(batch);
|
||||
geometryCache->renderUnitQuad(batch, vec4(1));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue