From 6cfdf96deac0fd1a8a371bb3ec3bb9b1980147dd Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Tue, 14 May 2013 17:11:16 -0700 Subject: [PATCH] Added mouse panning in the Yaw direction - at edges of screen. --- interface/src/Application.cpp | 19 ++++++++++++------- interface/src/Avatar.cpp | 17 +++++++++++++++++ interface/src/Avatar.h | 1 + 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 65c29d2d88..1f11a63367 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -859,6 +859,9 @@ void Application::idle() { _handControl.stop(); } + // Update from Mouse + _myAvatar.updateFromMouse(_mouseX, _mouseY, _glWidget->width(), _glWidget->height()); + // Read serial port interface devices if (_serialPort.active) { _serialPort.readData(); @@ -1162,8 +1165,8 @@ void Application::init() { _handControl.setScreenDimensions(_glWidget->width(), _glWidget->height()); - _headMouseX = _glWidget->width()/2; - _headMouseY = _glWidget->height()/2; + _headMouseX = _mouseX = _glWidget->width() / 2; + _headMouseY = _mouseY = _glWidget->height() / 2; _stars.readInput(STAR_FILE, STAR_CACHE_FILE, 0); @@ -1173,7 +1176,9 @@ void Application::init() { a.distance = 1.5f; a.tightness = 8.0f; _myCamera.setMode(CAMERA_MODE_THIRD_PERSON, a); - _myAvatar.setDisplayingHead(true); + _myAvatar.setDisplayingHead(true); + + QCursor::setPos(_headMouseX, _headMouseY); OculusManager::connect(); @@ -1228,7 +1233,6 @@ void Application::updateAvatar(float deltaTime) { renderPitchSpring * deltaTime * -_myAvatar.getHeadPitch() * RENDER_PITCH_MULTIPLY); } - if (OculusManager::isConnected()) { float yaw, pitch, roll; OculusManager::getEulerAngles(yaw, pitch, roll); @@ -1900,12 +1904,13 @@ void Application::deleteVoxelUnderCursor() { void Application::resetSensors() { _myAvatar.setPosition(START_LOCATION); - _headMouseX = _glWidget->width() / 2; - _headMouseY = _glWidget->height() / 2; + _headMouseX = _mouseX = _glWidget->width() / 2; + _headMouseY = _mouseY = _glWidget->height() / 2; if (_serialPort.active) { _serialPort.resetAverages(); - } + } + QCursor::setPos(_headMouseX, _headMouseY); _myAvatar.reset(); } diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 64b9310b78..4203bd0d4c 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -291,6 +291,23 @@ bool Avatar::getIsNearInteractingOther() { return _avatarTouch.getAbleToReachOtherAvatar(); } +void Avatar::updateFromMouse(int mouseX, int mouseY, int screenWidth, int screenHeight) { + // Update pitch and yaw based on mouse behavior + const float MOUSE_MOVE_RADIUS = 0.25f; + const float MOUSE_ROTATE_SPEED = 7.5f; + float mouseLocationX = (float)mouseX / (float)screenWidth - 0.5f; + + if (fabs(mouseLocationX) > MOUSE_MOVE_RADIUS) { + float mouseMag = (fabs(mouseLocationX) - MOUSE_MOVE_RADIUS) / (0.5f - MOUSE_MOVE_RADIUS) * MOUSE_ROTATE_SPEED; + setBodyYaw(getBodyYaw() - + ((mouseLocationX > 0.f) ? + mouseMag : + -mouseMag) ); + } + + return; +} + void Avatar::simulate(float deltaTime) { //figure out if the mouse cursor is over any body spheres... diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index beca93b53e..c4075858e1 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -82,6 +82,7 @@ public: void reset(); void updateHeadFromGyros(float frametime, SerialInterface * serialInterface, glm::vec3 * gravity); + void updateFromMouse(int mouseX, int mouseY, int screenWidth, int screenHeight); void setNoise (float mag) {_head.noise = mag;} void setRenderYaw(float y) {_renderYaw = y;} void setRenderPitch(float p) {_renderPitch = p;}