Added mouse panning in the Yaw direction - at edges of screen.

This commit is contained in:
Philip Rosedale 2013-05-14 17:11:16 -07:00
parent 62a97f23bf
commit 6cfdf96dea
3 changed files with 30 additions and 7 deletions

View file

@ -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();
}

View file

@ -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...

View file

@ -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;}