Merge pull request #3937 from Atlante45/mouse_pick_in_oculus

Mouse pick improvments
This commit is contained in:
Brad Hefta-Gaub 2014-12-09 18:33:25 -08:00
commit 69f7a89003
5 changed files with 40 additions and 120 deletions

View file

@ -13,7 +13,6 @@ Script.include("libraries/globals.js");
var panelWall = false;
var orbShell = false;
var reticle = false;
var descriptionText = false;
var showText = false;
@ -24,8 +23,6 @@ var numberOfLines = 2;
var textMargin = 0.0625;
var lineHeight = (textHeight - (2 * textMargin)) / numberOfLines;
var lastMouseMove = 0;
var IDLE_HOVER_TIME = 2000; // if you haven't moved the mouse in 2 seconds, and in HMD mode, then we use reticle for hover
var avatarStickPosition = {};
var orbNaturalExtentsMin = { x: -1.230354, y: -1.22077, z: -1.210487 };
@ -58,13 +55,6 @@ var elevatorSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Lobby/eleva
var currentMuzakInjector = null;
var currentSound = null;
var inOculusMode = false;
function reticlePosition() {
var RETICLE_DISTANCE = 1;
return Vec3.sum(Camera.position, Vec3.multiply(Quat.getFront(Camera.orientation), RETICLE_DISTANCE));
}
function textOverlayPosition() {
var TEXT_DISTANCE_OUT = 6;
var TEXT_DISTANCE_DOWN = -2;
@ -125,22 +115,6 @@ function drawLobby() {
panelWall = Overlays.addOverlay("model", panelWallProps);
orbShell = Overlays.addOverlay("model", orbShellProps);
descriptionText = Overlays.addOverlay("text3d", descriptionTextProps);
inOculusMode = Menu.isOptionChecked("Enable VR Mode");
// for HMD wearers, create a reticle in center of screen
if (inOculusMode) {
var CURSOR_SCALE = 0.025;
reticle = Overlays.addOverlay("billboard", {
url: HIFI_PUBLIC_BUCKET + "images/cursor.svg",
position: reticlePosition(),
ignoreRayIntersection: true,
isFacingAvatar: true,
alpha: 1.0,
scale: CURSOR_SCALE
});
}
// add an attachment on this avatar so other people see them in the lobby
MyAvatar.attach(HELMET_ATTACHMENT_URL, "Neck", {x: 0, y: 0, z: 0}, Quat.fromPitchYawRollDegrees(0, 0, 0), 1.15);
@ -228,14 +202,8 @@ function cleanupLobby() {
Overlays.deleteOverlay(orbShell);
Overlays.deleteOverlay(descriptionText);
if (reticle) {
Overlays.deleteOverlay(reticle);
}
panelWall = false;
orbShell = false;
reticle = false;
Audio.stopInjector(currentDrone);
currentDrone = null;
@ -359,20 +327,6 @@ function handleLookAt(pickRay) {
function update(deltaTime) {
maybeCleanupLobby();
if (panelWall) {
if (reticle) {
Overlays.editOverlay(reticle, {
position: reticlePosition()
});
var nowDate = new Date();
var now = nowDate.getTime();
if (now - lastMouseMove > IDLE_HOVER_TIME) {
var pickRay = Camera.computeViewPickRay(0.5, 0.5);
handleLookAt(pickRay);
}
}
Overlays.editOverlay(descriptionText, { position: textOverlayPosition() });
// if the reticle is up then we may need to play the next muzak
@ -384,8 +338,6 @@ function update(deltaTime) {
function mouseMoveEvent(event) {
if (panelWall) {
var nowDate = new Date();
lastMouseMove = nowDate.getTime();
var pickRay = Camera.computePickRay(event.x, event.y);
handleLookAt(pickRay);
}

View file

@ -167,8 +167,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
_raiseMirror(0.0f),
_lastMouseMove(usecTimestampNow()),
_lastMouseMoveWasSimulated(false),
_mouseHidden(false),
_seenMouseMove(false),
_touchAvgX(0.0f),
_touchAvgY(0.0f),
_isTouchPressed(false),
@ -1130,7 +1128,8 @@ void Application::keyPressEvent(QKeyEvent* event) {
if (!event->isAutoRepeat()) {
// this starts an HFActionEvent
HFActionEvent startActionEvent(HFActionEvent::startType(),
_myCamera.computeViewPickRay(0.5f, 0.5f));
_myCamera.computePickRay(getTrueMouseX(),
getTrueMouseY()));
sendEvent(this, &startActionEvent);
}
@ -1221,10 +1220,11 @@ void Application::keyReleaseEvent(QKeyEvent* event) {
case Qt::Key_Space: {
if (!event->isAutoRepeat()) {
// this ends the HFActionEvent
HFActionEvent endActionEvent(HFActionEvent::endType(), _myCamera.computeViewPickRay(0.5f, 0.5f));
HFActionEvent endActionEvent(HFActionEvent::endType(),
_myCamera.computePickRay(getTrueMouseX(),
getTrueMouseY()));
sendEvent(this, &endActionEvent);
}
break;
}
case Qt::Key_Escape: {
@ -1233,7 +1233,6 @@ void Application::keyReleaseEvent(QKeyEvent* event) {
HFBackEvent endBackEvent(HFBackEvent::endType());
sendEvent(this, &endBackEvent);
}
break;
}
default:
@ -1252,34 +1251,24 @@ void Application::focusOutEvent(QFocusEvent* event) {
}
void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) {
bool showMouse = true;
// Used by application overlay to determine how to draw cursor(s)
_lastMouseMoveWasSimulated = deviceID > 0;
// If this mouse move event is emitted by a controller, dont show the mouse cursor
if (_lastMouseMoveWasSimulated) {
showMouse = false;
if (!_lastMouseMoveWasSimulated) {
_lastMouseMove = usecTimestampNow();
}
if (!_aboutToQuit) {
_entities.mouseMoveEvent(event, deviceID);
if (_aboutToQuit) {
return;
}
_entities.mouseMoveEvent(event, deviceID);
_controllerScriptingInterface.emitMouseMoveEvent(event, deviceID); // send events to any registered scripts
// if one of our scripts have asked to capture this event, then stop processing it
if (_controllerScriptingInterface.isMouseCaptured()) {
return;
}
_lastMouseMove = usecTimestampNow();
if (_mouseHidden && showMouse && !OculusManager::isConnected() && !TV3DManager::isConnected()) {
getGLWidget()->setCursor(Qt::ArrowCursor);
_mouseHidden = false;
_seenMouseMove = true;
}
}
void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {
@ -2111,13 +2100,7 @@ void Application::updateMouseRay() {
// make sure the frustum is up-to-date
loadViewFrustum(_myCamera, _viewFrustum);
// if the mouse pointer isn't visible, act like it's at the center of the screen
float x = 0.5f, y = 0.5f;
if (!_mouseHidden) {
x = getTrueMouseX() / (float)_glWidget->width();
y = getTrueMouseY() / (float)_glWidget->height();
}
PickRay pickRay = _myCamera.computeViewPickRay(x, y);
PickRay pickRay = _myCamera.computePickRay(getTrueMouseX(), getTrueMouseY());
_mouseRayOrigin = pickRay.origin;
_mouseRayDirection = pickRay.direction;
@ -2313,22 +2296,29 @@ void Application::updateCursor(float deltaTime) {
bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
PerformanceWarning warn(showWarnings, "Application::updateCursor()");
// watch mouse position, if it hasn't moved, hide the cursor
bool hideMouse = false;
bool underMouse = _glWidget->underMouse();
if (!_mouseHidden) {
quint64 now = usecTimestampNow();
int elapsed = now - _lastMouseMove;
const int HIDE_CURSOR_TIMEOUT = 1 * 1000 * 1000; // 1 second
if (elapsed > HIDE_CURSOR_TIMEOUT && (underMouse || !_seenMouseMove)) {
getGLWidget()->setCursor(Qt::BlankCursor);
_mouseHidden = true;
static const int HIDE_CURSOR_TIMEOUT = 3 * USECS_PER_SECOND; // 3 second
int elapsed = usecTimestampNow() - _lastMouseMove;
if ((elapsed > HIDE_CURSOR_TIMEOUT && underMouse) ||
(OculusManager::isConnected() && Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode))) {
hideMouse = true;
}
setCursorVisible(!hideMouse);
}
void Application::setCursorVisible(bool visible) {
if (visible) {
if (overrideCursor() != NULL) {
restoreOverrideCursor();
}
} else {
// if the mouse is hidden, but we're not inside our window, then consider ourselves to be moving
if (!underMouse && _seenMouseMove) {
_lastMouseMove = usecTimestampNow();
getGLWidget()->setCursor(Qt::ArrowCursor);
_mouseHidden = false;
if (overrideCursor() != NULL) {
changeOverrideCursor(Qt::BlankCursor);
} else {
setOverrideCursor(Qt::BlankCursor);
}
}
}
@ -2350,17 +2340,6 @@ void Application::update(float deltaTime) {
}
static QCursor cursor;
if (OculusManager::isConnected() &&
Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode)){
if (_window->cursor().shape() != Qt::BlankCursor) {
cursor = _window->cursor();
_window->setCursor(QCursor(Qt::BlankCursor));
}
} else if(_window->cursor().shape() == Qt::BlankCursor) {
_window->setCursor(cursor);
}
// Dispatch input events
_controllerScriptingInterface.updateInputControllers();
@ -4377,14 +4356,6 @@ void Application::skipVersion(QString latestVersion) {
skipFile.write(latestVersion.toStdString().c_str());
}
void Application::setCursorVisible(bool visible) {
if (visible) {
restoreOverrideCursor();
} else {
setOverrideCursor(Qt::BlankCursor);
}
}
void Application::takeSnapshot() {
QMediaPlayer* player = new QMediaPlayer();
QFileInfo inf = QFileInfo(Application::resourcesPath() + "sounds/snap.wav");

View file

@ -211,7 +211,8 @@ public:
EntityTreeRenderer* getEntityClipboardRenderer() { return &_entityClipboardRenderer; }
Environment* getEnvironment() { return &_environment; }
bool isMousePressed() const { return _mousePressed; }
bool isMouseHidden() const { return _mouseHidden; }
bool isMouseHidden() const { return _glWidget->cursor().shape() == Qt::BlankCursor; }
void setCursorVisible(bool visible);
const glm::vec3& getMouseRayOrigin() const { return _mouseRayOrigin; }
const glm::vec3& getMouseRayDirection() const { return _mouseRayDirection; }
bool mouseOnScreen() const;
@ -309,8 +310,6 @@ public:
QStringList getRunningScripts() { return _scriptEnginesHash.keys(); }
ScriptEngine* getScriptEngine(QString scriptHash) { return _scriptEnginesHash.contains(scriptHash) ? _scriptEnginesHash[scriptHash] : NULL; }
void setCursorVisible(bool visible);
bool isLookingAtMyAvatar(Avatar* avatar);
@ -567,8 +566,6 @@ private:
int _mouseDragStartedY;
quint64 _lastMouseMove;
bool _lastMouseMoveWasSimulated;
bool _mouseHidden;
bool _seenMouseMove;
glm::vec3 _mouseRayOrigin;
glm::vec3 _mouseRayDirection;

View file

@ -536,7 +536,7 @@ void ApplicationOverlay::renderPointers() {
glm::vec2 screenPos = sphericalToScreen(glm::vec2(yaw, -pitch));
position = QPoint(screenPos.x, screenPos.y);
QCursor::setPos(application->getGLWidget()->mapToGlobal(position));
application->getGLWidget()->cursor().setPos(application->getGLWidget()->mapToGlobal(position));
}
_reticlePosition[MOUSE] = position;

View file

@ -122,21 +122,21 @@ void FramelessDialog::mousePressEvent(QMouseEvent* mouseEvent) {
if (hitLeft || hitRight) {
_isResizing = true;
_resizeInitialWidth = size().width();
QApplication::setOverrideCursor(Qt::SizeHorCursor);
setCursor(Qt::SizeHorCursor);
}
} else {
bool hitTop = (_position == POSITION_TOP) && (abs(mouseEvent->pos().y() - size().height()) < RESIZE_HANDLE_WIDTH);
if (hitTop) {
_isResizing = true;
_resizeInitialWidth = size().height();
QApplication::setOverrideCursor(Qt::SizeHorCursor);
setCursor(Qt::SizeHorCursor);
}
}
}
}
void FramelessDialog::mouseReleaseEvent(QMouseEvent* mouseEvent) {
QApplication::restoreOverrideCursor();
unsetCursor();
_isResizing = false;
}